diff options
author | Abdo Roig-Maranges <abdo.roig@gmail.com> | 2013-02-13 10:46:54 +0100 |
---|---|---|
committer | hut <hut@lavabit.com> | 2013-02-15 22:40:10 +0100 |
commit | ca93ee5a9c54e3802726d09becdab745a41cc4ba (patch) | |
tree | 2072195ae90cccfa67d00b6eacf93e6191086623 | |
parent | aff0fa07a88d2e532420b69b244c332c5e6d7e08 (diff) | |
download | ranger-ca93ee5a9c54e3802726d09becdab745a41cc4ba.tar.gz |
fix vcs log errors on empty repos
-rw-r--r-- | ranger/vcs/bzr.py | 20 | ||||
-rw-r--r-- | ranger/vcs/git.py | 12 | ||||
-rw-r--r-- | ranger/vcs/hg.py | 11 |
3 files changed, 40 insertions, 3 deletions
diff --git a/ranger/vcs/bzr.py b/ranger/vcs/bzr.py index 2bd0c27a..a63eea54 100644 --- a/ranger/vcs/bzr.py +++ b/ranger/vcs/bzr.py @@ -36,6 +36,12 @@ class Bzr(Vcs): return self._vcs(path, 'bzr', args, silent=silent, catchout=catchout, bytes=bytes) + def _has_head(self): + """Checks whether repo has head""" + rnum = self._bzr(self.path, ['revno'], catchout=True) + return rnum != '0' + + def _sanitize_rev(self, rev): if rev == None: return None rev = rev.strip() @@ -203,11 +209,13 @@ class Bzr(Vcs): def get_log(self, filelist=None, maxres=None): """Get the entire log for the current HEAD""" + if not self._has_head(): return [] return self._log(refspec=None, filelist=filelist) def get_raw_log(self, filelist=None): """Gets the raw log as a string""" + if not self._has_head(): return [] args = ['log'] if filelist: args = args + filelist return self._bzr(self.path, args, catchout=True) @@ -223,7 +231,11 @@ class Bzr(Vcs): def get_remote(self): """Returns the url for the remote repo attached to head""" - remote = self._bzr(self.path, ['config', 'parent_location'], catchout=True) + try: + remote = self._bzr(self.path, ['config', 'parent_location'], catchout=True) + except VcsError: + remote = "" + return remote.strip() or None @@ -232,7 +244,10 @@ class Bzr(Vcs): if rev == None: rev = self.HEAD elif rev == self.INDEX: return None rev = self._sanitize_rev(rev) - L = self._log(refspec=rev) + try: + L = self._log(refspec=rev) + except VcsError: + L = [] if len(L) == 0: return None else: return L[0]['revid'] @@ -241,6 +256,7 @@ class Bzr(Vcs): """Gets info about the given revision rev""" if rev == None: rev = self.HEAD rev = self._sanitize_rev(rev) + if rev == self.HEAD and not self._has_head(): return [] L = self._log(refspec=rev) if len(L) == 0: diff --git a/ranger/vcs/git.py b/ranger/vcs/git.py index 9df27b39..b2e79a06 100644 --- a/ranger/vcs/git.py +++ b/ranger/vcs/git.py @@ -35,6 +35,15 @@ class Git(Vcs): return self._vcs(path, 'git', args, silent=silent, catchout=catchout, bytes=bytes) + def _has_head(self): + """Checks whether repo has head""" + try: + self._git(self.path, ['rev-parse', 'HEAD'], silent=True) + except VcsError: + return False + return True + + def _head_ref(self): """Gets HEAD's ref""" ref = self._git(self.path, ['symbolic-ref', self.HEAD], catchout=True, silent=True) @@ -230,11 +239,13 @@ class Git(Vcs): def get_log(self, filelist=None, maxres=None): """Get the entire log for the current HEAD""" + if not self._has_head(): return [] return self._log(refspec=None, maxres=maxres, filelist=filelist) def get_raw_log(self, filelist=None): """Gets the raw log as a string""" + if not self._has_head(): return [] args = ['log'] if filelist: args = args + ['--'] + filelist return self._git(self.path, args, catchout=True) @@ -278,6 +289,7 @@ class Git(Vcs): """Gets info about the given revision rev""" if rev == None: rev = self.HEAD rev = self._sanitize_rev(rev) + if rev == self.HEAD and not self._has_head(): return None L = self._log(refspec=rev) if len(L) == 0: diff --git a/ranger/vcs/hg.py b/ranger/vcs/hg.py index ac56d8ec..08e5753b 100644 --- a/ranger/vcs/hg.py +++ b/ranger/vcs/hg.py @@ -26,7 +26,7 @@ try: except ImportError: from ConfigParser import RawConfigParser -from .vcs import Vcs +from .vcs import Vcs, VcsError class Hg(Vcs): @@ -39,6 +39,12 @@ class Hg(Vcs): return self._vcs(path, 'hg', args, silent=silent, catchout=catchout, bytes=bytes) + def _has_head(self): + """Checks whether repo has head""" + rnum = self._hg(self.path, ['-q', 'identify', '--num', '-r', self.HEAD], catchout=True) + return rnum != '-1' + + def _sanitize_rev(self, rev): if rev == None: return None rev = rev.strip() @@ -211,11 +217,13 @@ class Hg(Vcs): def get_log(self, filelist=None, maxres=None): """Get the entire log for the current HEAD""" + if not self._has_head(): return [] return self._log(refspec=None, maxres=maxres, filelist=filelist) def get_raw_log(self, filelist=None): """Gets the raw log as a string""" + if not self._has_head(): return [] args = ['log'] if filelist: args = args + filelist return self._hg(self.path, args, catchout=True) @@ -248,6 +256,7 @@ class Hg(Vcs): """Gets info about the given revision rev""" if rev == None: rev = self.HEAD rev = self._sanitize_rev(rev) + if rev == self.HEAD and not self._has_head(): return None L = self._log(refspec=rev) if len(L) == 0: |