From: Clemens Buchacher Date: Sat, 21 Aug 2010 06:48:44 +0000 (+0200) Subject: checkout/merge: optionally fail operation when ignored files need to be overwritten X-Git-Tag: ko-pu~11^2 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=01bfbdca60577271c86addb86ff3f2701eef1882;p=git.git checkout/merge: optionally fail operation when ignored files need to be overwritten Signed-off-by: Clemens Buchacher Signed-off-by: Junio C Hamano --- diff --git a/Documentation/config.txt b/Documentation/config.txt index 5e86a28f9..fdaa586f0 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -450,6 +450,13 @@ core.excludesfile:: to the value of `$HOME` and "{tilde}user/" to the specified user's home directory. See linkgit:gitignore[5]. +core.ignoredareprecious:: + By default ignored (i.e. trashable) untracked files are + automatically removed from the working tree when they get in + the way of merge or switching between branches. This option + declares that such files are precious instead, and prevents + merges and checkouts from succeeding. + core.editor:: Commands such as `commit` and `tag` that lets you edit messages by launching an editor uses the value of this diff --git a/builtin/checkout.c b/builtin/checkout.c index 7f81120c7..cb83e6a63 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -392,9 +392,11 @@ static int merge_working_tree(struct checkout_opts *opts, topts.gently = opts->merge && old->commit; topts.verbose_update = !opts->quiet; topts.fn = twoway_merge; - topts.dir = xcalloc(1, sizeof(*topts.dir)); - topts.dir->flags |= DIR_SHOW_IGNORED; - topts.dir->exclude_per_dir = ".gitignore"; + if (!ignored_are_precious) { + topts.dir = xcalloc(1, sizeof(*topts.dir)); + topts.dir->flags |= DIR_SHOW_IGNORED; + topts.dir->exclude_per_dir = ".gitignore"; + } tree = parse_tree_indirect(old->commit ? old->commit->object.sha1 : (unsigned char *)EMPTY_TREE_SHA1_BIN); @@ -677,6 +679,8 @@ int cmd_checkout(int argc, const char **argv, const char *prefix) OPT_SET_INT('3', "theirs", &opts.writeout_stage, "stage", 3), OPT_BOOLEAN('f', "force", &opts.force, "force"), + OPT_BOOLEAN('i', "ignored-are-precious", &ignored_are_precious, + "fail when an ignored file needs to be overwritten"), OPT_BOOLEAN('m', "merge", &opts.merge, "merge"), OPT_STRING(0, "conflict", &conflict_style, "style", "conflict style (merge or diff3)"), diff --git a/builtin/merge.c b/builtin/merge.c index 37ce4f589..9ca7c5c72 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -185,6 +185,8 @@ static struct option builtin_merge_options[] = { "allow fast-forward (default)"), OPT_BOOLEAN(0, "ff-only", &fast_forward_only, "abort if fast-forward is not possible"), + OPT_BOOLEAN('i', "ignored-are-precious", &ignored_are_precious, + "fail when an ignored file needs to be overwritten"), OPT_RERERE_AUTOUPDATE(&allow_rerere_auto), OPT_CALLBACK('s', "strategy", &use_strategies, "strategy", "merge strategy to use", option_parse_strategy), @@ -693,9 +695,11 @@ int checkout_fast_forward(const unsigned char *head, const unsigned char *remote memset(&opts, 0, sizeof(opts)); memset(&t, 0, sizeof(t)); memset(&dir, 0, sizeof(dir)); - dir.flags |= DIR_SHOW_IGNORED; - dir.exclude_per_dir = ".gitignore"; - opts.dir = &dir; + if (!ignored_are_precious) { + dir.flags |= DIR_SHOW_IGNORED; + dir.exclude_per_dir = ".gitignore"; + opts.dir = &dir; + } opts.head_idx = 1; opts.src_index = &the_index; diff --git a/cache.h b/cache.h index 37ef9d8a0..cf5516faf 100644 --- a/cache.h +++ b/cache.h @@ -548,6 +548,7 @@ extern size_t packed_git_window_size; extern size_t packed_git_limit; extern size_t delta_base_cache_limit; extern int read_replace_refs; +extern int ignored_are_precious; extern int fsync_object_files; extern int core_preload_index; extern int core_apply_sparse_checkout; diff --git a/config.c b/config.c index cdcf5836c..c06b7f644 100644 --- a/config.c +++ b/config.c @@ -563,6 +563,11 @@ static int git_default_core_config(const char *var, const char *value) if (!strcmp(var, "core.excludesfile")) return git_config_pathname(&excludes_file, var, value); + if (!strcmp(var, "core.ignoredareprecious")) { + ignored_are_precious = git_config_bool(var, value); + return 0; + } + if (!strcmp(var, "core.whitespace")) { if (!value) return config_error_nonbool(var); diff --git a/environment.c b/environment.c index 83d38d3c2..0667c1f17 100644 --- a/environment.c +++ b/environment.c @@ -30,6 +30,7 @@ const char *apply_default_ignorewhitespace; int zlib_compression_level = Z_BEST_SPEED; int core_compression_level; int core_compression_seen; +int ignored_are_precious; int fsync_object_files; size_t packed_git_window_size = DEFAULT_PACKED_GIT_WINDOW_SIZE; size_t packed_git_limit = DEFAULT_PACKED_GIT_LIMIT;