FIXME: hotpatch for compatibility with latest hg
[git] / git_remote_helpers / hg / non_local.py
1 import os
2
3 from git_remote_helpers.util import die, warn
4
5 class NonLocalHg(object):
6     def __init__(self, repo):
7         self.repo = repo
8         self.hg = repo.hg
9
10     def clone(self, base):
11         path = self.repo.get_base_path(base)
12
13         # already cloned
14         if os.path.exists(os.path.join(path, '.hg')):
15             return path
16
17         if not os.path.exists(path):
18             os.makedirs(path)
19
20         if self.repo.path.endswith(".hg"):
21             from_path = self.repo.path[:-3]
22         else:
23             from_path = self.repo.path
24
25         self.repo.ui.setconfig('ui', 'quiet', "true")
26         self.hg.clone(self.repo.ui, {}, from_path, path, update=False, pull=True)
27
28         return path
29
30     def update(self, base):
31         path = self.repo.get_base_path(base)
32
33         if not os.path.exists(path):
34             die("could not find repo at %s", path)
35
36         repo = self.hg.repository(self.repo.ui, path)
37
38         repo.ui.setconfig('ui', 'quiet', "true")
39         repo.pull(self.repo, heads=self.repo.heads(), force=True)
40
41     def push(self, base):
42         path = self.repo.get_base_path(base)
43
44         if not os.path.exists(path):
45             die("could not find repo at %s", path)
46
47         repo = self.hg.repository(self.repo.ui, path)
48
49         self.repo.ui.setconfig('ui', 'quiet', "true")
50         repo.ui.setconfig('ui', 'quiet', "true")
51         repo.push(self.repo, force=False)