Skip to content

Commit 4b8b0f6

Browse files
vdyegitster
authored andcommitted
stash: make internal resets quiet and refresh index
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 <[email protected]> Signed-off-by: Victoria Dye <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d492abb commit 4b8b0f6

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

builtin/stash.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ static int reset_head(void)
310310
* API for resetting.
311311
*/
312312
cp.git_cmd = 1;
313-
strvec_push(&cp.args, "reset");
313+
strvec_pushl(&cp.args, "reset", "--quiet", "--refresh", NULL);
314314

315315
return run_command(&cp);
316316
}
@@ -1633,7 +1633,8 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q
16331633
struct child_process cp = CHILD_PROCESS_INIT;
16341634

16351635
cp.git_cmd = 1;
1636-
strvec_pushl(&cp.args, "reset", "-q", "--", NULL);
1636+
strvec_pushl(&cp.args, "reset", "-q", "--refresh", "--",
1637+
NULL);
16371638
add_pathspecs(&cp.args, ps);
16381639
if (run_command(&cp)) {
16391640
ret = -1;

t/t3903-stash.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,18 @@ test_expect_success 'apply -q is quiet' '
261261
test_must_be_empty output.out
262262
'
263263

264+
test_expect_success 'apply --index -q is quiet' '
265+
# Added file, deleted file, modified file all staged for commit
266+
echo foo >new-file &&
267+
echo test >file &&
268+
git add new-file file &&
269+
git rm other-file &&
270+
271+
git stash &&
272+
git stash apply --index -q >output.out 2>&1 &&
273+
test_must_be_empty output.out
274+
'
275+
264276
test_expect_success 'save -q is quiet' '
265277
git stash save --quiet >output.out 2>&1 &&
266278
test_must_be_empty output.out
@@ -291,6 +303,27 @@ test_expect_success 'drop -q is quiet' '
291303
test_must_be_empty output.out
292304
'
293305

306+
test_expect_success 'stash push -q --staged refreshes the index' '
307+
git reset --hard &&
308+
echo test >file &&
309+
git add file &&
310+
git stash push -q --staged &&
311+
git diff-files >output.out &&
312+
test_must_be_empty output.out
313+
'
314+
315+
test_expect_success 'stash apply -q --index refreshes the index' '
316+
echo test >other-file &&
317+
git add other-file &&
318+
echo another-change >other-file &&
319+
git diff-files >expect &&
320+
git stash &&
321+
322+
git stash apply -q --index &&
323+
git diff-files >actual &&
324+
test_cmp expect actual
325+
'
326+
294327
test_expect_success 'stash -k' '
295328
echo bar3 >file &&
296329
echo bar4 >file2 &&

0 commit comments

Comments
 (0)