Skip to content

Commit ba01785

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 <guyzmo+github@m0g.net>
1 parent 902679c commit ba01785

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

git/remote.py

Lines changed: 15 additions & 0 deletions
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):
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):
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)
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