diff --git a/git-open b/git-open index a05e8a5..0f74a70 100755 --- a/git-open +++ b/git-open @@ -1,11 +1,40 @@ #!/usr/bin/env bash -# Opens the GitHub page for a repo/branch in your browser. -# https://github.com/paulirish/git-open/ -# -# git open -# git open [remote] [branch] +# Use git-sh-setup, similar to git-rebase +# https://www.kernel.org/pub/software/scm/git/docs/git-sh-setup.html +# https://github.com/git/git/blob/master/git-rebase.sh +# shellcheck disable=SC2034 +OPTIONS_STUCKLONG=t +# shellcheck disable=SC2034 +OPTIONS_KEEPDASHDASH= +# shellcheck disable=SC2034 +OPTIONS_SPEC="\ +git open [options] +git open [remote] [branch] +git open issue +-- + Opens the GitHub page for a repo/branch in your browser. + https://github.com/paulirish/git-open/ + Available options are +i,issue! open issues page +" + +# https://github.com/koalaman/shellcheck/wiki/SC1090 +# shellcheck source=/dev/null +. "$(git --exec-path)/git-sh-setup" + +# Defaults +is_issue=0 +protocol="https" + +while test $# != 0; do + case "$1" in + --issue) is_issue=1;; + --) shift; break ;; + esac + shift +done # are we in a git repo? if ! git rev-parse --is-inside-work-tree &>/dev/null; then @@ -13,10 +42,6 @@ if ! git rev-parse --is-inside-work-tree &>/dev/null; then exit 1 fi -# Defaults -is_issue=0 -protocol="https" - # If the first argument is 'issue', we want to load the issue page if [[ "$1" == 'issue' ]]; then is_issue=1 diff --git a/test/git-open.bats b/test/git-open.bats index 48da34d..8521005 100755 --- a/test/git-open.bats +++ b/test/git-open.bats @@ -20,6 +20,21 @@ setup() { assert [ -e "$foldername/.git" ] } +## +## Help +## + +@test "help text" { + run ../git-open -h + assert_output --partial "usage: git open" +} + +@test "invalid option" { + run ../git-open --invalid-option + assert_output --partial "error: unknown option \`invalid-option'" + assert_output --partial "usage: git open" +} + ## ## GitHub ## @@ -85,6 +100,15 @@ setup() { git checkout -B "fix-issue-36" run ../git-open "issue" assert_output "https://github.com/paulirish/git-open/issues/36" + + # -i and --issue + git checkout -B "fix-issue-37" + run ../git-open "--issue" + assert_output "https://github.com/paulirish/git-open/issues/37" + + git checkout -B "fix-issue-38" + run ../git-open "-i" + assert_output "https://github.com/paulirish/git-open/issues/38" } @test "gh: gist" {