default to branch's tracked remote

This commit is contained in:
Paul Irish 2017-06-21 11:05:50 -07:00
parent e68eee6a44
commit e58004609a
2 changed files with 23 additions and 2 deletions

View file

@ -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")

View file

@ -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
}
##