@@ -13,6 +13,46 @@ setup_srcdst_basic () {
13
13
)
14
14
}
15
15
16
+ # For tests with "--force-if-includes".
17
+ setup_src_dup_dst () {
18
+ rm -fr src dup dst &&
19
+ git init --bare dst &&
20
+ git clone --no-local dst src &&
21
+ git clone --no-local dst dup
22
+ (
23
+ cd src &&
24
+ test_commit A &&
25
+ test_commit B &&
26
+ test_commit C &&
27
+ git push
28
+ ) &&
29
+ (
30
+ cd dup &&
31
+ git fetch &&
32
+ git merge origin/master &&
33
+ git switch -c branch master~2 &&
34
+ test_commit D &&
35
+ test_commit E &&
36
+ git push --all
37
+ ) &&
38
+ (
39
+ cd src &&
40
+ git switch master &&
41
+ git fetch --all &&
42
+ git branch branch --track origin/branch &&
43
+ git rebase origin/master
44
+ ) &&
45
+ (
46
+ cd dup &&
47
+ git switch master &&
48
+ test_commit F &&
49
+ test_commit G &&
50
+ git switch branch &&
51
+ test_commit H &&
52
+ git push origin --all
53
+ )
54
+ }
55
+
16
56
test_expect_success setup '
17
57
# create template repository
18
58
test_commit A &&
@@ -256,4 +296,104 @@ test_expect_success 'background updates of REMOTE can be mitigated with a non-up
256
296
)
257
297
'
258
298
299
+ test_expect_success ' background updates to remote can be mitigated with "--force-if-includes"' '
300
+ setup_src_dup_dst &&
301
+ test_when_finished "rm -fr dst src dup" &&
302
+ git ls-remote dst refs/heads/master >expect.master &&
303
+ git ls-remote dst refs/heads/master >expect.branch &&
304
+ (
305
+ cd src &&
306
+ git switch branch &&
307
+ test_commit I &&
308
+ git switch master &&
309
+ test_commit J &&
310
+ git fetch --all &&
311
+ test_must_fail git push --force-with-lease --force-if-includes --all
312
+ ) &&
313
+ git ls-remote dst refs/heads/master >actual.master &&
314
+ git ls-remote dst refs/heads/master >actual.branch &&
315
+ test_cmp expect.master actual.master &&
316
+ test_cmp expect.branch actual.branch
317
+ '
318
+
319
+ test_expect_success ' background updates to remote can be mitigated with "push.useForceIfIncludes"' '
320
+ setup_src_dup_dst &&
321
+ test_when_finished "rm -fr dst src dup" &&
322
+ git ls-remote dst refs/heads/master >expect.master &&
323
+ (
324
+ cd src &&
325
+ git switch branch &&
326
+ test_commit I &&
327
+ git switch master &&
328
+ test_commit J &&
329
+ git fetch --all &&
330
+ git config --local push.useForceIfIncludes true &&
331
+ test_must_fail git push --force-with-lease=master origin master
332
+ ) &&
333
+ git ls-remote dst refs/heads/master >actual.master &&
334
+ test_cmp expect.master actual.master
335
+ '
336
+
337
+ test_expect_success ' "--force-if-includes" should be disabled for --force-with-lease="<refname>:<expect>"' '
338
+ setup_src_dup_dst &&
339
+ test_when_finished "rm -fr dst src dup" &&
340
+ git ls-remote dst refs/heads/master >expect.master &&
341
+ git ls-remote dst refs/heads/master >expect.branch &&
342
+ (
343
+ cd src &&
344
+ git switch branch &&
345
+ test_commit I &&
346
+ git switch master &&
347
+ test_commit J &&
348
+ remote_head="$(git rev-parse refs/remotes/origin/master)" &&
349
+ git fetch --all &&
350
+ test_must_fail git push --force-if-includes --force-with-lease="master:$remote_head" 2>err &&
351
+ grep "stale info" err
352
+ ) &&
353
+ git ls-remote dst refs/heads/master >actual.master &&
354
+ git ls-remote dst refs/heads/master >actual.branch &&
355
+ test_cmp expect.master actual.master &&
356
+ test_cmp expect.branch actual.branch
357
+ '
358
+
359
+ test_expect_success ' "--force-if-includes" should allow forced update after a rebase ("pull --rebase")' '
360
+ setup_src_dup_dst &&
361
+ test_when_finished "rm -fr dst src dup" &&
362
+ (
363
+ cd src &&
364
+ git switch branch &&
365
+ test_commit I &&
366
+ git switch master &&
367
+ test_commit J &&
368
+ git pull --rebase origin master &&
369
+ git push --force-if-includes --force-with-lease="master"
370
+ )
371
+ '
372
+
373
+ test_expect_success ' "--force-if-includes" should allow forced update after a rebase ("pull --rebase", local rebase)' '
374
+ setup_src_dup_dst &&
375
+ test_when_finished "rm -fr dst src dup" &&
376
+ (
377
+ cd src &&
378
+ git switch branch &&
379
+ test_commit I &&
380
+ git switch master &&
381
+ test_commit J &&
382
+ git pull --rebase origin master &&
383
+ git rebase --onto HEAD~4 HEAD~1 &&
384
+ git push --force-if-includes --force-with-lease="master"
385
+ )
386
+ '
387
+
388
+ test_expect_success ' "--force-if-includes" should allow deletes ' '
389
+ setup_src_dup_dst &&
390
+ test_when_finished "rm -fr dst src dup" &&
391
+ (
392
+ cd src &&
393
+ git switch branch &&
394
+ git pull --rebase origin branch &&
395
+ git push --force-if-includes --force-with-lease=branch origin :branch
396
+ )
397
+ '
398
+
259
399
test_done
0 commit comments