frace / git-passport

A Git command and hook written in Python to manage multiple Git accounts / user identities.
https://github.com/frace/git-passport
Other
109 stars 25 forks source link

urlparse doesn't always give 'base url' #31

Open tverlaan opened 9 years ago

tverlaan commented 9 years ago

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('git@github.com:tverlaan/git-passport')
ParseResult(scheme='', netloc='', path='git@github.com: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:

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.

frace commented 9 years ago

@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 "git@github.com: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.

tverlaan commented 9 years ago

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 commented 9 years ago

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.

frace commented 9 years ago

@tverlaan Could you please give an example?

tverlaan commented 9 years ago

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.

frace commented 9 years ago

Ok, I see.

dhergert commented 8 years ago

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

Richard-Degenne commented 7 years ago

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!