Code

Merge branch 'ew/keepalive' into maint
[git.git] / git_remote_helpers / git / non_local.py
1 import os
2 import subprocess
4 from git_remote_helpers.util import check_call, 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         check_call(args)
34         return path
36     def update(self, base):
37         """Updates checkout of the non-local repo in base.
38         """
40         path = os.path.join(self.repo.get_base_path(base), '.git')
42         if not os.path.exists(path):
43             die("could not find repo at %s", path)
45         args = ["git", "--git-dir=" + path, "fetch", "--quiet", self.repo.gitpath]
46         check_call(args)
48         args = ["git", "--git-dir=" + path, "update-ref", "refs/heads/master", "FETCH_HEAD"]
49         child = check_call(args)
51     def push(self, base):
52         """Pushes from the non-local repo to base.
53         """
55         path = os.path.join(self.repo.get_base_path(base), '.git')
57         if not os.path.exists(path):
58             die("could not find repo at %s", path)
60         args = ["git", "--git-dir=" + path, "push", "--quiet", self.repo.gitpath, "--all"]
61         child = check_call(args)