Git styled -h and --issue options

Use git-sh-setup (like git rebase) to get git styled help (-h) option
and -i, --issue for issue option
This commit is contained in:
Love F 2017-09-06 18:16:04 +02:00
parent 07d75b2e1e
commit b25348e368
2 changed files with 58 additions and 9 deletions

View file

@ -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

View file

@ -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" {