Skip to content

Commit 424f30a

Browse files
committed
Merge branch 'nd/ignore-might-be-precious'
* nd/ignore-might-be-precious: checkout,merge: disallow overwriting ignored files with --no-overwrite-ignore
2 parents b2dd021 + c1d7036 commit 424f30a

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

builtin/checkout.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ struct checkout_opts {
3434
int force_detach;
3535
int writeout_stage;
3636
int writeout_error;
37+
int overwrite_ignore;
3738

3839
/* not set by parse_options */
3940
int branch_exists;
@@ -409,9 +410,11 @@ static int merge_working_tree(struct checkout_opts *opts,
409410
topts.gently = opts->merge && old->commit;
410411
topts.verbose_update = !opts->quiet;
411412
topts.fn = twoway_merge;
412-
topts.dir = xcalloc(1, sizeof(*topts.dir));
413-
topts.dir->flags |= DIR_SHOW_IGNORED;
414-
setup_standard_excludes(topts.dir);
413+
if (opts->overwrite_ignore) {
414+
topts.dir = xcalloc(1, sizeof(*topts.dir));
415+
topts.dir->flags |= DIR_SHOW_IGNORED;
416+
setup_standard_excludes(topts.dir);
417+
}
415418
tree = parse_tree_indirect(old->commit ?
416419
old->commit->object.sha1 :
417420
EMPTY_TREE_SHA1_BIN);
@@ -934,6 +937,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
934937
3),
935938
OPT__FORCE(&opts.force, "force checkout (throw away local modifications)"),
936939
OPT_BOOLEAN('m', "merge", &opts.merge, "perform a 3-way merge with the new branch"),
940+
OPT_BOOLEAN(0, "overwrite-ignore", &opts.overwrite_ignore, "update ignored files (default)"),
937941
OPT_STRING(0, "conflict", &conflict_style, "style",
938942
"conflict style (merge or diff3)"),
939943
OPT_BOOLEAN('p', "patch", &patch_mode, "select hunks interactively"),
@@ -945,6 +949,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
945949

946950
memset(&opts, 0, sizeof(opts));
947951
memset(&new, 0, sizeof(new));
952+
opts.overwrite_ignore = 1;
948953

949954
gitmodules_config();
950955
git_config(git_checkout_config, &opts);

builtin/merge.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ static int show_diffstat = 1, shortlog_len = -1, squash;
4949
static int option_commit = 1, allow_fast_forward = 1;
5050
static int fast_forward_only, option_edit;
5151
static int allow_trivial = 1, have_message;
52+
static int overwrite_ignore = 1;
5253
static struct strbuf merge_msg;
5354
static struct commit_list *remoteheads;
5455
static struct strategy **use_strategies;
@@ -208,6 +209,7 @@ static struct option builtin_merge_options[] = {
208209
OPT_BOOLEAN(0, "abort", &abort_current_merge,
209210
"abort the current in-progress merge"),
210211
OPT_SET_INT(0, "progress", &show_progress, "force progress reporting", 1),
212+
OPT_BOOLEAN(0, "overwrite-ignore", &overwrite_ignore, "update ignored files (default)"),
211213
OPT_END()
212214
};
213215

@@ -766,10 +768,12 @@ int checkout_fast_forward(const unsigned char *head, const unsigned char *remote
766768
memset(&trees, 0, sizeof(trees));
767769
memset(&opts, 0, sizeof(opts));
768770
memset(&t, 0, sizeof(t));
769-
memset(&dir, 0, sizeof(dir));
770-
dir.flags |= DIR_SHOW_IGNORED;
771-
setup_standard_excludes(&dir);
772-
opts.dir = &dir;
771+
if (overwrite_ignore) {
772+
memset(&dir, 0, sizeof(dir));
773+
dir.flags |= DIR_SHOW_IGNORED;
774+
setup_standard_excludes(&dir);
775+
opts.dir = &dir;
776+
}
773777

774778
opts.head_idx = 1;
775779
opts.src_index = &the_index;

0 commit comments

Comments
 (0)