Skip to content

Commit eab3f28

Browse files
newrengitster
authored andcommitted
t6044: recursive can silently incorporate dirty changes in a merge
The recursive merge strategy has some special handling when the tree for the merge branch exactly matches the merge base, but that code path is missing checks for the index having changes relative to HEAD. Add a testcase covering this scenario. Reported-by: Andreas Krey <[email protected]> Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3013dff commit eab3f28

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

t/t6044-merge-unrelated-index-changes.sh

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,21 @@ test_description="merges with unrelated index changes"
66

77
# Testcase for some simple merges
88
# A
9-
# o-----o B
9+
# o-------o B
1010
# \
11-
# \---o C
11+
# \-----o C
1212
# \
13-
# \-o D
13+
# \---o D
1414
# \
15-
# o E
15+
# \-o E
16+
# \
17+
# o F
1618
# Commit A: some file a
1719
# Commit B: adds file b, modifies end of a
1820
# Commit C: adds file c
1921
# Commit D: adds file d, modifies beginning of a
2022
# Commit E: renames a->subdir/a, adds subdir/e
23+
# Commit F: empty commit
2124

2225
test_expect_success 'setup trivial merges' '
2326
test_seq 1 10 >a &&
@@ -29,6 +32,7 @@ test_expect_success 'setup trivial merges' '
2932
git branch C &&
3033
git branch D &&
3134
git branch E &&
35+
git branch F &&
3236
3337
git checkout B &&
3438
echo b >b &&
@@ -52,7 +56,10 @@ test_expect_success 'setup trivial merges' '
5256
git mv a subdir/a &&
5357
echo e >subdir/e &&
5458
git add subdir &&
55-
test_tick && git commit -m E
59+
test_tick && git commit -m E &&
60+
61+
git checkout F &&
62+
test_tick && git commit --allow-empty -m F
5663
'
5764

5865
test_expect_success 'ff update' '
@@ -105,6 +112,15 @@ test_expect_success 'recursive' '
105112
test_must_fail git merge -s recursive C^0
106113
'
107114

115+
test_expect_failure 'recursive, when merge branch matches merge base' '
116+
git reset --hard &&
117+
git checkout B^0 &&
118+
119+
touch random_file && git add random_file &&
120+
121+
test_must_fail git merge -s recursive F^0
122+
'
123+
108124
test_expect_success 'octopus, unrelated file touched' '
109125
git reset --hard &&
110126
git checkout B^0 &&

0 commit comments

Comments
 (0)