mirror of
https://github.com/git/git
synced 2024-08-25 02:35:46 +00:00
checkout,merge: disallow overwriting ignored files with --no-overwrite-ignore
Ignored files usually are generated files (e.g. .o files) and can be safely discarded. However sometimes users may have important files in working directory, but still want a clean "git status", so they mark them as ignored files. But in this case, these files should not be overwritten without asking first. Enable this use case with --no-overwrite-ignore, where git only sees tracked and untracked files, no ignored files. Those who mix discardable ignored files with important ones may have to sort it out themselves. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
f44054c82f
commit
c1d7036b6b
|
@ -34,6 +34,7 @@ struct checkout_opts {
|
||||||
int force_detach;
|
int force_detach;
|
||||||
int writeout_stage;
|
int writeout_stage;
|
||||||
int writeout_error;
|
int writeout_error;
|
||||||
|
int overwrite_ignore;
|
||||||
|
|
||||||
/* not set by parse_options */
|
/* not set by parse_options */
|
||||||
int branch_exists;
|
int branch_exists;
|
||||||
|
@ -409,9 +410,11 @@ static int merge_working_tree(struct checkout_opts *opts,
|
||||||
topts.gently = opts->merge && old->commit;
|
topts.gently = opts->merge && old->commit;
|
||||||
topts.verbose_update = !opts->quiet;
|
topts.verbose_update = !opts->quiet;
|
||||||
topts.fn = twoway_merge;
|
topts.fn = twoway_merge;
|
||||||
topts.dir = xcalloc(1, sizeof(*topts.dir));
|
if (opts->overwrite_ignore) {
|
||||||
topts.dir->flags |= DIR_SHOW_IGNORED;
|
topts.dir = xcalloc(1, sizeof(*topts.dir));
|
||||||
setup_standard_excludes(topts.dir);
|
topts.dir->flags |= DIR_SHOW_IGNORED;
|
||||||
|
setup_standard_excludes(topts.dir);
|
||||||
|
}
|
||||||
tree = parse_tree_indirect(old->commit ?
|
tree = parse_tree_indirect(old->commit ?
|
||||||
old->commit->object.sha1 :
|
old->commit->object.sha1 :
|
||||||
EMPTY_TREE_SHA1_BIN);
|
EMPTY_TREE_SHA1_BIN);
|
||||||
|
@ -926,6 +929,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
|
||||||
3),
|
3),
|
||||||
OPT__FORCE(&opts.force, "force checkout (throw away local modifications)"),
|
OPT__FORCE(&opts.force, "force checkout (throw away local modifications)"),
|
||||||
OPT_BOOLEAN('m', "merge", &opts.merge, "perform a 3-way merge with the new branch"),
|
OPT_BOOLEAN('m', "merge", &opts.merge, "perform a 3-way merge with the new branch"),
|
||||||
|
OPT_BOOLEAN(0, "overwrite-ignore", &opts.overwrite_ignore, "update ignored files (default)"),
|
||||||
OPT_STRING(0, "conflict", &conflict_style, "style",
|
OPT_STRING(0, "conflict", &conflict_style, "style",
|
||||||
"conflict style (merge or diff3)"),
|
"conflict style (merge or diff3)"),
|
||||||
OPT_BOOLEAN('p', "patch", &patch_mode, "select hunks interactively"),
|
OPT_BOOLEAN('p', "patch", &patch_mode, "select hunks interactively"),
|
||||||
|
@ -937,6 +941,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
|
||||||
|
|
||||||
memset(&opts, 0, sizeof(opts));
|
memset(&opts, 0, sizeof(opts));
|
||||||
memset(&new, 0, sizeof(new));
|
memset(&new, 0, sizeof(new));
|
||||||
|
opts.overwrite_ignore = 1;
|
||||||
|
|
||||||
gitmodules_config();
|
gitmodules_config();
|
||||||
git_config(git_checkout_config, &opts);
|
git_config(git_checkout_config, &opts);
|
||||||
|
|
|
@ -48,6 +48,7 @@ static int show_diffstat = 1, shortlog_len, squash;
|
||||||
static int option_commit = 1, allow_fast_forward = 1;
|
static int option_commit = 1, allow_fast_forward = 1;
|
||||||
static int fast_forward_only, option_edit;
|
static int fast_forward_only, option_edit;
|
||||||
static int allow_trivial = 1, have_message;
|
static int allow_trivial = 1, have_message;
|
||||||
|
static int overwrite_ignore = 1;
|
||||||
static struct strbuf merge_msg;
|
static struct strbuf merge_msg;
|
||||||
static struct commit_list *remoteheads;
|
static struct commit_list *remoteheads;
|
||||||
static struct strategy **use_strategies;
|
static struct strategy **use_strategies;
|
||||||
|
@ -207,6 +208,7 @@ static struct option builtin_merge_options[] = {
|
||||||
OPT_BOOLEAN(0, "abort", &abort_current_merge,
|
OPT_BOOLEAN(0, "abort", &abort_current_merge,
|
||||||
"abort the current in-progress merge"),
|
"abort the current in-progress merge"),
|
||||||
OPT_SET_INT(0, "progress", &show_progress, "force progress reporting", 1),
|
OPT_SET_INT(0, "progress", &show_progress, "force progress reporting", 1),
|
||||||
|
OPT_BOOLEAN(0, "overwrite-ignore", &overwrite_ignore, "update ignored files (default)"),
|
||||||
OPT_END()
|
OPT_END()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -773,10 +775,12 @@ int checkout_fast_forward(const unsigned char *head, const unsigned char *remote
|
||||||
memset(&trees, 0, sizeof(trees));
|
memset(&trees, 0, sizeof(trees));
|
||||||
memset(&opts, 0, sizeof(opts));
|
memset(&opts, 0, sizeof(opts));
|
||||||
memset(&t, 0, sizeof(t));
|
memset(&t, 0, sizeof(t));
|
||||||
memset(&dir, 0, sizeof(dir));
|
if (overwrite_ignore) {
|
||||||
dir.flags |= DIR_SHOW_IGNORED;
|
memset(&dir, 0, sizeof(dir));
|
||||||
setup_standard_excludes(&dir);
|
dir.flags |= DIR_SHOW_IGNORED;
|
||||||
opts.dir = &dir;
|
setup_standard_excludes(&dir);
|
||||||
|
opts.dir = &dir;
|
||||||
|
}
|
||||||
|
|
||||||
opts.head_idx = 1;
|
opts.head_idx = 1;
|
||||||
opts.src_index = &the_index;
|
opts.src_index = &the_index;
|
||||||
|
|
Loading…
Reference in a new issue