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 <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Jun 30, 2018 at 18:25 UTC 7f5271fa1584d99fb3c83f308f35295ed78c8b8b
1 file changed +29
t/t6044-merge-unrelated-index-changes.sh
+29
@@ -137,6 +137,35 @@ test_expect_success 'merge-recursive, when index==head but head!=HEAD' '
137 test_i18ngrep "Already up to date" out
138 '
139
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 +
169 test_expect_success 'octopus, unrelated file touched' '
170 git reset --hard &&
171 git checkout B^0 &&