From 740222babfe98e11d18ea4d7334a184c583aa15c Mon Sep 17 00:00:00 2001 From: Lars Kellogg-Stedman Date: Wed, 31 Jan 2018 16:11:51 -0500 Subject: [PATCH] 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. --- git-open | 3 +-- test/git-open.bats | 12 ++++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/git-open b/git-open index d952c3a..e0ba782 100755 --- a/git-open +++ b/git-open @@ -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 diff --git a/test/git-open.bats b/test/git-open.bats index 3f90fb4..ac89edb 100755 --- a/test/git-open.bats +++ b/test/git-open.bats @@ -35,6 +35,18 @@ setup() { assert_output --partial "usage: git open" } +## +## url handling +## + +@test "url: insteadOf handling" { + git config --global url.http://example.com/.insteadOf ex: + git remote set-url origin ex:example.git + git checkout -B master + run ../git-open + assert_output "http://example.com/example" +} + ## ## GitHub ##