| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -455,24 +455,28 @@ def _set_alternates(self, alts): | |||
| 455 | 455 | is the array of string paths representing the alternates at which | |
| 456 | 456 | git should look for objects, i.e. /home/user/repo/.git/objects | |
| 457 | 457 | ||
| 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 | + | ||
| 461 | 465 | Returns | |
| 462 | 466 | None | |
| 463 | 467 | """ | |
| 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') | ||
| 468 | 469 | 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) | ||
| 470 | 472 | else: | |
| 471 | 473 | try: | |
| 472 | - f = open(os.path.join(self.path, 'objects', 'info', 'alternates'), 'w') | ||
| 474 | + f = open(alternates_path, 'w') | ||
| 473 | 475 | f.write("\n".join(alts)) | |
| 474 | 476 | finally: | |
| 475 | 477 | f.close() | |
| 478 | + # END file handling | ||
| 479 | + # END alts handling | ||
| 476 | 480 | ||
| 477 | 481 | alternates = property(_get_alternates, _set_alternates, doc="Retrieve a list of alternates paths or set a list paths to be used as alternates") | |
| 478 | 482 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -207,17 +207,15 @@ def test_disable_daemon_serve(self): | |||
| 207 | 207 | self.repo.daemon_serve = True | |
| 208 | 208 | assert_true(self.repo.daemon_serve) | |
| 209 | 209 | ||
| 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 | ||
| 219 | 213 | 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 | ||
| 221 | 219 | ||
| 222 | 220 | def test_repr(self): | |
| 223 | 221 | path = os.path.join(os.path.abspath(GIT_REPO), '.git') | |
| Back | FazBrowse Home | New Git URL |
0 commit comments