Skip to content

Commit 6d51217

Browse files
committed
Merge branch 'vd/stash-silence-reset'
"git stash" does not allow subcommands it internally runs as its implementation detail, except for "git reset", to emit messages; now "git reset" part has also been squelched. * vd/stash-silence-reset: reset: show --no-refresh in the short-help reset: remove 'reset.refresh' config option reset: remove 'reset.quiet' config option reset: do not make '--quiet' disable index refresh stash: make internal resets quiet and refresh index reset: suppress '--no-refresh' advice if logging is silenced reset: replace '--quiet' with '--no-refresh' in performance advice reset: introduce --[no-]refresh option to --mixed reset: revise index refresh advice
2 parents cb3b397 + 5891c76 commit 6d51217

File tree

11 files changed

+87
-30
lines changed

11 files changed

+87
-30
lines changed

Documentation/config.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,8 +495,6 @@ include::config/repack.txt[]
495495

496496
include::config/rerere.txt[]
497497

498-
include::config/reset.txt[]
499-
500498
include::config/sendemail.txt[]
501499

502500
include::config/sequencer.txt[]

Documentation/config/advice.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ advice.*::
6767
commitBeforeMerge::
6868
Advice shown when linkgit:git-merge[1] refuses to
6969
merge to avoid overwriting local changes.
70-
resetQuiet::
71-
Advice to consider using the `--quiet` option to linkgit:git-reset[1]
72-
when the command takes more than 2 seconds to enumerate unstaged
73-
changes after reset.
70+
resetNoRefresh::
71+
Advice to consider using the `--no-refresh` option to
72+
linkgit:git-reset[1] when the command takes more than 2 seconds
73+
to refresh the index after reset.
7474
resolveConflict::
7575
Advice shown by various commands when conflicts
7676
prevent the operation from being performed.

Documentation/config/reset.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

Documentation/git-reset.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,11 @@ OPTIONS
105105

106106
-q::
107107
--quiet::
108-
--no-quiet::
109-
Be quiet, only report errors. The default behavior is set by the
110-
`reset.quiet` config option. `--quiet` and `--no-quiet` will
111-
override the default behavior.
108+
Be quiet, only report errors.
109+
110+
--refresh::
111+
--no-refresh::
112+
Refresh the index after a mixed reset. Enabled by default.
112113

113114
--pathspec-from-file=<file>::
114115
Pathspec is passed in `<file>` instead of commandline args. If

advice.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static struct {
6161
[ADVICE_PUSH_NON_FF_MATCHING] = { "pushNonFFMatching", 1 },
6262
[ADVICE_PUSH_UNQUALIFIED_REF_NAME] = { "pushUnqualifiedRefName", 1 },
6363
[ADVICE_PUSH_UPDATE_REJECTED] = { "pushUpdateRejected", 1 },
64-
[ADVICE_RESET_QUIET_WARNING] = { "resetQuiet", 1 },
64+
[ADVICE_RESET_NO_REFRESH_WARNING] = { "resetNoRefresh", 1 },
6565
[ADVICE_RESOLVE_CONFLICT] = { "resolveConflict", 1 },
6666
[ADVICE_RM_HINTS] = { "rmHints", 1 },
6767
[ADVICE_SEQUENCER_IN_USE] = { "sequencerInUse", 1 },

advice.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ struct string_list;
3636
ADVICE_PUSH_UPDATE_REJECTED_ALIAS,
3737
ADVICE_PUSH_UPDATE_REJECTED,
3838
ADVICE_PUSH_REF_NEEDS_UPDATE,
39-
ADVICE_RESET_QUIET_WARNING,
39+
ADVICE_RESET_NO_REFRESH_WARNING,
4040
ADVICE_RESOLVE_CONFLICT,
4141
ADVICE_RM_HINTS,
4242
ADVICE_SEQUENCER_IN_USE,

builtin/reset.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -392,13 +392,16 @@ static int git_reset_config(const char *var, const char *value, void *cb)
392392
int cmd_reset(int argc, const char **argv, const char *prefix)
393393
{
394394
int reset_type = NONE, update_ref_status = 0, quiet = 0;
395+
int no_refresh = 0;
395396
int patch_mode = 0, pathspec_file_nul = 0, unborn;
396397
const char *rev, *pathspec_from_file = NULL;
397398
struct object_id oid;
398399
struct pathspec pathspec;
399400
int intent_to_add = 0;
400401
const struct option options[] = {
401402
OPT__QUIET(&quiet, N_("be quiet, only report errors")),
403+
OPT_BOOL(0, "no-refresh", &no_refresh,
404+
N_("skip refreshing the index after reset")),
402405
OPT_SET_INT(0, "mixed", &reset_type,
403406
N_("reset HEAD and index"), MIXED),
404407
OPT_SET_INT(0, "soft", &reset_type, N_("reset only HEAD"), SOFT),
@@ -420,7 +423,6 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
420423
};
421424

422425
git_config(git_reset_config, NULL);
423-
git_config_get_bool("reset.quiet", &quiet);
424426

425427
argc = parse_options(argc, argv, prefix, options, git_reset_usage,
426428
PARSE_OPT_KEEP_DASHDASH);
@@ -517,17 +519,16 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
517519
if (read_from_tree(&pathspec, &oid, intent_to_add))
518520
return 1;
519521
the_index.updated_skipworktree = 1;
520-
if (!quiet && get_git_work_tree()) {
522+
if (!no_refresh && get_git_work_tree()) {
521523
uint64_t t_begin, t_delta_in_ms;
522524

523525
t_begin = getnanotime();
524526
refresh_index(&the_index, flags, NULL, NULL,
525527
_("Unstaged changes after reset:"));
526528
t_delta_in_ms = (getnanotime() - t_begin) / 1000000;
527-
if (advice_enabled(ADVICE_RESET_QUIET_WARNING) && t_delta_in_ms > REFRESH_INDEX_DELAY_WARNING_IN_MS) {
528-
printf(_("\nIt took %.2f seconds to enumerate unstaged changes after reset. You can\n"
529-
"use '--quiet' to avoid this. Set the config setting reset.quiet to true\n"
530-
"to make this the default.\n"), t_delta_in_ms / 1000.0);
529+
if (!quiet && advice_enabled(ADVICE_RESET_NO_REFRESH_WARNING) && t_delta_in_ms > REFRESH_INDEX_DELAY_WARNING_IN_MS) {
530+
advise(_("It took %.2f seconds to refresh the index after reset. You can use\n"
531+
"'--no-refresh' to avoid this."), t_delta_in_ms / 1000.0);
531532
}
532533
}
533534
} else {

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
}
@@ -1622,7 +1622,8 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q
16221622
struct child_process cp = CHILD_PROCESS_INIT;
16231623

16241624
cp.git_cmd = 1;
1625-
strvec_pushl(&cp.args, "reset", "-q", "--", NULL);
1625+
strvec_pushl(&cp.args, "reset", "-q", "--refresh", "--",
1626+
NULL);
16261627
add_pathspecs(&cp.args, ps);
16271628
if (run_command(&cp)) {
16281629
ret = -1;

contrib/scalar/scalar.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ static int set_recommended_config(int reconfigure)
152152
{ "pack.useBitmaps", "false", 1 },
153153
{ "pack.useSparse", "true", 1 },
154154
{ "receive.autoGC", "false", 1 },
155-
{ "reset.quiet", "true", 1 },
156155
{ "feature.manyFiles", "false", 1 },
157156
{ "feature.experimental", "false", 1 },
158157
{ "fetch.unpackLimit", "1", 1 },

t/t3903-stash.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,18 @@ test_expect_success 'apply -q is quiet' '
302302
test_must_be_empty output.out
303303
'
304304

305+
test_expect_success 'apply --index -q is quiet' '
306+
# Added file, deleted file, modified file all staged for commit
307+
echo foo >new-file &&
308+
echo test >file &&
309+
git add new-file file &&
310+
git rm other-file &&
311+
312+
git stash &&
313+
git stash apply --index -q >output.out 2>&1 &&
314+
test_must_be_empty output.out
315+
'
316+
305317
test_expect_success 'save -q is quiet' '
306318
git stash save --quiet >output.out 2>&1 &&
307319
test_must_be_empty output.out
@@ -332,6 +344,27 @@ test_expect_success 'drop -q is quiet' '
332344
test_must_be_empty output.out
333345
'
334346

347+
test_expect_success 'stash push -q --staged refreshes the index' '
348+
git reset --hard &&
349+
echo test >file &&
350+
git add file &&
351+
git stash push -q --staged &&
352+
git diff-files >output.out &&
353+
test_must_be_empty output.out
354+
'
355+
356+
test_expect_success 'stash apply -q --index refreshes the index' '
357+
echo test >other-file &&
358+
git add other-file &&
359+
echo another-change >other-file &&
360+
git diff-files >expect &&
361+
git stash &&
362+
363+
git stash apply -q --index &&
364+
git diff-files >actual &&
365+
test_cmp expect actual
366+
'
367+
335368
test_expect_success 'stash -k' '
336369
echo bar3 >file &&
337370
echo bar4 >file2 &&

0 commit comments

Comments
 (0)