Skip to content

Commit 546dfeb

Browse files
committed
Adding set_url and list_urls methods to Remote
Both commands enable handling of a little known feature of git, which is to support multiple URL for one remote. You can add multiple url using the `set_url` subcommand of `git remote`. Though listing them is also handy, so there's a nice method to do it, using the configuration. Signed-off-by: Guyzmo <[email protected]>
1 parent 902679c commit 546dfeb

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Diff for: git/remote.py

+15
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,21 @@ def iter_items(cls, repo):
434434
yield Remote(repo, section[lbound + 1:rbound])
435435
# END for each configuration section
436436

437+
def set_url(self, url, **kwargs): # pragma: no cover
438+
'''Configure a new url on current remote (cf command git remote set_url'''
439+
scmd = 'set-url'
440+
kwargs['insert_kwargs_after'] = scmd
441+
self.repo.git.remote(scmd, self.name, url, **kwargs)
442+
return self
443+
444+
@property
445+
def list_urls(self): # pragma: no cover
446+
'''Return the list of all configured URL targets'''
447+
remote_details = self.repo.git.remote("show", self.name)
448+
for line in remote_details.split('\n'):
449+
if ' Push URL:' in line:
450+
yield line.split(': ')[-1]
451+
437452
@property
438453
def refs(self):
439454
"""

0 commit comments

Comments
 (0)