]> git.ipfire.org Git - thirdparty/git.git/blame - git_remote_helpers/git/non_local.py
remote-helpers: add testgit helper
[thirdparty/git.git] / git_remote_helpers / git / non_local.py
CommitLineData
7aeaa2fc
SR
1import os
2import subprocess
3
4from git_remote_helpers.util import die, warn
5
6
7class 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 subprocess.check_call(args)
33
34 return path
35
36 def update(self, base):
37 """Updates checkout of the non-local repo in base.
38 """
39
40 path = os.path.join(self.repo.get_base_path(base), '.git')
41
42 if not os.path.exists(path):
43 die("could not find repo at %s", path)
44
45 args = ["git", "--git-dir=" + path, "fetch", "--quiet", self.repo.gitpath]
46 subprocess.check_call(args)
47
48 args = ["git", "--git-dir=" + path, "update-ref", "refs/heads/master", "FETCH_HEAD"]
49 subprocess.check_call(args)
50
51 def push(self, base):
52 """Pushes from the non-local repo to base.
53 """
54
55 path = os.path.join(self.repo.get_base_path(base), '.git')
56
57 if not os.path.exists(path):
58 die("could not find repo at %s", path)
59
60 args = ["git", "--git-dir=" + path, "push", "--quiet", self.repo.gitpath]
61 subprocess.check_call(args)