merge-recursive: conflicting rename case.
This changes the way the case two branches rename the same path to different paths is handled. Earlier, the code removed the original path and added both destinations to the index at stage0. This commit changes it to leave the original path at stage1, and two destination paths at stage2 and stage3, respectively. [jc: I am not really sure if this makes much difference in the real life merge situations. What should happen when our branch renames A to B and M to N, while their branch renames A to M? That is, M remains in our tree as is.] Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Dec 11, 2005 at 16:44 UTC
724b511d4fb363ebee828ba3992c831ba006444c
2 files changed
+64
-11
git-merge-recursive.py
+27
-11
@@ -283,12 +283,20 @@ def updateFileExt(sha, mode, path, updateCache, updateWd):
283
def setIndexStages(path,
284
oSHA1, oMode,
285
aSHA1, aMode,
286
- bSHA1, bMode):
286
+ bSHA1, bMode,
287
+ clear=True):
288
+ istring = []
289
+ if clear:
290
+ istring.append("0 " + ("0" * 40) + "\t" + path + "\0")
291
+ if oMode:
292
+ istring.append("%o %s %d\t%s\0" % (oMode, oSHA1, 1, path))
293
+ if aMode:
294
+ istring.append("%o %s %d\t%s\0" % (aMode, aSHA1, 2, path))
295
+ if bMode:
296
+ istring.append("%o %s %d\t%s\0" % (bMode, bSHA1, 3, path))
297
+
298
runProgram(['git-update-index', '-z', '--index-info'],
288
- input="0 " + ("0" * 40) + "\t" + path + "\0" + \
289
- "%o %s %d\t%s\0" % (oMode, oSHA1, 1, path) + \
290
- "%o %s %d\t%s\0" % (aMode, aSHA1, 2, path) + \
291
- "%o %s %d\t%s\0" % (bMode, bSHA1, 3, path))
299
+ input="".join(istring))
300
301
def removeFile(clean, path):
302
updateCache = cacheOnly or clean
@@ -570,7 +578,7 @@ def processRenames(renamesA, renamesB, branchNameA, branchNameB):
578
continue
579
580
ren1.processed = True
573
- removeFile(True, ren1.srcName)
581
+
582
if ren2:
583
# Renamed in 1 and renamed in 2
584
assert(ren1.srcName == ren2.srcName)
@@ -598,13 +606,19 @@ def processRenames(renamesA, renamesB, branchNameA, branchNameB):
606
'adding as', dstName2, 'instead.')
607
removeFile(False, ren2.dstName)
608
else:
601
- dstName2 = ren1.dstName
609
+ dstName2 = ren2.dstName
610
+ setIndexStages(dstName1,
611
+ None, None,
612
+ ren1.dstSha, ren1.dstMode,
613
+ None, None)
614
+ setIndexStages(dstName2,
615
+ None, None,
616
+ None, None,
617
+ ren2.dstSha, ren2.dstMode)
618
603
- # NEEDSWORK: place dstNameA at stage 2 and dstNameB at stage 3
604
- # What about other stages???
605
- updateFile(False, ren1.dstSha, ren1.dstMode, dstName1)
606
- updateFile(False, ren2.dstSha, ren2.dstMode, dstName2)
619
else:
620
+ removeFile(True, ren1.srcName)
621
+
622
[resSha, resMode, clean, merge] = \
623
mergeFile(ren1.srcName, ren1.srcSha, ren1.srcMode,
624
ren1.dstName, ren1.dstSha, ren1.dstMode,
@@ -630,6 +644,8 @@ def processRenames(renamesA, renamesB, branchNameA, branchNameB):
644
645
updateFile(clean, resSha, resMode, ren1.dstName)
646
else:
647
+ removeFile(True, ren1.srcName)
648
+
649
# Renamed in 1, maybe changed in 2
650
if renamesA == renames1:
651
stage = 3
t/t6022-merge-rename.sh
+37
@@ -161,4 +161,41 @@ test_expect_success 'pull unrenaming branch into renaming one' \
161
}
162
'
163
164
+test_expect_success 'pull conflicting renames' \
165
+'
166
+ git reset --hard
167
+ git show-branch
168
+ git pull . blue && {
169
+ echo "BAD: should have conflicted"
170
+ exit 1
171
+ }
172
+ test "$(git ls-files -u A | wc -l)" -eq 1 || {
173
+ echo "BAD: should have left a stage"
174
+ exit 1
175
+ }
176
+ test "$(git ls-files -u B | wc -l)" -eq 1 || {
177
+ echo "BAD: should have left a stage"
178
+ exit 1
179
+ }
180
+ test "$(git ls-files -u C | wc -l)" -eq 1 || {
181
+ echo "BAD: should have left a stage"
182
+ exit 1
183
+ }
184
+ test "$(git ls-files -s N | wc -l)" -eq 1 || {
185
+ echo "BAD: should have merged N"
186
+ exit 1
187
+ }
188
+ sed -ne "/^g/{
189
+ p
190
+ q
191
+ }" B | grep red || {
192
+ echo "BAD: should have listed our change first"
193
+ exit 1
194
+ }
195
+ test "$(git diff white N | wc -l)" -eq 0 || {
196
+ echo "BAD: should have taken colored branch"
197
+ exit 1
198
+ }
199
+'
200
+
201
test_done