diff --git a/README.md b/README.md index 2f6834b..1a8b74f 100644 --- a/README.md +++ b/README.md @@ -150,7 +150,7 @@ Please provide examples of the URLs you are parsing with each PR. ### Testing: -You'll need to install [bats](https://github.com/sstephenson/bats#installing-bats-from-source), the Bash automated testing system. It's also available as `brew install bats` +You'll need to install [bats](https://github.com/bats-core/bats-core), the Bash automated testing system. It's also available as `brew install bats-core` ```sh git submodule update --init # pull in the assertion libraries diff --git a/git-open b/git-open index bc3d121..23bc0c7 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 +b,ignore-branch! just open the repo regardless of the currently checked out branch " # https://github.com/koalaman/shellcheck/wiki/SC1090 @@ -32,6 +33,7 @@ is_issue=0 protocol="https" print_only=0 suffix_flag="" +ignore_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;; + --ignore-branch) ignore_branch=1;; --) shift; break ;; esac shift @@ -241,8 +244,8 @@ openurl="$protocol://$domain/$urlpath" if (( is_commit )); then sha=$(git rev-parse HEAD) openurl="$openurl/commit/$sha" -elif [[ $remote_ref != "master" ]]; then - # simplify URL for master +elif [[ $remote_ref != "master" && $remote_ref != "main" && $ignore_branch != 1 ]]; then + # simplify URL for master and main openurl="$openurl$providerBranchRef" fi diff --git a/git-open.1.md b/git-open.1.md index 5c63db3..54fece2 100644 --- a/git-open.1.md +++ b/git-open.1.md @@ -23,6 +23,9 @@ git hosting services are supported. it will open the webpage with that issue. See `EXAMPLES` for more information. This only works on GitHub, GitLab, Visual Studio Team Services and Team Foundation Server at the moment. +`-b`, `--ignore-branch` + Just open the repository regardless of the currently checked out branch + `-s`, `--suffix` some_suffix Append the given suffix to the url @@ -59,6 +62,13 @@ git open --issue If branches use naming convention of `issues/#123`, it opens https://github.com/TRACKED_REMOTE_USER/CURRENT_REPO/issues/123 + +```sh +git open --ignore-branch +``` + +It won't suffix the url with `/tree/CURRENT_BRANCH` regardless of the currently checked out branch, it opens https://github.com/TRACKED_REMOTE_USER/CURRENT_REPO/ + ```sh git open --suffix pulls ``` diff --git a/test/git-open.bats b/test/git-open.bats index 32c0fe1..8979a0f 100755 --- a/test/git-open.bats +++ b/test/git-open.bats @@ -58,6 +58,30 @@ setup() { assert_output "http://example.com/example" } +@test "url: simplification" { + git config --local url.http://example.com/.insteadOf ex: + git remote set-url origin ex:example.git + git checkout -B main + run ../git-open + 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 -b + 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 -b -s actions + assert_output "http://example.com/example/actions" +} + ## ## GitHub ##