diff options
author | EuAndreh <eu@euandre.org> | 2021-06-12 19:01:31 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2021-06-12 19:01:31 -0300 |
commit | 69c4a5e27cfb4a347987e2dc5c9c20b29cce7d0a (patch) | |
tree | 6a5030f6f6030457c5fa70e237097642c8449424 | |
parent | tests/xdg-open: Remove unused file (diff) | |
download | git-permalink-69c4a5e27cfb4a347987e2dc5c9c20b29cce7d0a.tar.gz git-permalink-69c4a5e27cfb4a347987e2dc5c9c20b29cce7d0a.tar.xz |
src/git-permalink.sh: Fix bad treatment of -p flag
-rwxr-xr-x | src/git-permalink.sh | 29 | ||||
-rwxr-xr-x | tests/cli-opts.sh | 14 |
2 files changed, 27 insertions, 16 deletions
diff --git a/src/git-permalink.sh b/src/git-permalink.sh index f664b9e..d861ccd 100755 --- a/src/git-permalink.sh +++ b/src/git-permalink.sh @@ -1,14 +1,6 @@ #!/bin/sh set -eu -FILE="${1:-}" -MYLINENO="${2:-}" -COMMIT="$(git rev-parse HEAD)" -ORIGIN="$(git config remote.origin.url)" -OVERRIDE_CF="$(git config git-permalink.template-commit-file ||:)" -OVERRIDE_FC="$(git config git-permalink.template-file-commit ||:)" -REPOSITORY="$(basename "$PWD")" - usage() { printf 'Usage: %s [-p] FILE [LINENO]\n' "$0" } @@ -27,13 +19,18 @@ version() { echo 'git-permalink-@VERSION@ @DATE@' } -if [ -z "$FILE" ]; then +PRINTONLY=false +if [ "${1:-}" = '-p' ]; then + PRINTONLY=true + shift +fi +if [ -z "${1:-}" ]; then printf "Missing \$FILE argument\n\n" >&2 usage >&2 exit 2 fi +FILE="$1" -PRINTONLY=false # shellcheck disable=2068 for flag in $@; do case "$flag" in @@ -46,15 +43,19 @@ for flag in $@; do version exit ;; - -p) - PRINTONLY=true - shift - ;; *) ;; esac done +FILE="${1:-}" +MYLINENO="${2:-}" +COMMIT="$(git rev-parse HEAD)" +ORIGIN="$(git config remote.origin.url)" +OVERRIDE_CF="$(git config git-permalink.template-commit-file ||:)" +OVERRIDE_FC="$(git config git-permalink.template-file-commit ||:)" +REPOSITORY="$(basename "$PWD")" + euandreh() { printf 'https://git.euandreh.xyz/%s/tree/%s?id=%s%s\n' "$REPOSITORY" "$FILE" "$COMMIT" "${MYLINENO:+#n$MYLINENO}" } diff --git a/tests/cli-opts.sh b/tests/cli-opts.sh index 6bd6adf..befff4d 100755 --- a/tests/cli-opts.sh +++ b/tests/cli-opts.sh @@ -89,15 +89,25 @@ test_version_flags() { test_unsupported_flags_are_treated_as_arguments() { testing 'usupported flags are treated as arguments' + OUT="$(mktemp)" ERR="$(mktemp)" ./git-permalink --first-flag --second-flag 1>"$OUT" 2>"$ERR" STATUS=$? assert_status 0 - assert_fgrep_stdout "--first-flag" + assert_empty_stdout assert_fgrep_stderr "--first-flag" - assert_fgrep_stdout "--second-flag" assert_fgrep_stderr "--second-flag" + + OUT="$(mktemp)" + ERR="$(mktemp)" + ./git-permalink -p --first-flag --second-flag 1>"$OUT" 2>"$ERR" + STATUS=$? + assert_status 0 + assert_empty_stderr + assert_fgrep_stdout "--first-flag" + assert_fgrep_stdout "--second-flag" + test_ok } |