git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 2/2] bisect: warn if given dubious tag or branch as rev
@ 2008-04-14  3:41 Christian Couder
  2008-04-14 23:33 ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Christian Couder @ 2008-04-14  3:41 UTC (permalink / raw)
  To: Junio Hamano, Ingo Molnar; +Cc: git

This patch refactors rev parsing code in a new "bisect_parse_rev"
function, and adds warnings in case a rev with a name that is the
same as one of the bisect subcommands is given where a revision
is expected.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 git-bisect.sh               |   47 ++++++++++++++++++++++++++++++------------
 t/t6030-bisect-porcelain.sh |   21 +++++++++++++++++++
 2 files changed, 54 insertions(+), 14 deletions(-)

diff --git a/git-bisect.sh b/git-bisect.sh
index 6b43461..a090b97 100755
--- a/git-bisect.sh
+++ b/git-bisect.sh
@@ -61,6 +61,31 @@ bisect_autostart() {
 	}
 }
 
+bisect_parse_rev() {
+	rev="$1"
+	dont_die_on_wrong_rev="$2"
+	name="$rev^{commit}"
+	dubious_rev_name=''
+
+	case "$rev" in
+		HEAD)
+			name='HEAD' ;;
+		help|start|bad|good|skip|next|reset|visualize|replay|log|run)
+			dubious_rev_name='yes' ;;
+	esac
+
+	sha=$(git rev-parse --verify "$name" 2>/dev/null)
+	status=$?
+
+	test $status -eq 0 && test -n "$dubious_rev_name" &&
+		echo >&2 "A tag or branch named '$rev' exists and will be used." \
+			"This may be a syntax error, please check."
+
+	test -n "$dont_die_on_wrong_rev" && return $status
+
+	test $status -eq 0 || die "Bad rev input: $rev"
+}
+
 bisect_start() {
 	#
 	# Verify HEAD. If we were bisecting before this, reset to the
@@ -68,7 +93,7 @@ bisect_start() {
 	#
 	head=$(GIT_DIR="$GIT_DIR" git symbolic-ref HEAD) ||
 	head=$(GIT_DIR="$GIT_DIR" git rev-parse --verify HEAD) ||
-	die "Bad HEAD - I need a HEAD"
+		die "Bad HEAD - I need a HEAD"
 	start_head=''
 	case "$head" in
 	refs/heads/bisect)
@@ -98,9 +123,9 @@ bisect_start() {
 	#
 	# Check for one bad and then some good revisions.
 	#
-	has_double_dash=0
+	dont_die_on_wrong_rev='yes'
 	for arg; do
-	    case "$arg" in --) has_double_dash=1; break ;; esac
+	    case "$arg" in --) dont_die_on_wrong_rev=''; break ;; esac
 	done
 	orig_args=$(sq "$@")
 	bad_seen=0
@@ -113,16 +138,12 @@ bisect_start() {
 		break
 		;;
 	    *)
-		rev=$(git rev-parse --verify "$arg^{commit}" 2>/dev/null) || {
-		    test $has_double_dash -eq 1 &&
-		        die "'$arg' does not appear to be a valid revision"
-		    break
-		}
+		bisect_parse_rev "$arg" "$dont_die_on_wrong_rev" || break
 		case $bad_seen in
 		0) state='bad' ; bad_seen=1 ;;
 		*) state='good' ;;
 		esac
-		eval="$eval bisect_write '$state' '$rev' 'nolog'; "
+		eval="$eval bisect_write '$state' '$sha' 'nolog'; "
 		shift
 		;;
 	    esac
@@ -156,16 +177,14 @@ bisect_state() {
 	0,*)
 		die "Please call 'bisect_state' with at least one argument." ;;
 	1,bad|1,good|1,skip)
-		rev=$(git rev-parse --verify HEAD) ||
-			die "Bad rev input: HEAD"
-		bisect_write "$state" "$rev" ;;
+		bisect_parse_rev HEAD
+		bisect_write "$state" "$sha" ;;
 	2,bad|*,good|*,skip)
 		shift
 		eval=''
 		for rev in "$@"
 		do
-			sha=$(git rev-parse --verify "$rev^{commit}") ||
-				die "Bad rev input: $rev"
+			bisect_parse_rev "$rev"
 			eval="$eval bisect_write '$state' '$sha'; "
 		done
 		eval "$eval" ;;
diff --git a/t/t6030-bisect-porcelain.sh b/t/t6030-bisect-porcelain.sh
index 5e3e544..dc95117 100755
--- a/t/t6030-bisect-porcelain.sh
+++ b/t/t6030-bisect-porcelain.sh
@@ -89,6 +89,27 @@ test_expect_success 'bisect fails if given any junk instead of revs' '
 	git bisect bad $HASH4
 '
 
+test_expect_success 'bisect warns if given dubious tags or branches' '
+	git branch bad $HASH4 &&
+	git bisect start bad -- 2>start.output &&
+	grep "bad" start.output &&
+	grep "may be a syntax error" start.output &&
+	git tag good $HASH1 &&
+	git bisect start $HASH4 $HASH2 good -- 2>start.output &&
+	grep "good" start.output &&
+	grep "may be a syntax error" start.output &&
+	git bisect start &&
+	git bisect good $HASH2 bad 2>good.output &&
+	grep "bad" good.output &&
+	grep "may be a syntax error" good.output &&
+	git bisect start &&
+	git bisect bad bad 2>bad.output &&
+	grep "bad" bad.output &&
+	grep "may be a syntax error" bad.output &&
+	git branch -D bad &&
+	git tag -d good
+'
+
 test_expect_success 'bisect reset: back in the master branch' '
 	git bisect reset &&
 	echo "* master" > branch.expect &&
-- 
1.5.5.50.ge6e82.dirty

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-04-15  7:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-14  3:41 [PATCH 2/2] bisect: warn if given dubious tag or branch as rev Christian Couder
2008-04-14 23:33 ` Junio C Hamano
2008-04-15  7:05   ` Christian Couder

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).