]> git.ipfire.org Git - thirdparty/git.git/commitdiff
sparse-checkout: disable advice in 'disable'
authorDerrick Stolee <stolee@gmail.com>
Mon, 23 Sep 2024 19:31:22 +0000 (19:31 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 23 Sep 2024 20:19:01 +0000 (13:19 -0700)
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>
builtin/sparse-checkout.c
sparse-index.c
sparse-index.h
t/t1092-sparse-checkout-compatibility.sh

index 2604ab04df5aee8046b7511587cb0c8cda768ddb..fe4f11390c915a0f5571ad08bb094ef95ddda2a5 100644 (file)
@@ -925,6 +925,11 @@ static int sparse_checkout_disable(int argc, const char **argv,
                             builtin_sparse_checkout_disable_options,
                             builtin_sparse_checkout_disable_usage, 0);
 
+       /*
+        * Disable the advice message for expanding a sparse index, as we
+        * are expecting to do that when disabling sparse-checkout.
+        */
+       give_advice_on_expansion = 0;
        repo_read_index(the_repository);
 
        memset(&pl, 0, sizeof(pl));
index 9958656ded1931fc6c293f02a7be255f6ecc855e..0f9fb4df026f0ffbd7d757d30cdc87c990543938 100644 (file)
  * advice for advice.sparseIndexExpanded when expanding a sparse index to a full
  * one. However, this is sometimes done on purpose, such as in the sparse-checkout
  * builtin, even when index.sparse=false. This may be disabled in
- * convert_to_sparse().
+ * convert_to_sparse() or by commands that know they will lead to a full
+ * expansion, but this message is not actionable.
  */
-static int give_advice_on_expansion = 1;
+int give_advice_on_expansion = 1;
 #define ADVICE_MSG \
        "The sparse index is expanding to a full index, a slow operation.\n"   \
        "Your working directory likely has contents that are outside of\n"     \
index a16f3e67d75913daffc7ded0e08118ca233d1f5d..727034be7ca917eff9d90ee564ba22c5754a6809 100644 (file)
@@ -1,6 +1,13 @@
 #ifndef SPARSE_INDEX_H__
 #define SPARSE_INDEX_H__
 
+/*
+ * If performing an operation where the index is supposed to expand to a
+ * full index, then disable the advice message by setting this global to
+ * zero.
+ */
+extern int give_advice_on_expansion;
+
 struct index_state;
 #define SPARSE_INDEX_MEMORY_ONLY (1 << 0)
 int is_sparse_index_allowed(struct index_state *istate, int flags);
index a2c0e1b4dcc56438853752c0b780f644ab3a646a..e3834b84013dd0037660cd4de654ac658b26470f 100755 (executable)
@@ -2342,7 +2342,10 @@ test_expect_success 'advice.sparseIndexExpanded' '
        mkdir -p sparse-index/deep/deeper2/deepest &&
        touch sparse-index/deep/deeper2/deepest/bogus &&
        git -C sparse-index status 2>err &&
-       grep "The sparse index is expanding to a full index" err
+       grep "The sparse index is expanding to a full index" err &&
+
+       git -C sparse-index sparse-checkout disable 2>err &&
+       test_line_count = 0 err
 '
 
 test_done