From 153adb508952beaba42e6fefab22f91c52c47631 Mon Sep 17 00:00:00 2001 From: phwt <28344318+phwt@users.noreply.github.com> Date: Fri, 12 Aug 2022 16:46:07 +0700 Subject: [PATCH] feat: `default-branch` option --- git-open | 13 ++++++++----- test/git-open.bats | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/git-open b/git-open index 01a8827..9ebc6fd 100755 --- a/git-open +++ b/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 diff --git a/test/git-open.bats b/test/git-open.bats index ea13561..fb50b63 100755 --- a/test/git-open.bats +++ b/test/git-open.bats @@ -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 ##