diff options
author | Guyzmo <guyzmo+github@m0g.net> | 2016-05-26 20:43:28 +0200 |
---|---|---|
committer | Guyzmo <guyzmo+github@m0g.net> | 2016-06-08 19:34:29 +0200 |
commit | b366d3fabd79e921e30b44448cb357a05730c42f (patch) | |
tree | 6d6ab0a14a6e89b2cd52fc993663f2d6b8a274ed /git/remote.py | |
parent | 902679c47c3d1238833ac9c9fdbc7c0ddbedf509 (diff) | |
download | gitpython-b366d3fabd79e921e30b44448cb357a05730c42f.tar.gz |
Adding support for git remote set-url/get-url API 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`. As listing them is also handy, there's a
nice method to do it, using `get_url`.
* adding set_url method that maps to the git remote set-url command¶
* can be used to set an URL, or replace an URL with optional positional arg¶
* can be used to add, delete URL with kwargs (matching set-url options)¶
* adding add_url, delete_url methods that wraps around set_url for conveniency¶
* adding urls property that yields an iterator over the setup urls for a remote¶
* adding a test suite that checks all use case scenarii of this added API.¶
Signed-off-by: Guyzmo <guyzmo+github@m0g.net>
Diffstat (limited to 'git/remote.py')
-rw-r--r-- | git/remote.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/git/remote.py b/git/remote.py index 92203588..ef02c629 100644 --- a/git/remote.py +++ b/git/remote.py @@ -434,6 +434,54 @@ class Remote(LazyMixin, Iterable): yield Remote(repo, section[lbound + 1:rbound]) # END for each configuration section + def set_url(self, new_url, old_url=None, **kwargs): + """Configure URLs on current remote (cf command git remote set_url) + + This command manages URLs on the remote. + + :param new_url: string being the URL to add as an extra remote URL + :param old_url: when set, replaces this URL with new_url for the remote + :return: self + """ + scmd = 'set-url' + kwargs['insert_kwargs_after'] = scmd + if old_url: + self.repo.git.remote(scmd, self.name, old_url, new_url, **kwargs) + else: + self.repo.git.remote(scmd, self.name, new_url, **kwargs) + return self + + def add_url(self, url, **kwargs): + """Adds a new url on current remote (special case of git remote set_url) + + This command adds new URLs to a given remote, making it possible to have + multiple URLs for a single remote. + + :param url: string being the URL to add as an extra remote URL + :return: self + """ + return self.set_url(url, add=True) + + def delete_url(self, url, **kwargs): + """Deletes a new url on current remote (special case of git remote set_url) + + This command deletes new URLs to a given remote, making it possible to have + multiple URLs for a single remote. + + :param url: string being the URL to delete from the remote + :return: self + """ + return self.set_url(url, delete=True) + + @property + def urls(self): + """:return: Iterator yielding all configured URL targets on a remote + as strings""" + scmd = 'get-url' + kwargs = {'insert_kwargs_after': scmd} + for url in self.repo.git.remote(scmd, self.name, all=True, **kwargs).split('\n'): + yield url + @property def refs(self): """ |