vim-githubinator
vim-githubinator copied to clipboard
invalid URLs generated when multiple remotes are present
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
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".
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.