git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] git-checkout -m: fix merge case

From
Junio C Hamano <junkio@cox.net>
Date
Jan 24, 2007, 01:42 UTC
Message-ID
<7vtzyhkxow.fsf@assigned-by-dhcp.cox.net>

Commit c1a4278e switched the "merging checkout" implementation from 3-way read-tree to merge-recursive, but forgot that merge-recursive will signal an unmerged state with its own exit status code. This prevented the clean-up phase (paths cleanly merged should not be updated in the index) from running.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 git-checkout.sh |   15 +++++----------
 t/t7201-co.sh   |   28 +++++++++++++++++++++++++++-
 2 files changed, 32 insertions(+), 11 deletions(-)
diff --git a/git-checkout.sh b/git-checkout.sh
index e02d4d8..c52f352 100755
--- a/git-checkout.sh
+++ b/git-checkout.sh
@@ -200,17 +200,12 @@ else
 	# Match the index to the working tree, and do a three-way.
     	git diff-files --name-only | git update-index --remove --stdin &&
 	work=`git write-tree` &&
-	git read-tree --reset -u $new &&
-	eval GITHEAD_$new=${new_name:-${branch:-$new}} GITHEAD_$work=local &&
-	export GITHEAD_$new GITHEAD_$work &&
-	git merge-recursive $old -- $new $work || exit
+	git read-tree --reset -u $new || exit
 
-	if result=`git write-tree 2>/dev/null`
-	then
-	    echo >&2 "Trivially automerged."
-	else
-	    git merge-index -o git-merge-one-file -a
-	fi
+	eval GITHEAD_$new=${new_name:-${branch:-$new}} &&
+	eval GITHEAD_$work=local &&
+	export GITHEAD_$new GITHEAD_$work &&
+	git merge-recursive $old -- $new $work
 
 	# Do not register the cleanly merged paths in the index yet.
 	# this is not a real merge before committing, but just carrying
diff --git a/t/t7201-co.sh b/t/t7201-co.sh
index 315fa35..867bbd2 100755
--- a/t/t7201-co.sh
+++ b/t/t7201-co.sh
@@ -100,7 +100,33 @@ test_expect_success "checkout -m with dirty tree, renamed" '
 	git checkout -m renamer &&
 	fill 1 3 4 5 7 8 >expect &&
 	diff expect uno &&
-	! test -f one
+	! test -f one &&
+	git diff --cached >current &&
+	! test -s current
+
+'
+
+test_expect_success 'checkout -m with merge conflict' '
+
+	git checkout -f master && git clean &&
+
+	fill 1 T 3 4 5 6 S 8 >one &&
+	if git checkout renamer
+	then
+		echo Not happy
+		false
+	else
+		echo "happy - failed correctly"
+	fi &&
+
+	git checkout -m renamer &&
+
+	git diff master:one :3:uno |
+	sed -e "1,/^@@/d" -e "/^ /d" -e "s/^-/d/" -e "s/^+/a/" >current &&
+	fill d2 aT d7 aS >expect &&
+	diff current expect &&
+	git diff --cached two >current &&
+	! test -s current
 '
 
 test_done
-- 
1.5.0.rc2.gd7eb
Message 1 of 1 in “git-checkout -m: fix merge case”
  1. git-checkout -m: fix merge caseJunio C Hamano, Jan 24, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.