Skip to content

Add support ssh:// URL and github local branch name fix. #148

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 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 6 additions & 6 deletions git_repo/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,15 @@ def _guess_repo_slug(self, repository, service, resolve_targets=None):
for remote in repository.remotes:
if remote.name in targets:
for url in remote.urls:
if url.startswith('https'):
if url.endswith('.git'):
url = url[:-4]
if url.endswith('.git'):
url = url[:-4]
if url.find('://') > -1:
# http://, https:// and ssh://
*_, user, name = url.split('/')
self.set_repo_slug('/'.join([user, name]))
return
elif url.startswith('git@'):
if url.endswith('.git'):
url = url[:-4]
elif url.find('@') > -1 and url.find(':') > -1:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so you know, this is not very pythonic, the pythonic way is if '@' in url 😉

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, thanks for comments!

# scp-style URL
_, repo_slug = url.split(':')
self.set_repo_slug(repo_slug)
return
Expand Down
5 changes: 4 additions & 1 deletion git_repo/services/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,10 @@ def format_path(self, repository, namespace=None, rw=False):
if not rw and '/' in repo:
return '{}/{}'.format(self.url_ro, repo)
elif rw and '/' in repo:
return '{}:{}'.format(self.url_rw, repo)
if self.url_rw.startswith('ssh://'):
return '{}/{}'.format(self.url_rw, repo)
else:
return '{}:{}'.format(self.url_rw, repo)
else:
raise ArgumentError("Cannot tell how to handle this url: `{}/{}`!".format(namespace, repo))

Expand Down