Skip to content

Commit f7f5c6c

Browse files
newrengitster
authored andcommitted
clean: consolidate handling of ignored parameters
I spent a long time trying to figure out how and whether the code worked with different values of ignore, ignore_only, and remove_directories. After lots of time setting up lots of testcases, sifting through lots of print statements, and walking through the debugger, I finally realized that one piece of code related to how it was all setup was found in clean.c rather than dir.c. Make a change that would have made it easier for me to do the extra testing by putting this handling in one spot. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 351ea1c commit f7f5c6c

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

builtin/clean.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -924,12 +924,6 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
924924
0);
925925

926926
memset(&dir, 0, sizeof(dir));
927-
if (ignored_only)
928-
dir.flags |= DIR_SHOW_IGNORED;
929-
930-
if (ignored && ignored_only)
931-
die(_("-x and -X cannot be used together"));
932-
933927
if (!interactive && !dry_run && !force) {
934928
if (config_set)
935929
die(_("clean.requireForce set to true and neither -i, -n, nor -f given; "
@@ -946,6 +940,13 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
946940

947941
dir.flags |= DIR_SHOW_OTHER_DIRECTORIES;
948942

943+
if (ignored && ignored_only)
944+
die(_("-x and -X cannot be used together"));
945+
if (!ignored)
946+
setup_standard_excludes(&dir);
947+
if (ignored_only)
948+
dir.flags |= DIR_SHOW_IGNORED;
949+
949950
if (argc) {
950951
/*
951952
* Remaining args implies pathspecs specified, and we should
@@ -960,9 +961,6 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
960961
if (read_cache() < 0)
961962
die(_("index file corrupt"));
962963

963-
if (!ignored)
964-
setup_standard_excludes(&dir);
965-
966964
pl = add_pattern_list(&dir, EXC_CMDL, "--exclude option");
967965
for (i = 0; i < exclude_list.nr; i++)
968966
add_pattern(exclude_list.items[i].string, "", 0, pl, -(i+1));

0 commit comments

Comments
 (0)