@@ -1439,4 +1439,90 @@ test_expect_success 'rename/rename(1to2) with a binary file' '
14391439 )
14401440'
14411441
1442+ # Testcase preliminary submodule/directory conflict and submodule rename
1443+ # Commit O: <empty, or additional irrelevant stuff>
1444+ # Commit A1: introduce "folder" (as a tree)
1445+ # Commit B1: introduce "folder" (as a submodule)
1446+ # Commit A2: merge B1 into A1, but keep folder as a tree
1447+ # Commit B2: merge A1 into B1, but keep folder as a submodule
1448+ # Merge A2 & B2
1449+ test_setup_submodule_directory_preliminary_conflict () {
1450+ git init submodule_directory_preliminary_conflict &&
1451+ (
1452+ cd submodule_directory_preliminary_conflict &&
1453+
1454+ # Trying to do the A2 and B2 merges above is slightly more
1455+ # challenging with a local submodule (because checking out
1456+ # another commit has the submodule in the way). Instead,
1457+ # first create the commits with the wrong parents but right
1458+ # trees, in the order A1, A2, B1, B2...
1459+ #
1460+ # Then go back and create new A2 & B2 with the correct
1461+ # parents and the same trees.
1462+
1463+ git commit --allow-empty -m orig &&
1464+
1465+ git branch A &&
1466+ git branch B &&
1467+
1468+ git checkout B &&
1469+ mkdir folder &&
1470+ echo A> folder/A &&
1471+ echo B> folder/B &&
1472+ echo C> folder/C &&
1473+ echo D> folder/D &&
1474+ echo E> folder/E &&
1475+ git add folder &&
1476+ git commit -m B1 &&
1477+
1478+ git commit --allow-empty -m B2 &&
1479+
1480+ git checkout A &&
1481+ git init folder &&
1482+ (
1483+ cd folder &&
1484+ > Z &&
1485+ > Y &&
1486+ git add Z Y &&
1487+ git commit -m " original submodule commit"
1488+ ) &&
1489+ git add folder &&
1490+ git commit -m A1 &&
1491+
1492+ git commit --allow-empty -m A2 &&
1493+
1494+ NewA2=$( git commit-tree -p A^ -p B^ -m " Merge B into A" A^{tree}) &&
1495+ NewB2=$( git commit-tree -p B^ -p A^ -m " Merge A into B" B^{tree}) &&
1496+ git update-ref refs/heads/A $NewA2 &&
1497+ git update-ref refs/heads/B $NewB2
1498+ )
1499+ }
1500+
1501+ test_expect_success ' submodule/directory preliminary conflict' '
1502+ test_setup_submodule_directory_preliminary_conflict &&
1503+ (
1504+ cd submodule_directory_preliminary_conflict &&
1505+
1506+ git checkout A^0 &&
1507+
1508+ test_expect_code 1 git merge B^0 &&
1509+
1510+ # Make sure the index has the right number of entries
1511+ git ls-files -s >actual &&
1512+ test_line_count = 2 actual &&
1513+
1514+ # The "folder" as directory should have been resolved away
1515+ # as part of the merge. The "folder" as submodule got
1516+ # renamed to "folder~Temporary merge branch 2" in the
1517+ # virtual merge base, resulting in a
1518+ # "folder~Temporary merge branch 2" -> "folder"
1519+ # rename in the outermerge for the submodule, which then
1520+ # becomes part of a rename/delete conflict (because "folder"
1521+ # as a submodule was deleted in A2).
1522+ submod=$(git rev-parse A:folder) &&
1523+ printf "160000 $submod 1\tfolder\n160000 $submod 2\tfolder\n" >expect &&
1524+ test_cmp expect actual
1525+ )
1526+ '
1527+
14421528test_done
0 commit comments