Skip to content

Commit 5d71940

Browse files
committed
Merge branch 'ds/advice-sparse-index-expansion'
A new warning message is issued when a command has to expand a sparse index to handle working tree cruft that are outside of the sparse checkout. * ds/advice-sparse-index-expansion: advice: warn when sparse index expands
2 parents f4c6a0e + 9479a31 commit 5d71940

File tree

5 files changed

+49
-1
lines changed

5 files changed

+49
-1
lines changed

Documentation/config/advice.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ advice.*::
116116
skippedCherryPicks::
117117
Shown when linkgit:git-rebase[1] skips a commit that has already
118118
been cherry-picked onto the upstream branch.
119+
sparseIndexExpanded::
120+
Shown when a sparse index is expanded to a full index, which is likely
121+
due to an unexpected set of files existing outside of the
122+
sparse-checkout.
119123
statusAheadBehind::
120124
Shown when linkgit:git-status[1] computes the ahead/behind
121125
counts for a local ref compared to its remote tracking ref,

advice.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ static struct {
7878
[ADVICE_SEQUENCER_IN_USE] = { "sequencerInUse" },
7979
[ADVICE_SET_UPSTREAM_FAILURE] = { "setUpstreamFailure" },
8080
[ADVICE_SKIPPED_CHERRY_PICKS] = { "skippedCherryPicks" },
81+
[ADVICE_SPARSE_INDEX_EXPANDED] = { "sparseIndexExpanded" },
8182
[ADVICE_STATUS_AHEAD_BEHIND_WARNING] = { "statusAheadBehindWarning" },
8283
[ADVICE_STATUS_HINTS] = { "statusHints" },
8384
[ADVICE_STATUS_U_OPTION] = { "statusUoption" },

advice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ enum advice_type {
4545
ADVICE_SEQUENCER_IN_USE,
4646
ADVICE_SET_UPSTREAM_FAILURE,
4747
ADVICE_SKIPPED_CHERRY_PICKS,
48+
ADVICE_SPARSE_INDEX_EXPANDED,
4849
ADVICE_STATUS_AHEAD_BEHIND_WARNING,
4950
ADVICE_STATUS_HINTS,
5051
ADVICE_STATUS_U_OPTION,

sparse-index.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,22 @@
1212
#include "config.h"
1313
#include "dir.h"
1414
#include "fsmonitor-ll.h"
15+
#include "advice.h"
16+
17+
/**
18+
* This global is used by expand_index() to determine if we should give the
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().
23+
*/
24+
static int give_advice_on_expansion = 1;
25+
#define ADVICE_MSG \
26+
"The sparse index is expanding to a full index, a slow operation.\n" \
27+
"Your working directory likely has contents that are outside of\n" \
28+
"your sparse-checkout patterns. Use 'git sparse-checkout list' to\n" \
29+
"see your sparse-checkout definition and compare it to your working\n" \
30+
"directory contents. Running 'git clean' may assist in this cleanup."
1531

1632
struct modify_index_context {
1733
struct index_state *write;
@@ -183,6 +199,12 @@ int convert_to_sparse(struct index_state *istate, int flags)
183199
!is_sparse_index_allowed(istate, flags))
184200
return 0;
185201

202+
/*
203+
* If we are purposefully collapsing a full index, then don't give
204+
* advice when it is expanded later.
205+
*/
206+
give_advice_on_expansion = 0;
207+
186208
/*
187209
* NEEDSWORK: If we have unmerged entries, then stay full.
188210
* Unmerged entries prevent the cache-tree extension from working.
@@ -328,6 +350,12 @@ void expand_index(struct index_state *istate, struct pattern_list *pl)
328350
pl = NULL;
329351
}
330352

353+
if (!pl && give_advice_on_expansion) {
354+
give_advice_on_expansion = 0;
355+
advise_if_enabled(ADVICE_SPARSE_INDEX_EXPANDED,
356+
_(ADVICE_MSG));
357+
}
358+
331359
/*
332360
* A NULL pattern set indicates we are expanding a full index, so
333361
* we use a special region name that indicates the full expansion.

t/t1092-sparse-checkout-compatibility.sh

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,10 @@ init_repos () {
159159
git -C sparse-checkout sparse-checkout set deep &&
160160
git -C sparse-index sparse-checkout init --cone --sparse-index &&
161161
test_cmp_config -C sparse-index true index.sparse &&
162-
git -C sparse-index sparse-checkout set deep
162+
git -C sparse-index sparse-checkout set deep &&
163+
164+
# Disable this message to keep stderr the same.
165+
git -C sparse-index config advice.sparseIndexExpanded false
163166
}
164167

165168
init_repos_as_submodules () {
@@ -2331,4 +2334,15 @@ test_expect_success 'sparse-index is not expanded: check-attr' '
23312334
ensure_not_expanded check-attr -a --cached -- folder1/a
23322335
'
23332336

2337+
test_expect_success 'advice.sparseIndexExpanded' '
2338+
init_repos &&
2339+
2340+
git -C sparse-index config --unset advice.sparseIndexExpanded &&
2341+
git -C sparse-index sparse-checkout set deep/deeper1 &&
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
2346+
'
2347+
23342348
test_done

0 commit comments

Comments
 (0)