Skip to content

Commit 6adbbab

Browse files
committed
update-index: integrate with sparse index
Enable usage of the sparse index with `update-index`. Most variations of `update-index` work without explicitly expanding the index (due to the implicit expansion performed when attempting to find an existing entry). However, in order to prevent manually creating a sparse directory cache entry (current behavior is to throw an error when presented with a directory using `--cacheinfo`), the index is expanded before the the entry is added. Signed-off-by: Victoria Dye <[email protected]>
1 parent db6ed4f commit 6adbbab

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

builtin/update-index.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,10 @@ static int add_cacheinfo(unsigned int mode, const struct object_id *oid,
426426
ce->ce_flags |= CE_VALID;
427427
option = allow_add ? ADD_CACHE_OK_TO_ADD : 0;
428428
option |= allow_replace ? ADD_CACHE_OK_TO_REPLACE : 0;
429+
430+
/* TODO: ensure full index to maintain expected behavior */
431+
ensure_full_index(&the_index);
432+
429433
if (add_cache_entry(ce, option))
430434
return error("%s: cannot add to the index - missing --add option?",
431435
path);
@@ -1083,6 +1087,9 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
10831087

10841088
git_config(git_default_config, NULL);
10851089

1090+
prepare_repo_settings(r);
1091+
the_repository->settings.command_requires_full_index = 0;
1092+
10861093
/* we will diagnose later if it turns out that we need to update it */
10871094
newfd = hold_locked_index(&lock_file, 0);
10881095
if (newfd < 0)

t/t1092-sparse-checkout-compatibility.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,18 @@ test_expect_success 'sparse index is not expanded: sparse-checkout' '
10181018
ensure_not_expanded sparse-checkout set
10191019
'
10201020

1021+
test_expect_success 'sparse index is not expanded: update-index' '
1022+
init_repos &&
1023+
1024+
echo "test" >sparse-index/README.md &&
1025+
echo "test2" >sparse-index/a &&
1026+
rm -f sparse-index/deep/a &&
1027+
1028+
ensure_not_expanded update-index --add README.md &&
1029+
ensure_not_expanded update-index a &&
1030+
ensure_not_expanded update-index --remove deep/a &&
1031+
'
1032+
10211033
# NEEDSWORK: a sparse-checkout behaves differently from a full checkout
10221034
# in this scenario, but it shouldn't.
10231035
test_expect_success 'reset mixed and checkout orphan' '

0 commit comments

Comments
 (0)