changeset 749:40932d7c4783

hgrepo: catch NotGitRepository and turn it into abort
author Augie Fackler <raf@durin42.com>
date Sat, 23 Aug 2014 12:35:57 -0400
parents 8b85933fb095
children e5e1a287121d
files hggit/hgrepo.py
diffstat 1 files changed, 13 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/hggit/hgrepo.py	Sat Aug 23 12:01:06 2014 -0400
+++ b/hggit/hgrepo.py	Sat Aug 23 12:35:57 2014 -0400
@@ -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)