diff options
-rw-r--r-- | TODO | 6 | ||||
-rw-r--r-- | lib/git/repo.py | 16 | ||||
-rw-r--r-- | test/git/test_repo.py | 18 |
3 files changed, 24 insertions, 16 deletions
@@ -21,6 +21,12 @@ Config it will be returned instead of raising. This way the class will be much more usable, and ... I truly hate this config reader as it is so 'old' style. Its not even a new-style class yet showing that it must be ten years old. + +Diff +---- +* Check docs on diff-core to be sure the raw-format presented there can be read + properly: + - http://www.kernel.org/pub/software/scm/git-core/docs/gitdiffcore.html Docs ---- diff --git a/lib/git/repo.py b/lib/git/repo.py index 898b0f30..37847c98 100644 --- a/lib/git/repo.py +++ b/lib/git/repo.py @@ -394,21 +394,25 @@ class Repo(object): Raises NoSuchPathError + Note + The method does not check for the existance of the paths in alts + as the caller is responsible. + Returns None """ - for alt in alts: - if not os.path.exists(alt): - raise NoSuchPathError("Could not set alternates. Alternate path %s must exist" % alt) - + alternates_path = os.path.join(self.path, 'objects', 'info', 'alternates') if not alts: - os.remove(os.path.join(self.path, 'objects', 'info', 'alternates')) + if os.path.isfile(alternates_path): + os.remove(alternates_path) else: try: - f = open(os.path.join(self.path, 'objects', 'info', 'alternates'), 'w') + f = open(alternates_path, 'w') f.write("\n".join(alts)) finally: f.close() + # END file handling + # END alts handling alternates = property(_get_alternates, _set_alternates, doc="Retrieve a list of alternates paths or set a list paths to be used as alternates") diff --git a/test/git/test_repo.py b/test/git/test_repo.py index c89bcde3..bc2c7094 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -142,17 +142,15 @@ class TestRepo(TestCase): self.repo.daemon_export = orig_val assert self.repo.daemon_export == orig_val - @patch_object(os.path, 'exists') - def test_alternates_no_file(self, os): - os.return_value = False - assert_equal([], self.repo.alternates) - - assert_true(os.called) - - @patch_object(os, 'remove') - def test_alternates_setter_empty(self, os): + def test_alternates(self): + cur_alternates = self.repo.alternates + # empty alternates self.repo.alternates = [] - assert_true(os.called) + assert self.repo.alternates == [] + alts = [ "other/location", "this/location" ] + self.repo.alternates = alts + assert alts == self.repo.alternates + self.repo.alternates = cur_alternates def test_repr(self): path = os.path.join(os.path.abspath(GIT_REPO), '.git') |