Skip to content

Commit 066124d

Browse files
committed
Merge branch 'so/clean-dry-run-without-force'
The implementation in "git clean" that makes "-n" and "-i" ignore clean.requireForce has been simplified, together with the documentation. * so/clean-dry-run-without-force: clean: further clean-up of implementation around "--force" clean: improve -n and -f implementation and documentation
2 parents 9451150 + 105ec9a commit 066124d

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

Documentation/config/clean.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
clean.requireForce::
2-
A boolean to make git-clean do nothing unless given -f,
3-
-i, or -n. Defaults to true.
2+
A boolean to make git-clean refuse to delete files unless -f
3+
is given. Defaults to true.

Documentation/git-clean.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,22 @@ OPTIONS
3737
--force::
3838
If the Git configuration variable clean.requireForce is not set
3939
to false, 'git clean' will refuse to delete files or directories
40-
unless given -f or -i. Git will refuse to modify untracked
40+
unless given -f. Git will refuse to modify untracked
4141
nested git repositories (directories with a .git subdirectory)
4242
unless a second -f is given.
4343

4444
-i::
4545
--interactive::
4646
Show what would be done and clean files interactively. See
4747
``Interactive mode'' for details.
48+
Configuration variable `clean.requireForce` is ignored, as
49+
this mode gives its own safety protection by going interactive.
4850

4951
-n::
5052
--dry-run::
5153
Don't actually remove anything, just show what would be done.
54+
Configuration variable `clean.requireForce` is ignored, as
55+
nothing will be deleted anyway.
5256

5357
-q::
5458
--quiet::

builtin/clean.c

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include "help.h"
2626
#include "prompt.h"
2727

28-
static int force = -1; /* unset */
28+
static int require_force = -1; /* unset */
2929
static int interactive;
3030
static struct string_list del_list = STRING_LIST_INIT_DUP;
3131
static unsigned int colopts;
@@ -128,7 +128,7 @@ static int git_clean_config(const char *var, const char *value,
128128
}
129129

130130
if (!strcmp(var, "clean.requireforce")) {
131-
force = !git_config_bool(var, value);
131+
require_force = git_config_bool(var, value);
132132
return 0;
133133
}
134134

@@ -920,7 +920,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
920920
{
921921
int i, res;
922922
int dry_run = 0, remove_directories = 0, quiet = 0, ignored = 0;
923-
int ignored_only = 0, config_set = 0, errors = 0, gone = 1;
923+
int ignored_only = 0, force = 0, errors = 0, gone = 1;
924924
int rm_flags = REMOVE_DIR_KEEP_NESTED_GIT;
925925
struct strbuf abs_path = STRBUF_INIT;
926926
struct dir_struct dir = DIR_INIT;
@@ -946,22 +946,12 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
946946
};
947947

948948
git_config(git_clean_config, NULL);
949-
if (force < 0)
950-
force = 0;
951-
else
952-
config_set = 1;
953949

954950
argc = parse_options(argc, argv, prefix, options, builtin_clean_usage,
955951
0);
956952

957-
if (!interactive && !dry_run && !force) {
958-
if (config_set)
959-
die(_("clean.requireForce set to true and neither -i, -n, nor -f given; "
960-
"refusing to clean"));
961-
else
962-
die(_("clean.requireForce defaults to true and neither -i, -n, nor -f given;"
963-
" refusing to clean"));
964-
}
953+
if (require_force != 0 && !force && !interactive && !dry_run)
954+
die(_("clean.requireForce is true and -f not given: refusing to clean"));
965955

966956
if (force > 1)
967957
rm_flags = 0;

t/t7300-clean.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,12 @@ test_expect_success 'clean.requireForce and -f' '
407407
408408
'
409409

410+
test_expect_success 'clean.requireForce and --interactive' '
411+
git clean --interactive </dev/null >output 2>error &&
412+
test_grep ! "requireForce is true and" error &&
413+
test_grep "\*\*\* Commands \*\*\*" output
414+
'
415+
410416
test_expect_success 'core.excludesfile' '
411417
412418
echo excludes >excludes &&

0 commit comments

Comments
 (0)