Skip to content

Commit fb47b56

Browse files
committed
sparse-checkout: add config to disable deleting dirs
The clean_tracked_sparse_directories() method deletes the tracked directories that go out of scope when the sparse-checkout cone changes, at least in cone mode. This is new behavior, but is recommended based on our understanding of how users are interacting with the feature in most cases. It is possible that some users will object to the new behavior, so create a new configuration option 'index.deleteSparseDirectories' that can be set to 'false' to make clean_tracked_sparse_directories() do nothing. This will keep all untracked files in the working tree and cause performance problems with the sparse index, but those trade-offs are for the user to decide. Signed-off-by: Derrick Stolee <[email protected]>
1 parent 3a2f316 commit fb47b56

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

Documentation/config/index.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
index.deleteSparseDirectories::
2+
When enabled, the cone mode sparse-checkout feature will delete
3+
directories that are outside of the sparse-checkout cone, unless
4+
such a directory contains an untracked, non-ignored file. Defaults
5+
to true.
6+
17
index.recordEndOfIndexEntries::
28
Specifies whether the index file should include an "End Of Index
39
Entry" section. This reduces index load time on multiprocessor

builtin/sparse-checkout.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ static int sparse_checkout_list(int argc, const char **argv)
102102

103103
static void clean_tracked_sparse_directories(struct repository *r)
104104
{
105-
int i, was_full = 0;
105+
int i, value, was_full = 0;
106106
struct strbuf path = STRBUF_INIT;
107107
size_t pathlen;
108108
struct string_list_item *item;
@@ -119,6 +119,13 @@ static void clean_tracked_sparse_directories(struct repository *r)
119119
!r->index->sparse_checkout_patterns->use_cone_patterns)
120120
return;
121121

122+
/*
123+
* Users can disable this behavior.
124+
*/
125+
if (!repo_config_get_bool(r, "index.deletesparsedirectories", &value) &&
126+
!value)
127+
return;
128+
122129
/*
123130
* Use the sparse index as a data structure to assist finding
124131
* directories that are safe to delete. This conversion to a

t/t1091-sparse-checkout-builtin.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,10 @@ test_expect_success 'cone mode clears ignored subdirectories' '
666666
git -C repo status --porcelain=v2 >out &&
667667
test_must_be_empty out &&
668668
669+
git -C repo -c index.deleteSparseDirectories=false sparse-checkout reapply &&
670+
test_path_is_dir repo/folder1 &&
671+
test_path_is_dir repo/deep/deeper2 &&
672+
669673
git -C repo sparse-checkout reapply &&
670674
test_path_is_missing repo/folder1 &&
671675
test_path_is_missing repo/deep/deeper2 &&

0 commit comments

Comments
 (0)