]> git.ipfire.org Git - thirdparty/git.git/commitdiff
stash: make internal resets quiet and refresh index
authorVictoria Dye <vdye@github.com>
Tue, 15 Mar 2022 01:49:42 +0000 (01:49 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 15 Mar 2022 01:51:56 +0000 (18:51 -0700)
Add the options '-q' and '--refresh' to the 'git reset' executed in
'reset_head()', and '--refresh' to the 'git reset -q' executed in
'do_push_stash(...)'.

'stash' is implemented such that git commands invoked  as part of it (e.g.,
'clean', 'read-tree', 'reset', etc.) have their informational output
silenced. However, the 'reset' in 'reset_head()' is *not* called with '-q',
leading to the potential for a misleading printout from 'git stash apply
--index' if the stash included a removed file:

Unstaged changes after reset: D      <deleted file>

Not only is this confusing in its own right (since, after the reset, 'git
stash' execution would stage the deletion in the index), it would be printed
even when the stash was applied with the '-q' option. As a result, the
messaging is removed entirely by calling 'git status' with '-q'.

Additionally, because the default behavior of 'git reset -q' is to skip
refreshing the index, but later operations in 'git stash' subcommands expect
a non-stale index, enable '--refresh' as well.

Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Victoria Dye <vdye@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/stash.c
t/t3903-stash.sh

index 3e8af210fdee6e5901497e5c572d8bc4da23502a..91407d9bbe0a6aea4c5e23cac60ab19503b91953 100644 (file)
@@ -310,7 +310,7 @@ static int reset_head(void)
         * API for resetting.
         */
        cp.git_cmd = 1;
-       strvec_push(&cp.args, "reset");
+       strvec_pushl(&cp.args, "reset", "--quiet", "--refresh", NULL);
 
        return run_command(&cp);
 }
@@ -1633,7 +1633,8 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q
                        struct child_process cp = CHILD_PROCESS_INIT;
 
                        cp.git_cmd = 1;
-                       strvec_pushl(&cp.args, "reset", "-q", "--", NULL);
+                       strvec_pushl(&cp.args, "reset", "-q", "--refresh", "--",
+                                    NULL);
                        add_pathspecs(&cp.args, ps);
                        if (run_command(&cp)) {
                                ret = -1;
index f36e121210e18e655b98c7e05505e5a5917ac2b7..1a5c1bd31094385f4f7a20a6bffdc151edc09be9 100755 (executable)
@@ -261,6 +261,18 @@ test_expect_success 'apply -q is quiet' '
        test_must_be_empty output.out
 '
 
+test_expect_success 'apply --index -q is quiet' '
+       # Added file, deleted file, modified file all staged for commit
+       echo foo >new-file &&
+       echo test >file &&
+       git add new-file file &&
+       git rm other-file &&
+
+       git stash &&
+       git stash apply --index -q >output.out 2>&1 &&
+       test_must_be_empty output.out
+'
+
 test_expect_success 'save -q is quiet' '
        git stash save --quiet >output.out 2>&1 &&
        test_must_be_empty output.out
@@ -291,6 +303,27 @@ test_expect_success 'drop -q is quiet' '
        test_must_be_empty output.out
 '
 
+test_expect_success 'stash push -q --staged refreshes the index' '
+       git reset --hard &&
+       echo test >file &&
+       git add file &&
+       git stash push -q --staged &&
+       git diff-files >output.out &&
+       test_must_be_empty output.out
+'
+
+test_expect_success 'stash apply -q --index refreshes the index' '
+       echo test >other-file &&
+       git add other-file &&
+       echo another-change >other-file &&
+       git diff-files >expect &&
+       git stash &&
+
+       git stash apply -q --index &&
+       git diff-files >actual &&
+       test_cmp expect actual
+'
+
 test_expect_success 'stash -k' '
        echo bar3 >file &&
        echo bar4 >file2 &&