Skip to content

Commit

Permalink
Use ls-remote --get-url to get remote url
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
larsks committed Feb 2, 2018
1 parent 51caa23 commit 740222b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 1 addition & 2 deletions git-open
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ remote=${1:-$default_remote}
remote=${remote:-$tracked_remote}
remote=${remote:-"origin"}

# @TODO ls-remote will also expand "insteadOf" items `giturl=$(git ls-remote --get-url $remote)``
giturl=$(git config --get "remote.${remote}.url")
giturl=$(git ls-remote --get-url "$remote")

if [[ -z "$giturl" ]]; then
echo "Git remote is not set for $remote" 1>&2
Expand Down
12 changes: 12 additions & 0 deletions test/git-open.bats
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ setup() {
assert_output --partial "usage: git open"
}

##
## url handling
##

@test "url: insteadOf handling" {
git config --global url.http:https://example.com/.insteadOf ex:
git remote set-url origin ex:example.git
git checkout -B master
run ../git-open
assert_output "http:https://example.com/example"
}

##
## GitHub
##
Expand Down

0 comments on commit 740222b

Please sign in to comment.