Skip to content

Commit 64685cb

Browse files
peffgitster
authored andcommitted
git-jump: move valid-mode check earlier
We check if the "mode" argument supplied by the user is valid by seeing if we have a mode_$mode function defined. But we don't do that until after creating the tempfile. This is wasteful (we create a tempfile but never use it), and makes it harder to add new options (the recent stdout option exits before creating the tempfile, so it misses the check and "git jump --stdout foo" will produce "git-jump: 92: mode_foo: not found" rather than the regular usage message). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cfb7b3b commit 64685cb

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

contrib/git-jump/git-jump

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,15 @@ if test $# -lt 1; then
8888
exit 1
8989
fi
9090
mode=$1; shift
91+
type "mode_$mode" >/dev/null 2>&1 || { usage >&2; exit 1; }
92+
9193
if test "$use_stdout" = "t"; then
9294
"mode_$mode" "$@"
9395
exit 0
9496
fi
9597

9698
trap 'rm -f "$tmp"' 0 1 2 3 15
9799
tmp=`mktemp -t git-jump.XXXXXX` || exit 1
98-
type "mode_$mode" >/dev/null 2>&1 || { usage >&2; exit 1; }
99100
"mode_$mode" "$@" >"$tmp"
100101
test -s "$tmp" || exit 0
101102
open_editor "$tmp"

0 commit comments

Comments
 (0)