| 917 | } |
| 918 | |
| 919 | int cmd_clean(int argc, |
| 920 | const char **argv, |
| 921 | const char *prefix, |
| 922 | struct repository *repo UNUSED) |
| 923 | { |
| 924 | int i, res; |
| 925 | int dry_run = 0, remove_directories = 0, quiet = 0, ignored = 0; |
| 926 | int ignored_only = 0, force = 0, errors = 0, gone = 1; |
| 927 | int rm_flags = REMOVE_DIR_KEEP_NESTED_GIT; |
| 928 | struct strbuf abs_path = STRBUF_INIT; |
| 929 | struct dir_struct dir = DIR_INIT; |
| 930 | struct pathspec pathspec; |
| 931 | struct strbuf buf = STRBUF_INIT; |
| 932 | struct string_list exclude_list = STRING_LIST_INIT_NODUP; |
| 933 | struct pattern_list *pl; |
| 934 | struct string_list_item *item; |
| 935 | const char *qname; |
| 936 | struct option options[] = { |
| 937 | OPT__QUIET(&quiet, N_("do not print names of files removed")), |
| 938 | OPT__DRY_RUN(&dry_run, N_("dry run")), |
| 939 | OPT__FORCE(&force, N_("force"), PARSE_OPT_NOCOMPLETE), |
| 940 | OPT_BOOL('i', "interactive", &interactive, N_("interactive cleaning")), |
| 941 | OPT_BOOL('d', NULL, &remove_directories, |
| 942 | N_("remove whole directories")), |
| 943 | OPT_CALLBACK_F('e', "exclude", &exclude_list, N_("pattern"), |
| 944 | N_("add <pattern> to ignore rules"), PARSE_OPT_NONEG, exclude_cb), |
| 945 | OPT_BOOL('x', NULL, &ignored, N_("remove ignored files, too")), |
| 946 | OPT_BOOL('X', NULL, &ignored_only, |
| 947 | N_("remove only ignored files")), |
| 948 | OPT_END() |
| 949 | }; |
| 950 | |
| 951 | repo_config(the_repository, git_clean_config, NULL); |
| 952 | |
| 953 | argc = parse_options(argc, argv, prefix, options, builtin_clean_usage, |
| 954 | 0); |
| 955 | |
| 956 | if (require_force != 0 && !force && !interactive && !dry_run) |
| 957 | die(_("clean.requireForce is true and -f not given: refusing to clean")); |
| 958 | |
| 959 | if (force > 1) |
| 960 | rm_flags = 0; |
| 961 | else |
| 962 | dir.flags |= DIR_SKIP_NESTED_GIT; |
| 963 | |
| 964 | dir.flags |= DIR_SHOW_OTHER_DIRECTORIES; |
| 965 | |
| 966 | if (ignored && ignored_only) |
| 967 | die(_("options '%s' and '%s' cannot be used together"), "-x", "-X"); |
| 968 | if (!ignored) |
| 969 | setup_standard_excludes(&dir); |
| 970 | if (ignored_only) |
| 971 | dir.flags |= DIR_SHOW_IGNORED; |
| 972 | |
| 973 | if (argc) { |
| 974 | /* |
| 975 | * Remaining args implies pathspecs specified, and we should |
| 976 | * recurse within those. |
nothing calls this directly
no test coverage detected