292
test_cmp expect actual
293
'
294
295
+test_expect_success 'status tracking origin/main shows only main' '
296
+ (
297
+ cd test &&
298
+ git checkout b4 &&
299
+ git status >../actual
300
+ ) &&
301
+ cat >expect <<-EOF &&
302
+ On branch b4
303
+ Your branch is ahead of ${SQ}origin/main${SQ} by 2 commits.
304
+ (use "git push" to publish your local commits)
305
+
306
+ nothing to commit, working tree clean
307
+ EOF
308
+ test_cmp expect actual
309
+'
310
+
311
+test_expect_success 'status --no-ahead-behind tracking origin/main shows only main' '
312
+ (
313
+ cd test &&
314
+ git checkout b4 &&
315
+ git status --no-ahead-behind >../actual
316
+ ) &&
317
+ cat >expect <<-EOF &&
318
+ On branch b4
319
+ Your branch and ${SQ}origin/main${SQ} refer to different commits.
320
+ (use "git status --ahead-behind" for details)
321
+
322
+ nothing to commit, working tree clean
323
+ EOF
324
+ test_cmp expect actual
325
+'
326
+
327
+test_expect_success 'status.compareBranches from upstream has no duplicates' '
328
+ test_config -C test status.compareBranches "@{upstream} @{push}" &&
329
+ git -C test checkout main &&
330
+ git -C test status >actual &&
331
+ cat >expect <<-EOF &&
332
+ On branch main
333
+ Your branch is up to date with ${SQ}origin/main${SQ}.
334
+
335
+ nothing to commit, working tree clean
336
+ EOF
337
+ test_cmp expect actual
338
+'
339
+
340
+test_expect_success 'status.compareBranches shows ahead of both upstream and push branch' '
341
+ test_config -C test push.default current &&
342
+ test_config -C test status.compareBranches "@{upstream} @{push}" &&
343
+ git -C test checkout -b feature2 origin/main &&
344
+ git -C test push origin HEAD &&
345
+ (cd test && advance work) &&
346
+ git -C test status >actual &&
347
+ cat >expect <<-EOF &&
348
+ On branch feature2
349
+ Your branch is ahead of ${SQ}origin/main${SQ} by 1 commit.
350
+
351
+ Your branch is ahead of ${SQ}origin/feature2${SQ} by 1 commit.
352
+ (use "git push" to publish your local commits)
353
+
354
+ nothing to commit, working tree clean
355
+ EOF
356
+ test_cmp expect actual
357
+'
358
+
359
+test_expect_success 'checkout with status.compareBranches shows both branches' '
360
+ test_config -C test push.default current &&
361
+ test_config -C test status.compareBranches "@{upstream} @{push}" &&
362
+ git -C test checkout feature2 >actual &&
363
+ cat >expect <<-EOF &&
364
+ Your branch is ahead of ${SQ}origin/main${SQ} by 1 commit.
365
+
366
+ Your branch is ahead of ${SQ}origin/feature2${SQ} by 1 commit.
367
+ (use "git push" to publish your local commits)
368
+ EOF
369
+ test_cmp expect actual
370
+'
371
+
372
+test_expect_success 'setup for ahead of tracked but diverged from main' '
373
+ (
374
+ cd test &&
375
+ git checkout -b feature4 origin/main &&
376
+ advance work1 &&
377
+ git checkout origin/main &&
378
+ advance work2 &&
379
+ git push origin HEAD:main &&
380
+ git checkout feature4 &&
381
+ advance work3
382
+ )
383
+'
384
+
385
+test_expect_success 'status.compareBranches shows diverged and ahead' '
386
+ test_config -C test push.default current &&
387
+ test_config -C test status.compareBranches "@{upstream} @{push}" &&
388
+ git -C test checkout feature4 &&
389
+ git -C test branch --set-upstream-to origin/main &&
390
+ git -C test push origin HEAD &&
391
+ (cd test && advance work) &&
392
+ git -C test status >actual &&
393
+ cat >expect <<-EOF &&
394
+ On branch feature4
395
+ Your branch and ${SQ}origin/main${SQ} have diverged,
396
+ and have 3 and 1 different commits each, respectively.
397
+ (use "git pull" if you want to integrate the remote branch with yours)
398
+
399
+ Your branch is ahead of ${SQ}origin/feature4${SQ} by 1 commit.
400
+ (use "git push" to publish your local commits)
401
+
402
+ nothing to commit, working tree clean
403
+ EOF
404
+ test_cmp expect actual
405
+'
406
+
407
+test_expect_success 'status --no-ahead-behind with status.compareBranches' '
408
+ test_config -C test push.default current &&
409
+ test_config -C test status.compareBranches "@{upstream} @{push}" &&
410
+ git -C test checkout feature4 &&
411
+ git -C test status --no-ahead-behind >actual &&
412
+ cat >expect <<-EOF &&
413
+ On branch feature4
414
+ Your branch and ${SQ}origin/main${SQ} refer to different commits.
415
+
416
+ Your branch and ${SQ}origin/feature4${SQ} refer to different commits.
417
+ (use "git status --ahead-behind" for details)
418
+
419
+ nothing to commit, working tree clean
420
+ EOF
421
+ test_cmp expect actual
422
+'
423
+
424
+test_expect_success 'setup upstream remote' '
425
+ (
426
+ cd test &&
427
+ git remote add upstream ../. &&
428
+ git fetch upstream
429
+ )
430
+'
431
+
432
+test_expect_success 'status.compareBranches with upstream and origin remotes' '
433
+ test_config -C test push.default current &&
434
+ test_config -C test remote.pushDefault origin &&
435
+ test_config -C test status.compareBranches "@{upstream} @{push}" &&
436
+ git -C test checkout -b feature5 upstream/main &&
437
+ git -C test push origin &&
438
+ (cd test && advance work) &&
439
+ git -C test status >actual &&
440
+ cat >expect <<-EOF &&
441
+ On branch feature5
442
+ Your branch is ahead of ${SQ}upstream/main${SQ} by 1 commit.
443
+
444
+ Your branch is ahead of ${SQ}origin/feature5${SQ} by 1 commit.
445
+ (use "git push" to publish your local commits)
446
+
447
+ nothing to commit, working tree clean
448
+ EOF
449
+ test_cmp expect actual
450
+'
451
+
452
+test_expect_success 'status.compareBranches supports ordered upstream/push entries' '
453
+ test_config -C test push.default current &&
454
+ test_config -C test remote.pushDefault origin &&
455
+ test_config -C test status.compareBranches "@{push} @{upstream}" &&
456
+ git -C test checkout -b feature6 upstream/main &&
457
+ git -C test push origin &&
458
+ (cd test && advance work) &&
459
+ git -C test status >actual &&
460
+ cat >expect <<-EOF &&
461
+ On branch feature6
462
+ Your branch is ahead of ${SQ}origin/feature6${SQ} by 1 commit.
463
+ (use "git push" to publish your local commits)
464
+
465
+ Your branch is ahead of ${SQ}upstream/main${SQ} by 1 commit.
466
+
467
+ nothing to commit, working tree clean
468
+ EOF
469
+ test_cmp expect actual
470
+'
471
+
472
+test_expect_success 'status.compareBranches with diverged push branch' '
473
+ test_config -C test push.default current &&
474
+ test_config -C test remote.pushDefault origin &&
475
+ test_config -C test status.compareBranches "@{upstream} @{push}" &&
476
+ git -C test checkout -b feature7 upstream/main &&
477
+ (cd test && advance work71) &&
478
+ git -C test push origin &&
479
+ git -C test reset --hard upstream/main &&
480
+ (cd test && advance work72) &&
481
+ git -C test status >actual &&
482
+ cat >expect <<-EOF &&
483
+ On branch feature7
484
+ Your branch is ahead of ${SQ}upstream/main${SQ} by 1 commit.
485
+
486
+ Your branch and ${SQ}origin/feature7${SQ} have diverged,
487
+ and have 1 and 1 different commits each, respectively.
488
+
489
+ nothing to commit, working tree clean
490
+ EOF
491
+ test_cmp expect actual
492
+'
493
+
494
+test_expect_success 'status.compareBranches shows up to date branches' '
495
+ test_config -C test push.default current &&
496
+ test_config -C test remote.pushDefault origin &&
497
+ test_config -C test status.compareBranches "@{upstream} @{push}" &&
498
+ git -C test checkout -b feature8 upstream/main &&
499
+ git -C test push origin &&
500
+ git -C test status >actual &&
501
+ cat >expect <<-EOF &&
502
+ On branch feature8
503
+ Your branch is up to date with ${SQ}upstream/main${SQ}.
504
+
505
+ Your branch is up to date with ${SQ}origin/feature8${SQ}.
506
+
507
+ nothing to commit, working tree clean
508
+ EOF
509
+ test_cmp expect actual
510
+'
511
+
512
+test_expect_success 'status --no-ahead-behind with status.compareBranches up to date' '
513
+ test_config -C test push.default current &&
514
+ test_config -C test remote.pushDefault origin &&
515
+ test_config -C test status.compareBranches "@{upstream} @{push}" &&
516
+ git -C test checkout feature8 >actual &&
517
+ git -C test push origin &&
518
+ git -C test status --no-ahead-behind >actual &&
519
+ cat >expect <<-EOF &&
520
+ On branch feature8
521
+ Your branch is up to date with ${SQ}upstream/main${SQ}.
522
+
523
+ Your branch is up to date with ${SQ}origin/feature8${SQ}.
524
+
525
+ nothing to commit, working tree clean
526
+ EOF
527
+ test_cmp expect actual
528
+'
529
+
530
+test_expect_success 'checkout with status.compareBranches shows up to date' '
531
+ test_config -C test push.default current &&
532
+ test_config -C test remote.pushDefault origin &&
533
+ test_config -C test status.compareBranches "@{upstream} @{push}" &&
534
+ git -C test checkout feature8 >actual &&
535
+ cat >expect <<-EOF &&
536
+ Your branch is up to date with ${SQ}upstream/main${SQ}.
537
+
538
+ Your branch is up to date with ${SQ}origin/feature8${SQ}.
539
+ EOF
540
+ test_cmp expect actual
541
+'
542
+
543
+test_expect_success 'status.compareBranches with upstream behind and push up to date' '
544
+ test_config -C test push.default current &&
545
+ test_config -C test remote.pushDefault origin &&
546
+ test_config -C test status.compareBranches "@{upstream} @{push}" &&
547
+ git -C test checkout -b ahead upstream/main &&
548
+ (cd test && advance work) &&
549
+ git -C test push upstream HEAD &&
550
+ git -C test checkout -b feature9 upstream/main &&
551
+ git -C test push origin &&
552
+ git -C test branch --set-upstream-to upstream/ahead &&
553
+ git -C test status >actual &&
554
+ cat >expect <<-EOF &&
555
+ On branch feature9
556
+ Your branch is behind ${SQ}upstream/ahead${SQ} by 1 commit, and can be fast-forwarded.
557
+ (use "git pull" to update your local branch)
558
+
559
+ Your branch is up to date with ${SQ}origin/feature9${SQ}.
560
+
561
+ nothing to commit, working tree clean
562
+ EOF
563
+ test_cmp expect actual
564
+'
565
+
566
+test_expect_success 'status.compareBranches with remapped push refspec' '
567
+ test_config -C test remote.origin.push refs/heads/feature10:refs/heads/remapped &&
568
+ test_config -C test status.compareBranches "@{upstream} @{push}" &&
569
+ git -C test checkout -b feature10 origin/main &&
570
+ git -C test push &&
571
+ (cd test && advance work) &&
572
+ git -C test status >actual &&
573
+ cat >expect <<-EOF &&
574
+ On branch feature10
575
+ Your branch is ahead of ${SQ}origin/main${SQ} by 1 commit.
576
+
577
+ Your branch is ahead of ${SQ}origin/remapped${SQ} by 1 commit.
578
+ (use "git push" to publish your local commits)
579
+
580
+ nothing to commit, working tree clean
581
+ EOF
582
+ test_cmp expect actual
583
+'
584
+
585
+test_expect_success 'status.compareBranches with remapped push and upstream remote' '
586
+ test_config -C test remote.pushDefault origin &&
587
+ test_config -C test remote.origin.push refs/heads/feature11:refs/heads/remapped &&
588
+ test_config -C test status.compareBranches "@{upstream} @{push}" &&
589
+ git -C test checkout -b feature11 upstream/main &&
590
+ git -C test push origin &&
591
+ (cd test && advance work) &&
592
+ git -C test status >actual &&
593
+ cat >expect <<-EOF &&
594
+ On branch feature11
595
+ Your branch is ahead of ${SQ}upstream/main${SQ} by 1 commit.
596
+
597
+ Your branch is ahead of ${SQ}origin/remapped${SQ} by 1 commit.
598
+ (use "git push" to publish your local commits)
599
+
600
+ nothing to commit, working tree clean
601
+ EOF
602
+ test_cmp expect actual
603
+'
604
+
605
test_done