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 /ranger/vcs/git.py | |
parent | aff0fa07a88d2e532420b69b244c332c5e6d7e08 (diff) | |
download | ranger-ca93ee5a9c54e3802726d09becdab745a41cc4ba.tar.gz |
fix vcs log errors on empty repos
Diffstat (limited to 'ranger/vcs/git.py')
-rw-r--r-- | ranger/vcs/git.py | 12 |
1 files changed, 12 insertions, 0 deletions
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: |