Skip to content

Commit 7f5271f

Browse files
newrengitster
authored andcommitted
t6044: add more testcases with staged changes before a merge is invoked
According to Documentation/git-merge.txt, ...[merge will] abort if there are any changes registered in the index relative to the `HEAD` commit. (One exception is when the changed index entries are in the state that would result from the merge already.) Add some tests showing that this exception, while it does accurately state what would be a safe condition under which we could allow the merge to proceed, is not what is actually implemented. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e1f8694 commit 7f5271f

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,35 @@ test_expect_success 'merge-recursive, when index==head but head!=HEAD' '
137137
test_i18ngrep "Already up to date" out
138138
'
139139

140+
test_expect_failure 'recursive, when file has staged changes not matching HEAD nor what a merge would give' '
141+
git reset --hard &&
142+
git checkout B^0 &&
143+
144+
mkdir subdir &&
145+
test_seq 1 10 >subdir/a &&
146+
git add subdir/a &&
147+
148+
# HEAD has no subdir/a; merge would write 1..11 to subdir/a;
149+
# Since subdir/a matches neither HEAD nor what the merge would write
150+
# to that file, the merge should fail to avoid overwriting what is
151+
# currently found in subdir/a
152+
test_must_fail git merge -s recursive E^0
153+
'
154+
155+
test_expect_failure 'recursive, when file has staged changes matching what a merge would give' '
156+
git reset --hard &&
157+
git checkout B^0 &&
158+
159+
mkdir subdir &&
160+
test_seq 1 11 >subdir/a &&
161+
git add subdir/a &&
162+
163+
# HEAD has no subdir/a; merge would write 1..11 to subdir/a;
164+
# Since subdir/a matches what the merge would write to that file,
165+
# the merge should be safe to proceed
166+
git merge -s recursive E^0
167+
'
168+
140169
test_expect_success 'octopus, unrelated file touched' '
141170
git reset --hard &&
142171
git checkout B^0 &&

0 commit comments

Comments
 (0)