]> asedeno.scripts.mit.edu Git - git.git/blob - git_remote_helpers/git/non_local.py
Merge branch 'ic/maint-rebase-i-abort'
[git.git] / git_remote_helpers / git / non_local.py
1 import os
2 import subprocess
3
4 from git_remote_helpers.util import die, warn
5
6
7 class NonLocalGit(object):
8     """Handler to interact with non-local repos.
9     """
10
11     def __init__(self, repo):
12         """Creates a new non-local handler for the specified repo.
13         """
14
15         self.repo = repo
16
17     def clone(self, base):
18         """Clones the non-local repo to base.
19
20         Does nothing if a clone already exists.
21         """
22
23         path = os.path.join(self.repo.get_base_path(base), '.git')
24
25         # already cloned
26         if os.path.exists(path):
27             return path
28
29         os.makedirs(path)
30         args = ["git", "clone", "--bare", "--quiet", self.repo.gitpath, path]
31
32         child = subprocess.Popen(args)
33         if child.wait() != 0:
34             raise CalledProcessError
35
36         return path
37
38     def update(self, base):
39         """Updates checkout of the non-local repo in base.
40         """
41
42         path = os.path.join(self.repo.get_base_path(base), '.git')
43
44         if not os.path.exists(path):
45             die("could not find repo at %s", path)
46
47         args = ["git", "--git-dir=" + path, "fetch", "--quiet", self.repo.gitpath]
48         child = subprocess.Popen(args)
49         if child.wait() != 0:
50             raise CalledProcessError
51
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
56
57     def push(self, base):
58         """Pushes from the non-local repo to base.
59         """
60
61         path = os.path.join(self.repo.get_base_path(base), '.git')
62
63         if not os.path.exists(path):
64             die("could not find repo at %s", path)
65
66         args = ["git", "--git-dir=" + path, "push", "--quiet", self.repo.gitpath]
67         child = subprocess.Popen(args)
68         if child.wait() != 0:
69             raise CalledProcessError