remote-hg: another case of Postel's law
[git/dscho.git] / git_remote_helpers / hg / non_local.py
blobabb7908da04b4156e8caa1246cb002b229a3d919
1 import os
3 from git_remote_helpers.util import die, warn
5 class NonLocalHg(object):
6 def __init__(self, repo):
7 self.repo = repo
8 self.hg = repo.hg
10 def clone(self, base):
11 path = self.repo.get_base_path(base)
13 # already cloned
14 if os.path.exists(os.path.join(path, '.hg')):
15 return path
17 if not os.path.exists(path):
18 os.makedirs(path)
20 if self.repo.path.endswith(".hg"):
21 from_path = self.repo.path[:-3]
22 else:
23 from_path = self.repo.path
25 self.repo.ui.setconfig('ui', 'quiet', "true")
26 self.hg.clone(self.repo.ui, {}, from_path, path, update=False, pull=True)
28 return path
30 def update(self, base):
31 path = self.repo.get_base_path(base)
33 if not os.path.exists(path):
34 die("could not find repo at %s", path)
36 repo = self.hg.repository(self.repo.ui, path)
38 repo.ui.setconfig('ui', 'quiet', "true")
39 repo.pull(self.repo, heads=self.repo.heads(), force=True)
41 def push(self, base):
42 path = self.repo.get_base_path(base)
44 if not os.path.exists(path):
45 die("could not find repo at %s", path)
47 repo = self.hg.repository(self.repo.ui, path)
49 self.repo.ui.setconfig('ui', 'quiet', "true")
50 repo.ui.setconfig('ui', 'quiet', "true")
51 repo.push(self.repo, force=False)