Skip to content

Commit a133894

Browse files
derrickstoleedscho
authored andcommitted
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 4250d6d commit a133894

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
@@ -111,7 +111,7 @@ static int sparse_checkout_list(int argc, const char **argv, const char *prefix,
111111

112112
static void clean_tracked_sparse_directories(struct repository *r)
113113
{
114-
int i, was_full = 0;
114+
int i, value, was_full = 0;
115115
struct strbuf path = STRBUF_INIT;
116116
size_t pathlen;
117117
struct string_list_item *item;
@@ -127,6 +127,13 @@ static void clean_tracked_sparse_directories(struct repository *r)
127127
!r->index->sparse_checkout_patterns->use_cone_patterns)
128128
return;
129129

130+
/*
131+
* Users can disable this behavior.
132+
*/
133+
if (!repo_config_get_bool(r, "index.deletesparsedirectories", &value) &&
134+
!value)
135+
return;
136+
130137
/*
131138
* Use the sparse index as a data structure to assist finding
132139
* 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
@@ -783,6 +783,10 @@ test_expect_success 'cone mode clears ignored subdirectories' '
783783
git -C repo status --porcelain=v2 >out &&
784784
test_must_be_empty out &&
785785
786+
git -C repo -c index.deleteSparseDirectories=false sparse-checkout reapply &&
787+
test_path_is_dir repo/folder1 &&
788+
test_path_is_dir repo/deep/deeper2 &&
789+
786790
git -C repo sparse-checkout reapply &&
787791
test_path_is_missing repo/folder1 &&
788792
test_path_is_missing repo/deep/deeper2 &&

0 commit comments

Comments
 (0)