Skip to content

Improved way of listing URLs in remote #528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 18 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
remote, #528: fix prev cmt, Git<2.7 miss get-url
  • Loading branch information
ankostis authored and guyzmo committed Oct 12, 2016
commit 32ca6864a9528cc483e9eaeb7ebd25c5e95dc376
22 changes: 17 additions & 5 deletions git/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from gitdb.util import join
from git.compat import (defenc, force_text, is_win)
import logging
from git.exc import GitCommandError

log = logging.getLogger('git.remote')

Expand Down Expand Up @@ -494,11 +495,22 @@ def delete_url(self, url, **kwargs):

@property
def urls(self):
""":return: Iterator yielding all configured URL targets on a remote
as strings"""
remote_details = self.repo.git.remote("get-url", "--all", self.name)
for line in remote_details.split('\n'):
yield line
""":return: Iterator yielding all configured URL targets on a remote as strings"""
try:
remote_details = self.repo.git.remote("get-url", "--all", self.name)
for line in remote_details.split('\n'):
yield line
except GitCommandError as ex:
## We are on git < 2.7 (i.e TravisCI as of Oct-2016),
# so `get-utl` command does not exist yet!
# see: https://github.com/gitpython-developers/GitPython/pull/528#issuecomment-252976319
# and: http://stackoverflow.com/a/32991784/548792
#
if 'Unknown subcommand: get-url' in str(ex):
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):
Expand Down