mirror of
https://github.com/paulirish/git-open.git
synced 2026-09-10 07:26:15 -04:00
feat: default-branch option
This commit is contained in:
parent
58648dfdd2
commit
153adb5089
13
git-open
13
git-open
|
|
@ -16,10 +16,11 @@ git open [remote] [branch]
|
|||
https://github.com/paulirish/git-open/
|
||||
|
||||
Available options are
|
||||
c,commit! open current commit
|
||||
i,issue! open issues page
|
||||
s,suffix= append this suffix
|
||||
p,print! just print the url
|
||||
c,commit! open current commit
|
||||
i,issue! open issues page
|
||||
s,suffix= append this suffix
|
||||
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
|
||||
|
|
@ -32,6 +33,7 @@ is_issue=0
|
|||
protocol="https"
|
||||
print_only=0
|
||||
suffix_flag=""
|
||||
use_default_branch=0
|
||||
|
||||
while test $# != 0; do
|
||||
case "$1" in
|
||||
|
|
@ -39,6 +41,7 @@ while test $# != 0; do
|
|||
--issue) is_issue=1;;
|
||||
--suffix=*) suffix_flag="$1";;
|
||||
--print) print_only=1;;
|
||||
--default-branch) use_default_branch=1;;
|
||||
--) shift; break ;;
|
||||
esac
|
||||
shift
|
||||
|
|
@ -241,7 +244,7 @@ openurl="$protocol://$domain/$urlpath"
|
|||
if (( is_commit )); then
|
||||
sha=$(git rev-parse HEAD)
|
||||
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
|
||||
openurl="$openurl$providerBranchRef"
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -66,6 +66,22 @@ setup() {
|
|||
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
|
||||
##
|
||||
|
|
|
|||
Loading…
Reference in a new issue