File tree Expand file tree Collapse file tree 2 files changed +66
-0
lines changed Expand file tree Collapse file tree 2 files changed +66
-0
lines changed Original file line number Diff line number Diff line change @@ -3468,6 +3468,21 @@ static int load_preimage(struct apply_state *state,
3468
3468
return 0 ;
3469
3469
}
3470
3470
3471
+ static int resolve_to (struct image * image , const struct object_id * result_id )
3472
+ {
3473
+ unsigned long size ;
3474
+ enum object_type type ;
3475
+
3476
+ clear_image (image );
3477
+
3478
+ image -> buf = read_object_file (result_id , & type , & size );
3479
+ if (!image -> buf || type != OBJ_BLOB )
3480
+ die ("unable to read blob object %s" , oid_to_hex (result_id ));
3481
+ image -> len = size ;
3482
+
3483
+ return 0 ;
3484
+ }
3485
+
3471
3486
static int three_way_merge (struct apply_state * state ,
3472
3487
struct image * image ,
3473
3488
char * path ,
@@ -3479,6 +3494,12 @@ static int three_way_merge(struct apply_state *state,
3479
3494
mmbuffer_t result = { NULL };
3480
3495
int status ;
3481
3496
3497
+ /* resolve trivial cases first */
3498
+ if (oideq (base , ours ))
3499
+ return resolve_to (image , theirs );
3500
+ else if (oideq (base , theirs ) || oideq (ours , theirs ))
3501
+ return resolve_to (image , ours );
3502
+
3482
3503
read_mmblob (& base_file , base );
3483
3504
read_mmblob (& our_file , ours );
3484
3505
read_mmblob (& their_file , theirs );
Original file line number Diff line number Diff line change @@ -230,4 +230,49 @@ test_expect_success 'apply with --3way --cached and conflicts' '
230
230
test_cmp expect.diff actual.diff
231
231
'
232
232
233
+ test_expect_success ' apply binary file patch' '
234
+ git reset --hard main &&
235
+ cp "$TEST_DIRECTORY/test-binary-1.png" bin.png &&
236
+ git add bin.png &&
237
+ git commit -m "add binary file" &&
238
+
239
+ cp "$TEST_DIRECTORY/test-binary-2.png" bin.png &&
240
+
241
+ git diff --binary >bin.diff &&
242
+ git reset --hard &&
243
+
244
+ # Apply must succeed.
245
+ git apply bin.diff
246
+ '
247
+
248
+ test_expect_success ' apply binary file patch with 3way' '
249
+ git reset --hard main &&
250
+ cp "$TEST_DIRECTORY/test-binary-1.png" bin.png &&
251
+ git add bin.png &&
252
+ git commit -m "add binary file" &&
253
+
254
+ cp "$TEST_DIRECTORY/test-binary-2.png" bin.png &&
255
+
256
+ git diff --binary >bin.diff &&
257
+ git reset --hard &&
258
+
259
+ # Apply must succeed.
260
+ git apply --3way --index bin.diff
261
+ '
262
+
263
+ test_expect_success ' apply full-index patch with 3way' '
264
+ git reset --hard main &&
265
+ cp "$TEST_DIRECTORY/test-binary-1.png" bin.png &&
266
+ git add bin.png &&
267
+ git commit -m "add binary file" &&
268
+
269
+ cp "$TEST_DIRECTORY/test-binary-2.png" bin.png &&
270
+
271
+ git diff --full-index >bin.diff &&
272
+ git reset --hard &&
273
+
274
+ # Apply must succeed.
275
+ git apply --3way --index bin.diff
276
+ '
277
+
233
278
test_done
You can’t perform that action at this time.
0 commit comments