Skip to content

Commit 740222b

Browse files
committed
Use ls-remote --get-url to get remote url
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.
1 parent 51caa23 commit 740222b

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

git-open

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ remote=${1:-$default_remote}
4949
remote=${remote:-$tracked_remote}
5050
remote=${remote:-"origin"}
5151

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

5554
if [[ -z "$giturl" ]]; then
5655
echo "Git remote is not set for $remote" 1>&2

test/git-open.bats

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ setup() {
3535
assert_output --partial "usage: git open"
3636
}
3737

38+
##
39+
## url handling
40+
##
41+
42+
@test "url: insteadOf handling" {
43+
git config --global url.http://example.com/.insteadOf ex:
44+
git remote set-url origin ex:example.git
45+
git checkout -B master
46+
run ../git-open
47+
assert_output "http://example.com/example"
48+
}
49+
3850
##
3951
## GitHub
4052
##

0 commit comments

Comments
 (0)