Mercurial > kallithea
diff rhodecode/lib/vcs/backends/git/repository.py @ 3835:42981614c624 beta
vcs: fixed issues with calling get_changesets method doesn't
throws EmptyRepositoryError when called on empty repos
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Fri, 10 May 2013 14:35:02 +0200 |
parents | 08d439bfbd8c |
children | f5a1314886ec |
line wrap: on
line diff
--- a/rhodecode/lib/vcs/backends/git/repository.py Thu May 09 22:51:53 2013 +0200 +++ b/rhodecode/lib/vcs/backends/git/repository.py Fri May 10 14:35:02 2013 +0200 @@ -81,6 +81,18 @@ except KeyError: return None + @property + def _empty(self): + """ + Checks if repository is empty ie. without any changesets + """ + + try: + self.revisions[0] + except (KeyError, IndexError): + return True + return False + @LazyProperty def revisions(self): """ @@ -250,9 +262,7 @@ is_null = lambda o: len(o) == revision.count('0') - try: - self.revisions[0] - except (KeyError, IndexError): + if self._empty: raise EmptyRepositoryError("There are no changesets yet") if revision in (None, '', 'tip', 'HEAD', 'head', -1): @@ -492,6 +502,11 @@ if branch_name and branch_name not in self.branches: raise BranchDoesNotExistError("Branch '%s' not found" \ % branch_name) + # actually we should check now if it's not an empty repo to not spaw + # subprocess commands + if self._empty: + raise EmptyRepositoryError("There are no changesets yet") + # %H at format means (full) commit hash, initial hashes are retrieved # in ascending date order cmd_template = 'log --date-order --reverse --pretty=format:"%H"'