git-passport icon indicating copy to clipboard operation
git-passport copied to clipboard

urlparse doesn't always give 'base url'

Open tverlaan opened this issue 9 years ago • 8 comments

In quite a few cases with my own repositories git-passport doesn't recognize the url correctly. This has to do with the use of urlparse. Some examples:

>>> from urllib.parse import urlparse

>>> urlparse('[email protected]:tverlaan/git-passport')
ParseResult(scheme='', netloc='', path='[email protected]:tverlaan/git-passport', params='', query='', fragment='')

>>> urlparse('github.com:tverlaan/git-passport')
ParseResult(scheme='github.com', netloc='', path='tverlaan/git-passport', params='', query='', fragment='')

>>> urlparse('https://github.com/tverlaan/git-passport.git')
ParseResult(scheme='https', netloc='github.com', path='/tverlaan/git-passport.git', params='', query='', fragment='')

I can think of two alternatives for fixing this issue:

  • string match between url in passport and git config url
  • improve url parsing

The first solution would also allow for automatic matching different usernames for different projects with the same base url (say github.com). I'm happy to issue a PR, but I wanted to discuss first.

tverlaan avatar Feb 04 '15 13:02 tverlaan

@tverlaan Thank you for your report! I could imagine the easiest solution would be to do a simple string match like

if "github.com" in "[email protected]:tverlaan/git-passport":
    ...

I'm not quite sure if it'd be more elegant to find a solution by using urllib? Because it is related in a way would you like to have a look at this issue: https://github.com/frace/git-passport/issues/28? I could incorporate the changes right in that branch.

frace avatar Feb 04 '15 13:02 frace

That would be indeed the most simple solution. This would also make it possible to have different name/email for github.com:tverlaan and github.com:somethingelse.

tverlaan avatar Feb 04 '15 13:02 tverlaan

I've thought about it. I think pattern matching is the way to go. It will cover more usecases but still allow for string matching.

tverlaan avatar Feb 04 '15 13:02 tverlaan

@tverlaan Could you please give an example?

frace avatar Feb 04 '15 14:02 frace

Well, some domains have multiple TLDs. Instead of listing each TLD (with name and possibly something after the slash, like my name), I want to use a regular expression. Eg.

>>> example = re.match('https://github\.(com|org)/tverlaan','https://github.org/tverlaan')
>>> example.group(0)
'https://github.org/tverlaan'
>>> example = re.match('https://github\.(com|org)/tverlaan','https://github.com/tverlaan')
>>> example.group(0)
'https://github.com/tverlaan'
>>> example = re.match('https://github\.(com|org)/tverlaan','https://github.net/tverlaan')
>>> example.group(0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'group'
>>> 

It's maybe not the best example, but you can imagine there are a lot more uses for this.

tverlaan avatar Feb 08 '15 18:02 tverlaan

Ok, I see.

frace avatar Feb 08 '15 23:02 frace

@frace - I see no pull requests have been approved in 18 months. If we submit a PR, can you review and incorporate?

dhergert avatar Aug 01 '16 04:08 dhergert

Allow me to bump this up.

Not being able to make the most out of git-passport when using ssh is a bit sad, it'd be lovely to have it merged!

Richard-Degenne avatar Aug 28 '17 10:08 Richard-Degenne