aboutsummaryrefslogtreecommitdiff
path: root/builtin-clean.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2009-06-30 15:33:45 -0700
committerJunio C Hamano <gitster@pobox.com>2009-07-29 12:22:30 -0700
commita0f4afbe87ddda7902e36350d163dea146166550 (patch)
tree9c90142f461b86ef045d672793b95f135be1970f /builtin-clean.c
parent0a53e9ddeaddad63ad106860237bbf53411d11a7 (diff)
downloadgit-a0f4afbe87ddda7902e36350d163dea146166550.tar.gz
git-a0f4afbe87ddda7902e36350d163dea146166550.tar.xz
clean: require double -f options to nuke nested git repository and work tree
When you have an embedded git work tree in your work tree (be it an orphaned submodule, or an independent checkout of an unrelated project), "git clean -d -f" blindly descended into it and removed everything. This is rarely what the user wants. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin-clean.c')
-rw-r--r--builtin-clean.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/builtin-clean.c b/builtin-clean.c
index 2d8c735d4..05c763cbe 100644
--- a/builtin-clean.c
+++ b/builtin-clean.c
@@ -31,6 +31,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
int i;
int show_only = 0, remove_directories = 0, quiet = 0, ignored = 0;
int ignored_only = 0, baselen = 0, config_set = 0, errors = 0;
+ int rm_flags = REMOVE_DIR_KEEP_NESTED_GIT;
struct strbuf directory = STRBUF_INIT;
struct dir_struct dir;
static const char **pathspec;
@@ -69,6 +70,9 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
die("clean.requireForce%s set and -n or -f not given; "
"refusing to clean", config_set ? "" : " not");
+ if (force > 1)
+ rm_flags = 0;
+
dir.flags |= DIR_SHOW_OTHER_DIRECTORIES;
if (!ignored)
@@ -131,7 +135,8 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
(matches == MATCHED_EXACTLY)) {
if (!quiet)
printf("Removing %s\n", qname);
- if (remove_dir_recursively(&directory, 0) != 0) {
+ if (remove_dir_recursively(&directory,
+ rm_flags) != 0) {
warning("failed to remove '%s'", qname);
errors++;
}