aboutsummaryrefslogtreecommitdiffstats
path: root/builtin/sparse-checkout.c
diff options
context:
space:
mode:
authorDerrick Stolee <stolee@gmail.com>2025-09-12 10:30:09 +0000
committerJunio C Hamano <gitster@pobox.com>2025-09-15 12:10:56 -0700
commit5b5a7f5ebd2e2701ac6fa522866f22b885147c01 (patch)
tree8246439b3f1b89c4a94c63ad61dc6110ea83ea77 /builtin/sparse-checkout.c
parentdir: add generic "walk all files" helper (diff)
downloadgit-5b5a7f5ebd2e2701ac6fa522866f22b885147c01.tar.gz
git-5b5a7f5ebd2e2701ac6fa522866f22b885147c01.zip
sparse-checkout: add --verbose option to 'clean'
The 'git sparse-checkout clean' subcommand is focused on directories, deleting any tracked sparse directories to clean up the worktree and make the sparse index feature work optimally. However, this directory-focused approach can leave users wondering why those directories exist at all. In my experience, these files are left over due to ignore or exclude patterns, Windows file handles, or possibly merge conflict resolutions. Add a new '--verbose' option for users to see all the files that are being deleted (with '--force') or would be deleted (with '--dry-run'). Based on usage, users may request further context on this list of files for states such as tracked/untracked, unstaged/staged/conflicted, etc. Signed-off-by: Derrick Stolee <stolee@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/sparse-checkout.c')
-rw-r--r--builtin/sparse-checkout.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c
index d777b64960..15d51e60a8 100644
--- a/builtin/sparse-checkout.c
+++ b/builtin/sparse-checkout.c
@@ -930,6 +930,24 @@ static char const * const builtin_sparse_checkout_clean_usage[] = {
NULL
};
+static int list_file_iterator(const char *path, const void *data)
+{
+ const char *msg = data;
+
+ printf(msg, path);
+ return 0;
+}
+
+static void list_every_file_in_dir(const char *msg,
+ const char *directory)
+{
+ struct strbuf path = STRBUF_INIT;
+
+ strbuf_addstr(&path, directory);
+ for_each_file_in_dir(&path, list_file_iterator, msg);
+ strbuf_release(&path);
+}
+
static const char *msg_remove = N_("Removing %s\n");
static const char *msg_would_remove = N_("Would remove %s\n");
@@ -940,12 +958,13 @@ static int sparse_checkout_clean(int argc, const char **argv,
struct strbuf full_path = STRBUF_INIT;
const char *msg = msg_remove;
size_t worktree_len;
- int force = 0, dry_run = 0;
+ int force = 0, dry_run = 0, verbose = 0;
int require_force = 1;
struct option builtin_sparse_checkout_clean_options[] = {
OPT__DRY_RUN(&dry_run, N_("dry run")),
OPT__FORCE(&force, N_("force"), PARSE_OPT_NOCOMPLETE),
+ OPT__VERBOSE(&verbose, N_("report each affected file, not just directories")),
OPT_END(),
};
@@ -987,7 +1006,10 @@ static int sparse_checkout_clean(int argc, const char **argv,
if (!is_directory(full_path.buf))
continue;
- printf(msg, ce->name);
+ if (verbose)
+ list_every_file_in_dir(msg, ce->name);
+ else
+ printf(msg, ce->name);
if (dry_run <= 0 &&
remove_dir_recursively(&full_path, 0))