зеркало из https://github.com/microsoft/git.git
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
This commit is contained in:
Коммит
6d51217467
|
@ -495,8 +495,6 @@ include::config/repack.txt[]
|
|||
|
||||
include::config/rerere.txt[]
|
||||
|
||||
include::config/reset.txt[]
|
||||
|
||||
include::config/sendemail.txt[]
|
||||
|
||||
include::config/sequencer.txt[]
|
||||
|
|
|
@ -67,10 +67,10 @@ advice.*::
|
|||
commitBeforeMerge::
|
||||
Advice shown when linkgit:git-merge[1] refuses to
|
||||
merge to avoid overwriting local changes.
|
||||
resetQuiet::
|
||||
Advice to consider using the `--quiet` option to linkgit:git-reset[1]
|
||||
when the command takes more than 2 seconds to enumerate unstaged
|
||||
changes after reset.
|
||||
resetNoRefresh::
|
||||
Advice to consider using the `--no-refresh` option to
|
||||
linkgit:git-reset[1] when the command takes more than 2 seconds
|
||||
to refresh the index after reset.
|
||||
resolveConflict::
|
||||
Advice shown by various commands when conflicts
|
||||
prevent the operation from being performed.
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
reset.quiet::
|
||||
When set to true, 'git reset' will default to the '--quiet' option.
|
|
@ -105,10 +105,11 @@ OPTIONS
|
|||
|
||||
-q::
|
||||
--quiet::
|
||||
--no-quiet::
|
||||
Be quiet, only report errors. The default behavior is set by the
|
||||
`reset.quiet` config option. `--quiet` and `--no-quiet` will
|
||||
override the default behavior.
|
||||
Be quiet, only report errors.
|
||||
|
||||
--refresh::
|
||||
--no-refresh::
|
||||
Refresh the index after a mixed reset. Enabled by default.
|
||||
|
||||
--pathspec-from-file=<file>::
|
||||
Pathspec is passed in `<file>` instead of commandline args. If
|
||||
|
|
2
advice.c
2
advice.c
|
@ -61,7 +61,7 @@ static struct {
|
|||
[ADVICE_PUSH_NON_FF_MATCHING] = { "pushNonFFMatching", 1 },
|
||||
[ADVICE_PUSH_UNQUALIFIED_REF_NAME] = { "pushUnqualifiedRefName", 1 },
|
||||
[ADVICE_PUSH_UPDATE_REJECTED] = { "pushUpdateRejected", 1 },
|
||||
[ADVICE_RESET_QUIET_WARNING] = { "resetQuiet", 1 },
|
||||
[ADVICE_RESET_NO_REFRESH_WARNING] = { "resetNoRefresh", 1 },
|
||||
[ADVICE_RESOLVE_CONFLICT] = { "resolveConflict", 1 },
|
||||
[ADVICE_RM_HINTS] = { "rmHints", 1 },
|
||||
[ADVICE_SEQUENCER_IN_USE] = { "sequencerInUse", 1 },
|
||||
|
|
2
advice.h
2
advice.h
|
@ -36,7 +36,7 @@ struct string_list;
|
|||
ADVICE_PUSH_UPDATE_REJECTED_ALIAS,
|
||||
ADVICE_PUSH_UPDATE_REJECTED,
|
||||
ADVICE_PUSH_REF_NEEDS_UPDATE,
|
||||
ADVICE_RESET_QUIET_WARNING,
|
||||
ADVICE_RESET_NO_REFRESH_WARNING,
|
||||
ADVICE_RESOLVE_CONFLICT,
|
||||
ADVICE_RM_HINTS,
|
||||
ADVICE_SEQUENCER_IN_USE,
|
||||
|
|
|
@ -392,6 +392,7 @@ static int git_reset_config(const char *var, const char *value, void *cb)
|
|||
int cmd_reset(int argc, const char **argv, const char *prefix)
|
||||
{
|
||||
int reset_type = NONE, update_ref_status = 0, quiet = 0;
|
||||
int no_refresh = 0;
|
||||
int patch_mode = 0, pathspec_file_nul = 0, unborn;
|
||||
const char *rev, *pathspec_from_file = NULL;
|
||||
struct object_id oid;
|
||||
|
@ -399,6 +400,8 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
|
|||
int intent_to_add = 0;
|
||||
const struct option options[] = {
|
||||
OPT__QUIET(&quiet, N_("be quiet, only report errors")),
|
||||
OPT_BOOL(0, "no-refresh", &no_refresh,
|
||||
N_("skip refreshing the index after reset")),
|
||||
OPT_SET_INT(0, "mixed", &reset_type,
|
||||
N_("reset HEAD and index"), MIXED),
|
||||
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)
|
|||
};
|
||||
|
||||
git_config(git_reset_config, NULL);
|
||||
git_config_get_bool("reset.quiet", &quiet);
|
||||
|
||||
argc = parse_options(argc, argv, prefix, options, git_reset_usage,
|
||||
PARSE_OPT_KEEP_DASHDASH);
|
||||
|
@ -517,17 +519,16 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
|
|||
if (read_from_tree(&pathspec, &oid, intent_to_add))
|
||||
return 1;
|
||||
the_index.updated_skipworktree = 1;
|
||||
if (!quiet && get_git_work_tree()) {
|
||||
if (!no_refresh && get_git_work_tree()) {
|
||||
uint64_t t_begin, t_delta_in_ms;
|
||||
|
||||
t_begin = getnanotime();
|
||||
refresh_index(&the_index, flags, NULL, NULL,
|
||||
_("Unstaged changes after reset:"));
|
||||
t_delta_in_ms = (getnanotime() - t_begin) / 1000000;
|
||||
if (advice_enabled(ADVICE_RESET_QUIET_WARNING) && t_delta_in_ms > REFRESH_INDEX_DELAY_WARNING_IN_MS) {
|
||||
printf(_("\nIt took %.2f seconds to enumerate unstaged changes after reset. You can\n"
|
||||
"use '--quiet' to avoid this. Set the config setting reset.quiet to true\n"
|
||||
"to make this the default.\n"), t_delta_in_ms / 1000.0);
|
||||
if (!quiet && advice_enabled(ADVICE_RESET_NO_REFRESH_WARNING) && t_delta_in_ms > REFRESH_INDEX_DELAY_WARNING_IN_MS) {
|
||||
advise(_("It took %.2f seconds to refresh the index after reset. You can use\n"
|
||||
"'--no-refresh' to avoid this."), t_delta_in_ms / 1000.0);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
@ -1622,7 +1622,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;
|
||||
|
|
|
@ -152,7 +152,6 @@ static int set_recommended_config(int reconfigure)
|
|||
{ "pack.useBitmaps", "false", 1 },
|
||||
{ "pack.useSparse", "true", 1 },
|
||||
{ "receive.autoGC", "false", 1 },
|
||||
{ "reset.quiet", "true", 1 },
|
||||
{ "feature.manyFiles", "false", 1 },
|
||||
{ "feature.experimental", "false", 1 },
|
||||
{ "fetch.unpackLimit", "1", 1 },
|
||||
|
|
|
@ -302,6 +302,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
|
||||
|
@ -332,6 +344,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 &&
|
||||
|
|
|
@ -462,14 +462,40 @@ test_expect_success 'resetting an unmodified path is a no-op' '
|
|||
git diff-index --cached --exit-code HEAD
|
||||
'
|
||||
|
||||
test_reset_refreshes_index () {
|
||||
|
||||
# To test whether the index is refreshed in `git reset --mixed` with
|
||||
# the given options, create a scenario where we clearly see different
|
||||
# results depending on whether the refresh occurred or not.
|
||||
|
||||
# Step 0: start with a clean index
|
||||
git reset --hard HEAD &&
|
||||
|
||||
# Step 1: remove file2, but only in the index (no change to worktree)
|
||||
git rm --cached file2 &&
|
||||
|
||||
# Step 2: reset index & leave worktree unchanged from HEAD
|
||||
git $1 reset $2 --mixed HEAD &&
|
||||
|
||||
# Step 3: verify whether the index is refreshed by checking whether
|
||||
# file2 still has staged changes in the index differing from HEAD (if
|
||||
# the refresh occurred, there should be no such changes)
|
||||
git diff-files >output.log &&
|
||||
test_must_be_empty output.log
|
||||
}
|
||||
|
||||
test_expect_success '--mixed refreshes the index' '
|
||||
cat >expect <<-\EOF &&
|
||||
Unstaged changes after reset:
|
||||
M file2
|
||||
EOF
|
||||
echo 123 >>file2 &&
|
||||
git reset --mixed HEAD >output &&
|
||||
test_cmp expect output
|
||||
# Verify default behavior (without --[no-]refresh or reset.refresh)
|
||||
test_reset_refreshes_index &&
|
||||
|
||||
# With --quiet
|
||||
test_reset_refreshes_index "" --quiet
|
||||
'
|
||||
|
||||
test_expect_success '--mixed --[no-]refresh sets refresh behavior' '
|
||||
# Verify that --[no-]refresh controls index refresh
|
||||
test_reset_refreshes_index "" --refresh &&
|
||||
! test_reset_refreshes_index "" --no-refresh
|
||||
'
|
||||
|
||||
test_expect_success '--mixed preserves skip-worktree' '
|
||||
|
|
Загрузка…
Ссылка в новой задаче