t6424: make sure a failed merge preserves local changes

We do make sure that an attempt to merge with various forms of local changes will "fail", but the point of stopping the merge is so that we refrain from discarding uncommitted local changes that could be precious. Add a few more checks for each case to make sure the local changes are left intact. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed May 19, 2022 at 11:59 UTC 4b317450ce140c8c188afba79aed9a2e8e95d79e
1 file changed +30 -2
t/t6424-merge-unrelated-index-changes.sh
+30 -2
@@ -71,7 +71,9 @@ test_expect_success 'ff update' '
71 git merge E^0 &&
72
73 test_must_fail git rev-parse HEAD:random_file &&
74 - test "$(git diff --name-only --cached E)" = "random_file"
74 + test "$(git diff --name-only --cached E)" = "random_file" &&
75 + test_path_is_file random_file &&
76 + git rev-parse --verify :random_file
77 '
78
79 test_expect_success 'ff update, important file modified' '
@@ -83,6 +85,8 @@ test_expect_success 'ff update, important file modified' '
85 git add subdir/e &&
86
87 test_must_fail git merge E^0 &&
88 + test_path_is_file subdir/e &&
89 + git rev-parse --verify :subdir/e &&
90 test_path_is_missing .git/MERGE_HEAD
91 '
92
@@ -93,6 +97,8 @@ test_expect_success 'resolve, trivial' '
97 touch random_file && git add random_file &&
98
99 test_must_fail git merge -s resolve C^0 &&
100 + test_path_is_file random_file &&
101 + git rev-parse --verify :random_file &&
102 test_path_is_missing .git/MERGE_HEAD
103 '
104
@@ -103,6 +109,8 @@ test_expect_success 'resolve, non-trivial' '
109 touch random_file && git add random_file &&
110
111 test_must_fail git merge -s resolve D^0 &&
112 + test_path_is_file random_file &&
113 + git rev-parse --verify :random_file &&
114 test_path_is_missing .git/MERGE_HEAD
115 '
116
@@ -113,6 +121,8 @@ test_expect_success 'recursive' '
121 touch random_file && git add random_file &&
122
123 test_must_fail git merge -s recursive C^0 &&
124 + test_path_is_file random_file &&
125 + git rev-parse --verify :random_file &&
126 test_path_is_missing .git/MERGE_HEAD
127 '
128
@@ -145,9 +155,12 @@ test_expect_success 'recursive, when file has staged changes not matching HEAD n
155 mkdir subdir &&
156 test_seq 1 10 >subdir/a &&
157 git add subdir/a &&
158 + git rev-parse --verify :subdir/a >expect &&
159
160 # We have staged changes; merge should error out
161 test_must_fail git merge -s recursive E^0 2>err &&
162 + git rev-parse --verify :subdir/a >actual &&
163 + test_cmp expect actual &&
164 test_i18ngrep "changes to the following files would be overwritten" err
165 '
166
@@ -158,9 +171,12 @@ test_expect_success 'recursive, when file has staged changes matching what a mer
171 mkdir subdir &&
172 test_seq 1 11 >subdir/a &&
173 git add subdir/a &&
174 + git rev-parse --verify :subdir/a >expect &&
175
176 # We have staged changes; merge should error out
177 test_must_fail git merge -s recursive E^0 2>err &&
178 + git rev-parse --verify :subdir/a >actual &&
179 + test_cmp expect actual &&
180 test_i18ngrep "changes to the following files would be overwritten" err
181 '
182
@@ -171,7 +187,9 @@ test_expect_success 'octopus, unrelated file touched' '
187 touch random_file && git add random_file &&
188
189 test_must_fail git merge C^0 D^0 &&
174 - test_path_is_missing .git/MERGE_HEAD
190 + test_path_is_missing .git/MERGE_HEAD &&
191 + git rev-parse --verify :random_file &&
192 + test_path_exists random_file
193 '
194
195 test_expect_success 'octopus, related file removed' '
@@ -181,6 +199,8 @@ test_expect_success 'octopus, related file removed' '
199 git rm b &&
200
201 test_must_fail git merge C^0 D^0 &&
202 + test_path_is_missing b &&
203 + test_must_fail git rev-parse --verify :b &&
204 test_path_is_missing .git/MERGE_HEAD
205 '
206
@@ -189,8 +209,12 @@ test_expect_success 'octopus, related file modified' '
209 git checkout B^0 &&
210
211 echo 12 >>a && git add a &&
212 + git rev-parse --verify :a >expect &&
213
214 test_must_fail git merge C^0 D^0 &&
215 + test_path_is_file a &&
216 + git rev-parse --verify :a >actual &&
217 + test_cmp expect actual &&
218 test_path_is_missing .git/MERGE_HEAD
219 '
220
@@ -201,6 +225,8 @@ test_expect_success 'ours' '
225 touch random_file && git add random_file &&
226
227 test_must_fail git merge -s ours C^0 &&
228 + test_path_is_file random_file &&
229 + git rev-parse --verify :random_file &&
230 test_path_is_missing .git/MERGE_HEAD
231 '
232
@@ -211,6 +237,8 @@ test_expect_success 'subtree' '
237 touch random_file && git add random_file &&
238
239 test_must_fail git merge -s subtree E^0 &&
240 + test_path_is_file random_file &&
241 + git rev-parse --verify :random_file &&
242 test_path_is_missing .git/MERGE_HEAD
243 '
244