diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2009-10-21 14:47:38 +0200 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2009-10-21 14:47:38 +0200 |
commit | a2ec078f25eb357edd1912ca3dbd578979a51226 (patch) | |
tree | e475fd9bc73b141b52e3117f6650a512987636e5 | |
parent | a7f52745c95e5dd673a79a2281ccd7463ce00ffa (diff) | |
download | gitpython-a2ec078f25eb357edd1912ca3dbd578979a51226.tar.gz |
Fixed repo.alternates implementation which didn't work in the 'real' world with a non-mock test
-rw-r--r-- | lib/git/repo.py | 22 | ||||
-rw-r--r-- | test/git/test_repo.py | 18 |
2 files changed, 21 insertions, 19 deletions
diff --git a/lib/git/repo.py b/lib/git/repo.py index 1c4b4095..ae9b94c3 100644 --- a/lib/git/repo.py +++ b/lib/git/repo.py @@ -455,24 +455,28 @@ class Repo(object): is the array of string paths representing the alternates at which git should look for objects, i.e. /home/user/repo/.git/objects - Raises - NoSuchPathError - + 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 1c5b50d9..8927971a 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -207,17 +207,15 @@ class TestRepo(object): self.repo.daemon_serve = True assert_true(self.repo.daemon_serve) - @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') |