Skip to content

Commit f8d627e

Browse files
committed
Merge branch 'sparse-index/merge' into vfs-2.33.0
Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
2 parents bd501df + f498339 commit f8d627e

File tree

5 files changed

+42
-1
lines changed

5 files changed

+42
-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;
@@ -118,6 +118,13 @@ static void clean_tracked_sparse_directories(struct repository *r)
118118
!r->index->sparse_checkout_patterns->use_cone_patterns)
119119
return;
120120

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

diff.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3901,6 +3901,13 @@ static int reuse_worktree_file(struct index_state *istate,
39013901
if (!FAST_WORKING_DIRECTORY && !want_file && has_object_pack(oid))
39023902
return 0;
39033903

3904+
/*
3905+
* If this path does not match our sparse-checkout definition,
3906+
* then the file will not be in the working directory.
3907+
*/
3908+
if (!path_in_sparse_checkout(name, istate))
3909+
return 0;
3910+
39043911
/*
39053912
* Similarly, if we'd have to convert the file contents anyway, that
39063913
* makes the optimization not worthwhile.

t/t1091-sparse-checkout-builtin.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,10 @@ test_expect_success 'cone mode clears ignored subdirectories' '
673673
git -C repo status --porcelain=v2 >out &&
674674
test_must_be_empty out &&
675675
676+
git -C repo -c index.deleteSparseDirectories=false sparse-checkout reapply &&
677+
test_path_is_dir repo/folder1 &&
678+
test_path_is_dir repo/deep/deeper2 &&
679+
676680
git -C repo sparse-checkout reapply &&
677681
test_path_is_missing repo/folder1 &&
678682
test_path_is_missing repo/deep/deeper2 &&

t/t1092-sparse-checkout-compatibility.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,23 @@ test_expect_success 'sparse-index is not expanded: merge conflict in cone' '
766766
)
767767
'
768768

769+
test_expect_success 'sparse-index is not expanded: merge conflict in cone' '
770+
init_repos &&
771+
772+
for side in right left
773+
do
774+
git -C sparse-index checkout -b expand-$side base &&
775+
echo $side >sparse-index/deep/a &&
776+
git -C sparse-index commit -a -m "$side" || return 1
777+
done &&
778+
779+
(
780+
sane_unset GIT_TEST_MERGE_ALGORITHM &&
781+
git -C sparse-index config pull.twohead ort &&
782+
ensure_not_expanded ! merge -m merged expand-right
783+
)
784+
'
785+
769786
# NEEDSWORK: a sparse-checkout behaves differently from a full checkout
770787
# in this scenario, but it shouldn't.
771788
test_expect_success 'reset mixed and checkout orphan' '

0 commit comments

Comments
 (0)