rerere: record resolution even if file is not in merge base
Two-file merges were rare enough that they were dropped outside of the radar. This fix is a trivial change to builtin-rerere.c::find_conflict(). It is still sane to insist that we do not do rerere for symlinks, and require to have stages #2 and #3, but we can drop the requirement to have stage #1. rerere does not use information from there anyway. This fix is from Junio, together with two tests to verify that it works as expected. Acked-by: Uwe Kleine-König <ukleinek@informatik.uni-freiburg.de> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Jul 9, 2007 at 14:47 UTC
52aaf649cb70134090c3e3a762bed730d5451c17
2 files changed
+46
-15
builtin-rerere.c
+7
-10
@@ -168,19 +168,16 @@ static int find_conflict(struct path_list *conflict)
168
int i;
169
if (read_cache() < 0)
170
return error("Could not read index");
171
- for (i = 0; i + 2 < active_nr; i++) {
172
- struct cache_entry *e1 = active_cache[i];
173
- struct cache_entry *e2 = active_cache[i+1];
174
- struct cache_entry *e3 = active_cache[i+2];
175
- if (ce_stage(e1) == 1 &&
176
- ce_stage(e2) == 2 &&
171
+ for (i = 0; i+1 < active_nr; i++) {
172
+ struct cache_entry *e2 = active_cache[i];
173
+ struct cache_entry *e3 = active_cache[i+1];
174
+ if (ce_stage(e2) == 2 &&
175
ce_stage(e3) == 3 &&
178
- ce_same_name(e1, e2) && ce_same_name(e1, e3) &&
179
- S_ISREG(ntohl(e1->ce_mode)) &&
176
+ ce_same_name(e2, e3) &&
177
S_ISREG(ntohl(e2->ce_mode)) &&
178
S_ISREG(ntohl(e3->ce_mode))) {
182
- path_list_insert((const char *)e1->name, conflict);
183
- i += 2;
179
+ path_list_insert((const char *)e2->name, conflict);
180
+ i++; /* skip over both #2 and #3 */
181
}
182
}
183
return 0;
t/t4200-rerere.sh
+39
-5
@@ -116,11 +116,12 @@ test_expect_success 'commit succeeds' \
116
117
test_expect_success 'recorded postimage' "test -f $rr/postimage"
118
119
-git checkout -b third master
120
-git show second^:a1 | sed 's/To die: t/To die! T/' > a1
121
-git commit -q -a -m third
122
-
123
-test_expect_failure 'another conflicting merge' 'git pull . first'
119
+test_expect_success 'another conflicting merge' '
120
+ git checkout -b third master &&
121
+ git show second^:a1 | sed "s/To die: t/To die! T/" > a1 &&
122
+ git commit -q -a -m third &&
123
+ ! git pull . first
124
+'
125
126
git show first:a1 | sed 's/To die: t/To die! T/' > expect
127
test_expect_success 'rerere kicked in' "! grep ======= a1"
@@ -164,4 +165,37 @@ test_expect_success 'garbage collection (part2)' 'git rerere gc'
165
test_expect_success 'old records rest in peace' \
166
"test ! -f $rr/preimage && test ! -f $rr2/preimage"
167
168
+test_expect_success 'file2 added differently in two branches' '
169
+ git reset --hard &&
170
+ git checkout -b fourth &&
171
+ echo Hallo > file2 &&
172
+ git add file2 &&
173
+ git commit -m version1 &&
174
+ git checkout third &&
175
+ echo Bello > file2 &&
176
+ git add file2 &&
177
+ git commit -m version2 &&
178
+ ! git merge fourth &&
179
+ sha1=$(sed -e "s/ .*//" .git/rr-cache/MERGE_RR) &&
180
+ rr=.git/rr-cache/$sha1 &&
181
+ echo Cello > file2 &&
182
+ git add file2 &&
183
+ git commit -m resolution
184
+'
185
+
186
+test_expect_success 'resolution was recorded properly' '
187
+ git reset --hard HEAD~2 &&
188
+ git checkout -b fifth &&
189
+ echo Hallo > file3 &&
190
+ git add file3 &&
191
+ git commit -m version1 &&
192
+ git checkout third &&
193
+ echo Bello > file3 &&
194
+ git add file3 &&
195
+ git commit -m version2 &&
196
+ ! git merge fifth &&
197
+ git diff-files -q &&
198
+ test Cello = "$(cat file3)"
199
+'
200
+
201
test_done