Skip to content

Commit 537e516

Browse files
derrickstoleegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4f71522 commit 537e516

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

builtin/sparse-checkout.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,11 @@ static int sparse_checkout_disable(int argc, const char **argv,
925925
builtin_sparse_checkout_disable_options,
926926
builtin_sparse_checkout_disable_usage, 0);
927927

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;
928933
repo_read_index(the_repository);
929934

930935
memset(&pl, 0, sizeof(pl));

sparse-index.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
* advice for advice.sparseIndexExpanded when expanding a sparse index to a full
2020
* one. However, this is sometimes done on purpose, such as in the sparse-checkout
2121
* 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.
2324
*/
24-
static int give_advice_on_expansion = 1;
25+
int give_advice_on_expansion = 1;
2526
#define ADVICE_MSG \
2627
"The sparse index is expanding to a full index, a slow operation.\n" \
2728
"Your working directory likely has contents that are outside of\n" \

sparse-index.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
#ifndef SPARSE_INDEX_H__
22
#define SPARSE_INDEX_H__
33

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+
411
struct index_state;
512
#define SPARSE_INDEX_MEMORY_ONLY (1 << 0)
613
int is_sparse_index_allowed(struct index_state *istate, int flags);

t/t1092-sparse-checkout-compatibility.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2342,7 +2342,10 @@ test_expect_success 'advice.sparseIndexExpanded' '
23422342
mkdir -p sparse-index/deep/deeper2/deepest &&
23432343
touch sparse-index/deep/deeper2/deepest/bogus &&
23442344
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
23462349
'
23472350

23482351
test_done

0 commit comments

Comments
 (0)