Skip to content

Conversation

larsks
Copy link
Contributor

@larsks larsks commented Jan 31, 2018

As noted in a comment, 'git ls-url --get-url' will expand insteadOf
mappings. I use a number of shortcuts (like gh: for git on github,
lp: for git on launchpad, me: for my github repositories, etc), so I
was constantly hitting situations in which git-open would fail to do
the right thing.

It looks like '--get-url' has been available since git 2.12.0.

This has been bugging me for a while, but the fact that it was listed
in a comment in the script and not implemented makes me wonder if
there was in fact a reason for that.

Copy link
Contributor

@4U6U57 4U6U57 left a comment

Choose a reason for hiding this comment

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

Please add a unit test in git-open/test/git-open.bats testing this functionality (adding an insteadOf config and verifying that it expands correctly).

@4U6U57
Copy link
Contributor

4U6U57 commented Feb 1, 2018

I'm not sure exactly why that code was added as a comment instead of patched in outright, I think @derimagia would be able to answer that?

I do think this is something that should be brought up to the team. 👍

@larsks
Copy link
Contributor Author

larsks commented Feb 1, 2018

@4U6U57 I added a unit test; let me know if that's sufficient.

@derimagia
Copy link
Collaborator

Thanks for the patch! Been meaning to switch this over - I wasn't 100% on git versions it was available. We may need to figure this out in a This looks good to me 👍

@larsks larsks changed the title Use ls-url to get remote url Use ls-remote --get-url to get remote url Feb 2, 2018
As noted in a comment, 'git ls-remote --get-url' will expand insteadOf
mappings.  I use a number of shortcuts (like gh: for git on github,
lp: for git on launchpad, me: for my github repositories, etc), so I
was constantly hitting situations in which git-open would fail to do
the right thing.

It looks like '--get-url' has been available since git 2.12.0.
@larsks
Copy link
Contributor Author

larsks commented Feb 2, 2018

If you were really concerned about older git versions, you could do something terrible like this...

# check git version
git_version=($(git version | cut -f3 -d' ' | tr '.' ' '))

if [ "${git_version[0]}" -lt 2 -o "${git_version[1]}" -lt 12 ]; then
  giturl=$(git config --get "remote.${remote}.url")
else
  giturl=$(git ls-remote --get-url "$remote")
fi

@nwinkler
Copy link
Contributor

nwinkler commented Feb 4, 2018

Instead of checking for the version number, why not check the git help command for the presence of the --get-url parameter?

git help ls-remote | grep '\-\-get-url' | wc -l

@larsks
Copy link
Contributor Author

larsks commented Feb 4, 2018

Sure, that works.

@derimagia
Copy link
Collaborator

@paulirish Ideas on how you wanted to deal with versions of git? Another option is just to fall back to the other way in an or statement.

@derimagia
Copy link
Collaborator

derimagia commented Feb 4, 2018

Actually may be a non-issue, looks like it was documented here git/git@2303cad and actually added here git/git@45781ad - that's long enough ago that I don't think we care - thought it was added more recent than that

@derimagia derimagia merged commit 7449bfa into paulirish:master Feb 4, 2018
@paulirish
Copy link
Owner

wow. nice digging!

Yeah I just tried --get-url on an september 2015-era release of git 2.3.7 and it worked great. So yeah 👍 to not worrying about compat on this one.

4U6U57 added a commit to 4U6U57/git-open that referenced this pull request Feb 27, 2018
Remove package-lock.json from gitignore for npm
Fix bug in paulirish#115 that modified user's gitconfig when running tests
iblea pushed a commit to iblea/git-open that referenced this pull request Jun 17, 2024
Use ls-remote --get-url to get remote url
iblea pushed a commit to iblea/git-open that referenced this pull request Jun 17, 2024
Remove package-lock.json from gitignore for npm
Fix bug in paulirish#115 that modified user's gitconfig when running tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants