sparse-checkout: disable advice in 'disable'

When running 'git sparse-checkout disable' with the sparse index enabled, Git is expected to expand the index into a full index. However, it currently outputs the advice message saying that that is unexpected and likely due to an issue with the working directory. Disable this advice message when in this code path. Establish a pattern for doing a similar removal in the future. Signed-off-by: Derrick Stolee <stolee@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Sep 23, 2024 at 19:31 UTC 537e516a39a760fddc4f3f5020c4118943f6c146
4 files changed +19 -3
builtin/sparse-checkout.c
+5
@@ -925,6 +925,11 @@ static int sparse_checkout_disable(int argc, const char **argv,
925 builtin_sparse_checkout_disable_options,
926 builtin_sparse_checkout_disable_usage, 0);
927
928 + /*
929 + * Disable the advice message for expanding a sparse index, as we
930 + * are expecting to do that when disabling sparse-checkout.
931 + */
932 + give_advice_on_expansion = 0;
933 repo_read_index(the_repository);
934
935 memset(&pl, 0, sizeof(pl));
sparse-index.c
+3 -2
@@ -19,9 +19,10 @@
19 * advice for advice.sparseIndexExpanded when expanding a sparse index to a full
20 * one. However, this is sometimes done on purpose, such as in the sparse-checkout
21 * builtin, even when index.sparse=false. This may be disabled in
22 - * convert_to_sparse().
22 + * convert_to_sparse() or by commands that know they will lead to a full
23 + * expansion, but this message is not actionable.
24 */
24 -static int give_advice_on_expansion = 1;
25 +int give_advice_on_expansion = 1;
26 #define ADVICE_MSG \
27 "The sparse index is expanding to a full index, a slow operation.\n" \
28 "Your working directory likely has contents that are outside of\n" \
sparse-index.h
+7
@@ -1,6 +1,13 @@
1 #ifndef SPARSE_INDEX_H__
2 #define SPARSE_INDEX_H__
3
4 +/*
5 + * If performing an operation where the index is supposed to expand to a
6 + * full index, then disable the advice message by setting this global to
7 + * zero.
8 + */
9 +extern int give_advice_on_expansion;
10 +
11 struct index_state;
12 #define SPARSE_INDEX_MEMORY_ONLY (1 << 0)
13 int is_sparse_index_allowed(struct index_state *istate, int flags);
t/t1092-sparse-checkout-compatibility.sh
+4 -1
@@ -2342,7 +2342,10 @@ test_expect_success 'advice.sparseIndexExpanded' '
2342 mkdir -p sparse-index/deep/deeper2/deepest &&
2343 touch sparse-index/deep/deeper2/deepest/bogus &&
2344 git -C sparse-index status 2>err &&
2345 - grep "The sparse index is expanding to a full index" err
2345 + grep "The sparse index is expanding to a full index" err &&
2346 +
2347 + git -C sparse-index sparse-checkout disable 2>err &&
2348 + test_line_count = 0 err
2349 '
2350
2351 test_done