| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e0b21f4 commit 6b1dd8b
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -452,6 +452,54 @@ def iter_items(cls, repo): | |||
| 452 | 452 | yield Remote(repo, section[lbound + 1:rbound]) | |
| 453 | 453 | # END for each configuration section | |
| 454 | 454 | ||
| 455 | + def set_url(self, new_url, old_url=None, **kwargs): | ||
| 456 | + """Configure URLs on current remote (cf command git remote set_url) | ||
| 457 | + | ||
| 458 | + This command manages URLs on the remote. | ||
| 459 | + | ||
| 460 | + :param new_url: string being the URL to add as an extra remote URL | ||
| 461 | + :param old_url: when set, replaces this URL with new_url for the remote | ||
| 462 | + :return: self | ||
| 463 | + """ | ||
| 464 | + scmd = 'set-url' | ||
| 465 | + kwargs['insert_kwargs_after'] = scmd | ||
| 466 | + if old_url: | ||
| 467 | + self.repo.git.remote(scmd, self.name, old_url, new_url, **kwargs) | ||
| 468 | + else: | ||
| 469 | + self.repo.git.remote(scmd, self.name, new_url, **kwargs) | ||
| 470 | + return self | ||
| 471 | + | ||
| 472 | + def add_url(self, url, **kwargs): | ||
| 473 | + """Adds a new url on current remote (special case of git remote set_url) | ||
| 474 | + | ||
| 475 | + This command adds new URLs to a given remote, making it possible to have | ||
| 476 | + multiple URLs for a single remote. | ||
| 477 | + | ||
| 478 | + :param url: string being the URL to add as an extra remote URL | ||
| 479 | + :return: self | ||
| 480 | + """ | ||
| 481 | + return self.set_url(url, add=True) | ||
| 482 | + | ||
| 483 | + def delete_url(self, url, **kwargs): | ||
| 484 | + """Deletes a new url on current remote (special case of git remote set_url) | ||
| 485 | + | ||
| 486 | + This command deletes new URLs to a given remote, making it possible to have | ||
| 487 | + multiple URLs for a single remote. | ||
| 488 | + | ||
| 489 | + :param url: string being the URL to delete from the remote | ||
| 490 | + :return: self | ||
| 491 | + """ | ||
| 492 | + return self.set_url(url, delete=True) | ||
| 493 | + | ||
| 494 | + @property | ||
| 495 | + def urls(self): | ||
| 496 | + """:return: Iterator yielding all configured URL targets on a remote | ||
| 497 | + as strings""" | ||
| 498 | + scmd = 'get-url' | ||
| 499 | + kwargs = {'insert_kwargs_after': scmd} | ||
| 500 | + for url in self.repo.git.remote(scmd, self.name, all=True, **kwargs).split('\n'): | ||
| 501 | + yield url | ||
| 502 | + | ||
| 455 | 503 | @property | |
| 456 | 504 | def refs(self): | |
| 457 | 505 | """ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,7 +9,8 @@ | |||
| 9 | 9 | with_rw_repo, | |
| 10 | 10 | with_rw_and_rw_remote_repo, | |
| 11 | 11 | fixture, | |
| 12 | - GIT_DAEMON_PORT | ||
| 12 | + GIT_DAEMON_PORT, | ||
| 13 | + assert_raises | ||
| 13 | 14 | ) | |
| 14 | 15 | from git import ( | |
| 15 | 16 | RemoteProgress, | |
@@ -62,7 +63,7 @@ def update(self, op_code, cur_count, max_count=None, message=''): | |||
| 62 | 63 | # check each stage only comes once | |
| 63 | 64 | op_id = op_code & self.OP_MASK | |
| 64 | 65 | assert op_id in (self.COUNTING, self.COMPRESSING, self.WRITING) | |
| 65 | - | ||
| 66 | + | ||
| 66 | 67 | if op_code & self.WRITING > 0: | |
| 67 | 68 | if op_code & self.BEGIN > 0: | |
| 68 | 69 | assert not message, 'should not have message when remote begins writing' | |
@@ -568,3 +569,47 @@ def test_uncommon_branch_names(self): | |||
| 568 | 569 | assert res[0].remote_ref_path == 'refs/pull/1/head' | |
| 569 | 570 | assert res[0].ref.path == 'refs/heads/pull/1/head' | |
| 570 | 571 | assert isinstance(res[0].ref, Head) | |
| 572 | + | ||
| 573 | + @with_rw_repo('HEAD', bare=False) | ||
| 574 | + def test_multiple_urls(self, rw_repo): | ||
| 575 | + # test addresses | ||
| 576 | + test1 = 'https://github.com/gitpython-developers/GitPython' | ||
| 577 | + test2 = 'https://github.com/gitpython-developers/gitdb' | ||
| 578 | + test3 = 'https://github.com/gitpython-developers/smmap' | ||
| 579 | + | ||
| 580 | + remote = rw_repo.remotes[0] | ||
| 581 | + # Testing setting a single URL | ||
| 582 | + remote.set_url(test1) | ||
| 583 | + assert list(remote.urls) == [test1] | ||
| 584 | + | ||
| 585 | + # Testing replacing that single URL | ||
| 586 | + remote.set_url(test1) | ||
| 587 | + assert list(remote.urls) == [test1] | ||
| 588 | + # Testing adding new URLs | ||
| 589 | + remote.set_url(test2, add=True) | ||
| 590 | + assert list(remote.urls) == [test1, test2] | ||
| 591 | + remote.set_url(test3, add=True) | ||
| 592 | + assert list(remote.urls) == [test1, test2, test3] | ||
| 593 | + # Testing removing an URL | ||
| 594 | + remote.set_url(test2, delete=True) | ||
| 595 | + assert list(remote.urls) == [test1, test3] | ||
| 596 | + # Testing changing an URL | ||
| 597 | + remote.set_url(test3, test2) | ||
| 598 | + assert list(remote.urls) == [test1, test2] | ||
| 599 | + | ||
| 600 | + # will raise: fatal: --add --delete doesn't make sense | ||
| 601 | + assert_raises(GitCommandError, remote.set_url, test2, add=True, delete=True) | ||
| 602 | + | ||
| 603 | + # Testing on another remote, with the add/delete URL | ||
| 604 | + remote = rw_repo.create_remote('another', url=test1) | ||
| 605 | + remote.add_url(test2) | ||
| 606 | + assert list(remote.urls) == [test1, test2] | ||
| 607 | + remote.add_url(test3) | ||
| 608 | + assert list(remote.urls) == [test1, test2, test3] | ||
| 609 | + # Testing removing all the URLs | ||
| 610 | + remote.delete_url(test2) | ||
| 611 | + assert list(remote.urls) == [test1, test3] | ||
| 612 | + remote.delete_url(test1) | ||
| 613 | + assert list(remote.urls) == [test3] | ||
| 614 | + # will raise fatal: Will not delete all non-push URLs | ||
| 615 | + assert_raises(GitCommandError, remote.delete_url, test3) | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments