diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2016-06-14 07:46:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-06-14 07:46:26 +0200 |
commit | 9bebaca85a19e0ac8a776ee09981f0c826e1cafa (patch) | |
tree | 1f11a3291c0acf3093ed72ecf9fb961a2d02912f /git/remote.py | |
parent | d22c40b942cca16ff9e70d879b669c97599406b7 (diff) | |
parent | 3f4b410c955ea08bfb7842320afa568090242679 (diff) | |
download | gitpython-9bebaca85a19e0ac8a776ee09981f0c826e1cafa.tar.gz |
Merge pull request #446 from guyzmo/updating_remote_url_handling
Adding support for git remote set-url/get-url API to Remote
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 e30debb7..75a6875f 100644 --- a/git/remote.py +++ b/git/remote.py @@ -451,6 +451,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""" + remote_details = self.repo.git.remote("show", self.name) + for line in remote_details.split('\n'): + if ' Push URL:' in line: + yield line.split(': ')[-1] + @property def refs(self): """ |