4 from git_remote_helpers.util import die, warn
7 class NonLocalGit(object):
8 """Handler to interact with non-local repos.
11 def __init__(self, repo):
12 """Creates a new non-local handler for the specified repo.
17 def clone(self, base):
18 """Clones the non-local repo to base.
20 Does nothing if a clone already exists.
23 path = os.path.join(self.repo.get_base_path(base), '.git')
26 if os.path.exists(path):
30 args = ["git", "clone", "--bare", "--quiet", self.repo.gitpath, path]
32 child = subprocess.Popen(args)
34 raise CalledProcessError
38 def update(self, base):
39 """Updates checkout of the non-local repo in base.
42 path = os.path.join(self.repo.get_base_path(base), '.git')
44 if not os.path.exists(path):
45 die("could not find repo at %s", path)
47 args = ["git", "--git-dir=" + path, "fetch", "--quiet", self.repo.gitpath]
48 child = subprocess.Popen(args)
50 raise CalledProcessError
52 args = ["git", "--git-dir=" + path, "update-ref", "refs/heads/master", "FETCH_HEAD"]
53 child = subprocess.Popen(args)
55 raise CalledProcessError
58 """Pushes from the non-local repo to base.
61 path = os.path.join(self.repo.get_base_path(base), '.git')
63 if not os.path.exists(path):
64 die("could not find repo at %s", path)
66 args = ["git", "--git-dir=" + path, "push", "--quiet", self.repo.gitpath]
67 child = subprocess.Popen(args)
69 raise CalledProcessError