Changeset - 42981614c624
[Not reviewed]
beta
0 3 0
Marcin Kuzminski - 13 years ago 2013-05-10 14:35:02
marcin@python-works.com
vcs: fixed issues with calling get_changesets method doesn't
throws EmptyRepositoryError when called on empty repos
3 files changed with 30 insertions and 5 deletions:
0 comments (0 inline, 0 general)
rhodecode/lib/vcs/backends/git/repository.py
Show inline comments
 
@@ -81,6 +81,18 @@ class GitRepository(BaseRepository):
 
        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 @@ class GitRepository(BaseRepository):
 

	
 
        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 @@ class GitRepository(BaseRepository):
 
        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"'
rhodecode/lib/vcs/backends/hg/repository.py
Show inline comments
 
@@ -78,7 +78,7 @@ class MercurialRepository(BaseRepository
 
    @property
 
    def _empty(self):
 
        """
 
        Checks if repository is empty without any changesets
 
        Checks if repository is empty ie. without any changesets
 
        """
 
        # TODO: Following raises errors when using InMemoryChangeset...
 
        # return len(self._repo.changelog) == 0
rhodecode/tests/vcs/test_changesets.py
Show inline comments
 
from __future__ import with_statement
 

	
 
import time
 
import datetime
 
from rhodecode.lib import vcs
 
from rhodecode.tests.vcs.base import BackendTestMixin
 
@@ -12,9 +13,10 @@ from rhodecode.lib.vcs.nodes import (
 
)
 
from rhodecode.lib.vcs.exceptions import (
 
    BranchDoesNotExistError, ChangesetDoesNotExistError,
 
    RepositoryError
 
    RepositoryError, EmptyRepositoryError
 
)
 
from rhodecode.lib.vcs.utils.compat import unittest
 
from rhodecode.tests.vcs.conf import get_new_dir
 

	
 

	
 
class TestBaseChangeset(unittest.TestCase):
 
@@ -197,6 +199,14 @@ class ChangesetsTestCaseMixin(BackendTes
 
        changesets = list(self.repo.get_changesets(start=2, end=3))
 
        self.assertEqual(len(changesets), 2)
 

	
 
    def test_get_changesets_on_empty_repo_raises_EmptyRepository_error(self):
 
        Backend = self.get_backend()
 
        repo_path = get_new_dir(str(time.time()))
 
        repo = Backend(repo_path, create=True)
 

	
 
        with self.assertRaises(EmptyRepositoryError):
 
            list(repo.get_changesets(start='foobar'))
 

	
 
    def test_get_changesets_includes_end_changeset(self):
 
        second_id = self.repo.revisions[1]
 
        changesets = list(self.repo.get_changesets(end=second_id))
0 comments (0 inline, 0 general)