462
git diff-index --cached --exit-code HEAD
463
'
464
465
+test_reset_refreshes_index () {
466
+
467
+ # To test whether the index is refreshed in `git reset --mixed` with
468
+ # the given options, create a scenario where we clearly see different
469
+ # results depending on whether the refresh occurred or not.
470
+
471
+ # Step 0: start with a clean index
472
+ git reset --hard HEAD &&
473
+
474
+ # Step 1: remove file2, but only in the index (no change to worktree)
475
+ git rm --cached file2 &&
476
+
477
+ # Step 2: reset index & leave worktree unchanged from HEAD
478
+ git $1 reset $2 --mixed HEAD &&
479
+
480
+ # Step 3: verify whether the index is refreshed by checking whether
481
+ # file2 still has staged changes in the index differing from HEAD (if
482
+ # the refresh occurred, there should be no such changes)
483
+ git diff-files >output.log &&
484
+ test_must_be_empty output.log
485
+}
486
+
487
test_expect_success '--mixed refreshes the index' '
466
- cat >expect <<-\EOF &&
467
- Unstaged changes after reset:
468
- M file2
469
- EOF
470
- echo 123 >>file2 &&
471
- git reset --mixed HEAD >output &&
472
- test_cmp expect output
488
+ # Verify default behavior (with no config settings or command line
489
+ # options)
490
+ test_reset_refreshes_index
491
+'
492
+test_expect_success '--mixed --[no-]quiet sets default refresh behavior' '
493
+ # Verify that --[no-]quiet and `reset.quiet` (without --[no-]refresh)
494
+ # determine refresh behavior
495
+
496
+ # Config setting
497
+ ! test_reset_refreshes_index "-c reset.quiet=true" &&
498
+ test_reset_refreshes_index "-c reset.quiet=false" &&
499
+
500
+ # Command line option
501
+ ! test_reset_refreshes_index "" --quiet &&
502
+ test_reset_refreshes_index "" --no-quiet &&
503
+
504
+ # Command line option overrides config setting
505
+ ! test_reset_refreshes_index "-c reset.quiet=false" --quiet &&
506
+ test_reset_refreshes_index "-c reset.refresh=true" --no-quiet
507
+'
508
+
509
+test_expect_success '--mixed --[no-]refresh sets refresh behavior' '
510
+ # Verify that --[no-]refresh and `reset.refresh` control index refresh
511
+
512
+ # Config setting
513
+ test_reset_refreshes_index "-c reset.refresh=true" &&
514
+ ! test_reset_refreshes_index "-c reset.refresh=false" &&
515
+
516
+ # Command line option
517
+ test_reset_refreshes_index "" --refresh &&
518
+ ! test_reset_refreshes_index "" --no-refresh &&
519
+
520
+ # Command line option overrides config setting
521
+ test_reset_refreshes_index "-c reset.refresh=false" --refresh &&
522
+ ! test_reset_refreshes_index "-c reset.refresh=true" --no-refresh
523
+'
524
+
525
+test_expect_success '--mixed --refresh overrides --quiet refresh behavior' '
526
+ # Verify that *both* --refresh and `reset.refresh` override the
527
+ # default non-refresh behavior of --quiet
528
+ test_reset_refreshes_index "" "--quiet --refresh" &&
529
+ test_reset_refreshes_index "-c reset.quiet=true" --refresh &&
530
+ test_reset_refreshes_index "-c reset.refresh=true" --quiet &&
531
+ test_reset_refreshes_index "-c reset.refresh=true -c reset.quiet=true"
532
'
533
534
test_expect_success '--mixed preserves skip-worktree' '