##// END OF EJS Templates
vcs: fixed issues with calling get_changesets method doesn't...
marcink -
r3835:42981614 beta
parent child Browse files
Show More
@@ -81,6 +81,18 b' class GitRepository(BaseRepository):'
81 except KeyError:
81 except KeyError:
82 return None
82 return None
83
83
84 @property
85 def _empty(self):
86 """
87 Checks if repository is empty ie. without any changesets
88 """
89
90 try:
91 self.revisions[0]
92 except (KeyError, IndexError):
93 return True
94 return False
95
84 @LazyProperty
96 @LazyProperty
85 def revisions(self):
97 def revisions(self):
86 """
98 """
@@ -250,9 +262,7 b' class GitRepository(BaseRepository):'
250
262
251 is_null = lambda o: len(o) == revision.count('0')
263 is_null = lambda o: len(o) == revision.count('0')
252
264
253 try:
265 if self._empty:
254 self.revisions[0]
255 except (KeyError, IndexError):
256 raise EmptyRepositoryError("There are no changesets yet")
266 raise EmptyRepositoryError("There are no changesets yet")
257
267
258 if revision in (None, '', 'tip', 'HEAD', 'head', -1):
268 if revision in (None, '', 'tip', 'HEAD', 'head', -1):
@@ -492,6 +502,11 b' class GitRepository(BaseRepository):'
492 if branch_name and branch_name not in self.branches:
502 if branch_name and branch_name not in self.branches:
493 raise BranchDoesNotExistError("Branch '%s' not found" \
503 raise BranchDoesNotExistError("Branch '%s' not found" \
494 % branch_name)
504 % branch_name)
505 # actually we should check now if it's not an empty repo to not spaw
506 # subprocess commands
507 if self._empty:
508 raise EmptyRepositoryError("There are no changesets yet")
509
495 # %H at format means (full) commit hash, initial hashes are retrieved
510 # %H at format means (full) commit hash, initial hashes are retrieved
496 # in ascending date order
511 # in ascending date order
497 cmd_template = 'log --date-order --reverse --pretty=format:"%H"'
512 cmd_template = 'log --date-order --reverse --pretty=format:"%H"'
@@ -78,7 +78,7 b' class MercurialRepository(BaseRepository'
78 @property
78 @property
79 def _empty(self):
79 def _empty(self):
80 """
80 """
81 Checks if repository is empty without any changesets
81 Checks if repository is empty ie. without any changesets
82 """
82 """
83 # TODO: Following raises errors when using InMemoryChangeset...
83 # TODO: Following raises errors when using InMemoryChangeset...
84 # return len(self._repo.changelog) == 0
84 # return len(self._repo.changelog) == 0
@@ -1,5 +1,6 b''
1 from __future__ import with_statement
1 from __future__ import with_statement
2
2
3 import time
3 import datetime
4 import datetime
4 from rhodecode.lib import vcs
5 from rhodecode.lib import vcs
5 from rhodecode.tests.vcs.base import BackendTestMixin
6 from rhodecode.tests.vcs.base import BackendTestMixin
@@ -12,9 +13,10 b' from rhodecode.lib.vcs.nodes import ('
12 )
13 )
13 from rhodecode.lib.vcs.exceptions import (
14 from rhodecode.lib.vcs.exceptions import (
14 BranchDoesNotExistError, ChangesetDoesNotExistError,
15 BranchDoesNotExistError, ChangesetDoesNotExistError,
15 RepositoryError
16 RepositoryError, EmptyRepositoryError
16 )
17 )
17 from rhodecode.lib.vcs.utils.compat import unittest
18 from rhodecode.lib.vcs.utils.compat import unittest
19 from rhodecode.tests.vcs.conf import get_new_dir
18
20
19
21
20 class TestBaseChangeset(unittest.TestCase):
22 class TestBaseChangeset(unittest.TestCase):
@@ -197,6 +199,14 b' class ChangesetsTestCaseMixin(BackendTes'
197 changesets = list(self.repo.get_changesets(start=2, end=3))
199 changesets = list(self.repo.get_changesets(start=2, end=3))
198 self.assertEqual(len(changesets), 2)
200 self.assertEqual(len(changesets), 2)
199
201
202 def test_get_changesets_on_empty_repo_raises_EmptyRepository_error(self):
203 Backend = self.get_backend()
204 repo_path = get_new_dir(str(time.time()))
205 repo = Backend(repo_path, create=True)
206
207 with self.assertRaises(EmptyRepositoryError):
208 list(repo.get_changesets(start='foobar'))
209
200 def test_get_changesets_includes_end_changeset(self):
210 def test_get_changesets_includes_end_changeset(self):
201 second_id = self.repo.revisions[1]
211 second_id = self.repo.revisions[1]
202 changesets = list(self.repo.get_changesets(end=second_id))
212 changesets = list(self.repo.get_changesets(end=second_id))
General Comments 0
You need to be logged in to leave comments. Login now