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 <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Matthieu Moy committed
Jun 29, 2015 at 17:40 UTC
fe67687bb1b38cbbdca4339caf14136b33e04783
1 file changed
+33
git-bisect.sh
+33
@@ -535,9 +535,42 @@ get_terms () {
535
write_terms () {
536
TERM_BAD=$1
537
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
544
printf '%s\n%s\n' "$TERM_BAD" "$TERM_GOOD" >"$GIT_DIR/BISECT_TERMS"
545
}
546
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
+
574
check_and_set_terms () {
575
cmd="$1"
576
case "$cmd" in