feat: default-branch option

This commit is contained in:
phwt 2022-08-12 16:46:07 +07:00
parent 58648dfdd2
commit 153adb5089
2 changed files with 24 additions and 5 deletions

View file

@ -16,10 +16,11 @@ git open [remote] [branch]
https://github.com/paulirish/git-open/ https://github.com/paulirish/git-open/
Available options are Available options are
c,commit! open current commit c,commit! open current commit
i,issue! open issues page i,issue! open issues page
s,suffix= append this suffix s,suffix= append this suffix
p,print! just print the url p,print! just print the url
d,default-branch! open the repo as if you were in the default branch (master/main)
" "
# https://github.com/koalaman/shellcheck/wiki/SC1090 # https://github.com/koalaman/shellcheck/wiki/SC1090
@ -32,6 +33,7 @@ is_issue=0
protocol="https" protocol="https"
print_only=0 print_only=0
suffix_flag="" suffix_flag=""
use_default_branch=0
while test $# != 0; do while test $# != 0; do
case "$1" in case "$1" in
@ -39,6 +41,7 @@ while test $# != 0; do
--issue) is_issue=1;; --issue) is_issue=1;;
--suffix=*) suffix_flag="$1";; --suffix=*) suffix_flag="$1";;
--print) print_only=1;; --print) print_only=1;;
--default-branch) use_default_branch=1;;
--) shift; break ;; --) shift; break ;;
esac esac
shift shift
@ -241,7 +244,7 @@ openurl="$protocol://$domain/$urlpath"
if (( is_commit )); then if (( is_commit )); then
sha=$(git rev-parse HEAD) sha=$(git rev-parse HEAD)
openurl="$openurl/commit/$sha" openurl="$openurl/commit/$sha"
elif [[ $remote_ref != "master" && $remote_ref != "main" ]]; then elif [[ $remote_ref != "master" && $remote_ref != "main" && $use_default_branch != 1 ]]; then
# simplify URL for master and main # simplify URL for master and main
openurl="$openurl$providerBranchRef" openurl="$openurl$providerBranchRef"
fi fi

View file

@ -66,6 +66,22 @@ setup() {
assert_output "http://example.com/example" assert_output "http://example.com/example"
} }
@test "url: use default branch" {
git config --local url.http://example.com/.insteadOf ex:
git remote set-url origin ex:example.git
git checkout -B development
run ../git-open -d
assert_output "http://example.com/example"
}
@test "url: use-default with suffix" {
git config --local url.http://example.com/.insteadOf ex:
git remote set-url origin ex:example.git
git checkout -B development
run ../git-open -d -s actions
assert_output "http://example.com/example/actions"
}
## ##
## GitHub ## GitHub
## ##