Skip to content

Commit a2ec078

Browse files
committed
Fixed repo.alternates implementation which didn't work in the 'real' world with a non-mock test
1 parent a7f5274 commit a2ec078

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

lib/git/repo.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -455,24 +455,28 @@ def _set_alternates(self, alts):
455455
is the array of string paths representing the alternates at which
456456
git should look for objects, i.e. /home/user/repo/.git/objects
457457
458-
Raises
459-
NoSuchPathError
460-
458+
Raises
459+
NoSuchPathError
460+
461+
Note
462+
The method does not check for the existance of the paths in alts
463+
as the caller is responsible.
464+
461465
Returns
462466
None
463467
"""
464-
for alt in alts:
465-
if not os.path.exists(alt):
466-
raise NoSuchPathError("Could not set alternates. Alternate path %s must exist" % alt)
467-
468+
alternates_path = os.path.join(self.path, 'objects', 'info', 'alternates')
468469
if not alts:
469-
os.remove(os.path.join(self.path, 'objects', 'info', 'alternates'))
470+
if os.path.isfile(alternates_path):
471+
os.remove(alternates_path)
470472
else:
471473
try:
472-
f = open(os.path.join(self.path, 'objects', 'info', 'alternates'), 'w')
474+
f = open(alternates_path, 'w')
473475
f.write("\n".join(alts))
474476
finally:
475477
f.close()
478+
# END file handling
479+
# END alts handling
476480

477481
alternates = property(_get_alternates, _set_alternates, doc="Retrieve a list of alternates paths or set a list paths to be used as alternates")
478482

test/git/test_repo.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -207,17 +207,15 @@ def test_disable_daemon_serve(self):
207207
self.repo.daemon_serve = True
208208
assert_true(self.repo.daemon_serve)
209209

210-
@patch_object(os.path, 'exists')
211-
def test_alternates_no_file(self, os):
212-
os.return_value = False
213-
assert_equal([], self.repo.alternates)
214-
215-
assert_true(os.called)
216-
217-
@patch_object(os, 'remove')
218-
def test_alternates_setter_empty(self, os):
210+
def test_alternates(self):
211+
cur_alternates = self.repo.alternates
212+
# empty alternates
219213
self.repo.alternates = []
220-
assert_true(os.called)
214+
assert self.repo.alternates == []
215+
alts = [ "other/location", "this/location" ]
216+
self.repo.alternates = alts
217+
assert alts == self.repo.alternates
218+
self.repo.alternates = cur_alternates
221219

222220
def test_repr(self):
223221
path = os.path.join(os.path.abspath(GIT_REPO), '.git')

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy