@@ -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 origin
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 origin --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,101 @@ 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/branch >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/branch >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
+ (
342
+ cd src &&
343
+ git switch branch &&
344
+ test_commit I &&
345
+ git switch master &&
346
+ test_commit J &&
347
+ remote_head="$(git rev-parse refs/remotes/origin/master)" &&
348
+ git fetch --all &&
349
+ test_must_fail git push --force-if-includes --force-with-lease="master:$remote_head" 2>err &&
350
+ grep "stale info" err
351
+ ) &&
352
+ git ls-remote dst refs/heads/master >actual.master &&
353
+ test_cmp expect.master actual.master
354
+ '
355
+
356
+ test_expect_success ' "--force-if-includes" should allow forced update after a rebase ("pull --rebase")' '
357
+ setup_src_dup_dst &&
358
+ test_when_finished "rm -fr dst src dup" &&
359
+ (
360
+ cd src &&
361
+ git switch branch &&
362
+ test_commit I &&
363
+ git switch master &&
364
+ test_commit J &&
365
+ git pull --rebase origin master &&
366
+ git push --force-if-includes --force-with-lease="master"
367
+ )
368
+ '
369
+
370
+ test_expect_success ' "--force-if-includes" should allow forced update after a rebase ("pull --rebase", local rebase)' '
371
+ setup_src_dup_dst &&
372
+ test_when_finished "rm -fr dst src dup" &&
373
+ (
374
+ cd src &&
375
+ git switch branch &&
376
+ test_commit I &&
377
+ git switch master &&
378
+ test_commit J &&
379
+ git pull --rebase origin master &&
380
+ git rebase --onto HEAD~4 HEAD~1 &&
381
+ git push --force-if-includes --force-with-lease="master"
382
+ )
383
+ '
384
+
385
+ test_expect_success ' "--force-if-includes" should allow deletes' '
386
+ setup_src_dup_dst &&
387
+ test_when_finished "rm -fr dst src dup" &&
388
+ (
389
+ cd src &&
390
+ git switch branch &&
391
+ git pull --rebase origin branch &&
392
+ git push --force-if-includes --force-with-lease="branch" origin :branch
393
+ )
394
+ '
395
+
259
396
test_done
0 commit comments