# HG changeset patch # User Augie Fackler # Date 1408811757 14400 # Node ID 40932d7c478314dec6fd482d44dc5ed197f6989a # Parent 8b85933fb095e5ebd2ec2c8adf839556a738bec1 hgrepo: catch NotGitRepository and turn it into abort diff --git a/hggit/hgrepo.py b/hggit/hgrepo.py --- a/hggit/hgrepo.py +++ b/hggit/hgrepo.py @@ -6,9 +6,20 @@ from git_handler import GitHandler from gitrepo import gitrepo +from dulwich import errors + +def _transform_notgit(f): + def inner(*args, **kwargs): + try: + return f(*args, **kwargs) + except errors.NotGitRepository: + raise util.Abort('not a git repository') + return inner + def generate_repo_subclass(baseclass): class hgrepo(baseclass): + @_transform_notgit def pull(self, remote, heads=None, force=False): if isinstance(remote, gitrepo): return self.githandler.fetch(remote.path, heads) @@ -16,12 +27,14 @@ return super(hgrepo, self).pull(remote, heads, force) # TODO figure out something useful to do with the newbranch param + @_transform_notgit def push(self, remote, force=False, revs=None, newbranch=False): if isinstance(remote, gitrepo): return self.githandler.push(remote.path, revs, force) else: #pragma: no cover return super(hgrepo, self).push(remote, force, revs, newbranch) + @_transform_notgit def findoutgoing(self, remote, base=None, heads=None, force=False): if isinstance(remote, gitrepo): base, heads = self.githandler.get_refs(remote.path)