diff --git a/git-open b/git-open index fc6a1c5..a05e8a5 100755 --- a/git-open +++ b/git-open @@ -25,8 +25,11 @@ if [[ "$1" == 'issue' ]]; then shift fi -# assume remote origin if not provided -remote=${1:-"origin"} +# choose remote. priority to: provided argument, detected tracked remote, 'origin' +branch_name=$(git name-rev --name-only HEAD 2>/dev/null) +tracked_remote=$(git config "branch.$branch_name.remote") +remote=${1:-$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") diff --git a/test/git-open.bats b/test/git-open.bats index 1192dae..3d331c3 100755 --- a/test/git-open.bats +++ b/test/git-open.bats @@ -104,6 +104,24 @@ setup() { assert_output "https://github.com/paulirish/git-open/tree/just-50%25" } +@test "basic: tracked remote is default" { + # https://github.com/paulirish/git-open/issues/65 + + # create a local git repo I can push to + local_remote="sandboxremote" + cd .. && rm -rf $local_remote && mkdir $local_remote && cd $local_remote && + git init --bare myrepo.git && + cd ../$foldername + + git remote add other "../$local_remote/myrepo.git" + git push --set-upstream other master + run ../git-open + # Not an ideal assertion, but it works.. + assert_output "https://../$local_remote/myrepo" + + # cleanup + rm -rf ../$local_remote +} ##