git-checkout -m: fix merge case
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>
Junio C Hamano committed
Jan 23, 2007 at 16:51 UTC
d7ebd53d371153f7a61c0fe9f384c9662b751bf6
2 files changed
+32
-11
git-checkout.sh
+5
-10
@@ -200,17 +200,12 @@ else
200
# Match the index to the working tree, and do a three-way.
201
git diff-files --name-only | git update-index --remove --stdin &&
202
work=`git write-tree` &&
203
- git read-tree --reset -u $new &&
204
- eval GITHEAD_$new=${new_name:-${branch:-$new}} GITHEAD_$work=local &&
205
- export GITHEAD_$new GITHEAD_$work &&
206
- git merge-recursive $old -- $new $work || exit
203
+ git read-tree --reset -u $new || exit
204
208
- if result=`git write-tree 2>/dev/null`
209
- then
210
- echo >&2 "Trivially automerged."
211
- else
212
- git merge-index -o git-merge-one-file -a
213
- fi
205
+ eval GITHEAD_$new=${new_name:-${branch:-$new}} &&
206
+ eval GITHEAD_$work=local &&
207
+ export GITHEAD_$new GITHEAD_$work &&
208
+ git merge-recursive $old -- $new $work
209
210
# Do not register the cleanly merged paths in the index yet.
211
# this is not a real merge before committing, but just carrying
t/t7201-co.sh
+27
-1
@@ -100,7 +100,33 @@ test_expect_success "checkout -m with dirty tree, renamed" '
100
git checkout -m renamer &&
101
fill 1 3 4 5 7 8 >expect &&
102
diff expect uno &&
103
- ! test -f one
103
+ ! test -f one &&
104
+ git diff --cached >current &&
105
+ ! test -s current
106
+
107
+'
108
+
109
+test_expect_success 'checkout -m with merge conflict' '
110
+
111
+ git checkout -f master && git clean &&
112
+
113
+ fill 1 T 3 4 5 6 S 8 >one &&
114
+ if git checkout renamer
115
+ then
116
+ echo Not happy
117
+ false
118
+ else
119
+ echo "happy - failed correctly"
120
+ fi &&
121
+
122
+ git checkout -m renamer &&
123
+
124
+ git diff master:one :3:uno |
125
+ sed -e "1,/^@@/d" -e "/^ /d" -e "s/^-/d/" -e "s/^+/a/" >current &&
126
+ fill d2 aT d7 aS >expect &&
127
+ diff current expect &&
128
+ git diff --cached two >current &&
129
+ ! test -s current
130
'
131
132
test_done