Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita2ec078

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

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-
foraltinalts:
465-
ifnotos.path.exists(alt):
466-
raiseNoSuchPathError("Could not set alternates. Alternate path %s must exist"%alt)
467-
468+
alternates_path=os.path.join(self.path,'objects','info','alternates')
468469
ifnotalts:
469-
os.remove(os.path.join(self.path,'objects','info','alternates'))
470+
ifos.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-
deftest_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-
deftest_alternates_setter_empty(self,os):
210+
deftest_alternates(self):
211+
cur_alternates=self.repo.alternates
212+
# empty alternates
219213
self.repo.alternates= []
220-
assert_true(os.called)
214+
assertself.repo.alternates== []
215+
alts= ["other/location","this/location" ]
216+
self.repo.alternates=alts
217+
assertalts==self.repo.alternates
218+
self.repo.alternates=cur_alternates
221219

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp