Skip to content

Commit fe67687

Browse files
moygitster
authored andcommitted
bisect: sanity check on terms
This is currently only a defensive check since the only terms are bad/good and new/old, which pass it, but this is a preparation step for accepting user-supplied terms. Signed-off-by: Matthieu Moy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4a6ada3 commit fe67687

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

git-bisect.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,9 +535,42 @@ get_terms () {
535535
write_terms () {
536536
TERM_BAD=$1
537537
TERM_GOOD=$2
538+
if test "$TERM_BAD" = "$TERM_GOOD"
539+
then
540+
die "$(gettext "please use two different terms")"
541+
fi
542+
check_term_format "$TERM_BAD" bad
543+
check_term_format "$TERM_GOOD" good
538544
printf '%s\n%s\n' "$TERM_BAD" "$TERM_GOOD" >"$GIT_DIR/BISECT_TERMS"
539545
}
540546

547+
check_term_format () {
548+
term=$1
549+
git check-ref-format refs/bisect/"$term" ||
550+
die "$(eval_gettext "'\$term' is not a valid term")"
551+
case "$term" in
552+
help|start|terms|skip|next|reset|visualize|replay|log|run)
553+
die "$(eval_gettext "can't use the builtin command '\$term' as a term")"
554+
;;
555+
bad|new)
556+
if test "$2" != bad
557+
then
558+
# In theory, nothing prevents swapping
559+
# completely good and bad, but this situation
560+
# could be confusing and hasn't been tested
561+
# enough. Forbid it for now.
562+
die "$(eval_gettext "can't change the meaning of term '\$term'")"
563+
fi
564+
;;
565+
good|old)
566+
if test "$2" != good
567+
then
568+
die "$(eval_gettext "can't change the meaning of term '\$term'")"
569+
fi
570+
;;
571+
esac
572+
}
573+
541574
check_and_set_terms () {
542575
cmd="$1"
543576
case "$cmd" in

0 commit comments

Comments
 (0)