Merge branch 'maint'
[alt-git.git] / git_remote_helpers / git / non_local.py
blobf27389bb945ef423dc412c2368762439086f593e
1 import os
2 import subprocess
4 from git_remote_helpers.util import die, warn
7 class NonLocalGit(object):
8 """Handler to interact with non-local repos.
9 """
11 def __init__(self, repo):
12 """Creates a new non-local handler for the specified repo.
13 """
15 self.repo = repo
17 def clone(self, base):
18 """Clones the non-local repo to base.
20 Does nothing if a clone already exists.
21 """
23 path = os.path.join(self.repo.get_base_path(base), '.git')
25 # already cloned
26 if os.path.exists(path):
27 return path
29 os.makedirs(path)
30 args = ["git", "clone", "--bare", "--quiet", self.repo.gitpath, path]
32 child = subprocess.Popen(args)
33 if child.wait() != 0:
34 raise CalledProcessError
36 return path
38 def update(self, base):
39 """Updates checkout of the non-local repo in base.
40 """
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)
49 if child.wait() != 0:
50 raise CalledProcessError
52 args = ["git", "--git-dir=" + path, "update-ref", "refs/heads/master", "FETCH_HEAD"]
53 child = subprocess.Popen(args)
54 if child.wait() != 0:
55 raise CalledProcessError
57 def push(self, base):
58 """Pushes from the non-local repo to base.
59 """
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)
68 if child.wait() != 0:
69 raise CalledProcessError