vim-githubinator icon indicating copy to clipboard operation
vim-githubinator copied to clipboard

invalid URLs generated when multiple remotes are present

Open mwcz opened this issue 7 years ago • 2 comments

Inside this repo, the following...

    let l:git_remote = system("cat .git/config | grep \"url\" | sed \"s/url.*://g\" | awk '{print \"https://github.com/\", $0}' | tr -d '[:blank:]' | sed \"s/\.git$//g\" | tr -d '\n'")

returns this, a concatenation of all the remotes' URLs:

https://github.com/RHElements/rhelementshttps://github.com/kylebuch8/rhelements

mwcz avatar Jul 31 '18 18:07 mwcz

The command could be changed to this, which targets the "origin" remote only.

cat .git/config 
 | grep \"remote \\"origin\\"\" -A1
 | grep \"url\" 
 | sed \"s/url.*://g\" 
 | awk '{print \"https://github.com/\", $0}' 
 | tr -d '[:blank:]' 
 | sed \"s/\.git$//g\" 
 | tr -d '\n'

But it would fail to return anything for a repo without a remote named "origin".

mwcz avatar Jul 31 '18 18:07 mwcz

Okay, my bad. Since I was using an ssh remote URL when I wrote this, I somehow overlooked the fact that this could cause an issue. But could you make sure this works for you?

cat .git/config | grep "url" | sed "s/url.*= //g" | sed "s/^[ \t]//g" | awk '{if ($0 ~ /^https.*/) {print $0} else {if ($0 ~ /^git.*/) {gsub("^git.*:", "https://github.com/", $0); print}}}'

Checks whether the remote URL is https or SSH and applies replace accordingly.

danishprakash avatar Aug 02 '18 12:08 danishprakash