Skip to content

Commit 7db06bd

Browse files
authored
Merge pull request #430 from vdye/sparse-index/clean
Sparse index: integrate with `clean` and `stash -u`
2 parents f2bf729 + 0c06339 commit 7db06bd

File tree

4 files changed

+66
-1
lines changed

4 files changed

+66
-1
lines changed

builtin/clean.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,9 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
10101010
dir.flags |= DIR_KEEP_UNTRACKED_CONTENTS;
10111011
}
10121012

1013+
prepare_repo_settings(the_repository);
1014+
the_repository->settings.command_requires_full_index = 0;
1015+
10131016
if (read_cache() < 0)
10141017
die(_("index file corrupt"));
10151018
enable_fscache(active_nr);

builtin/stash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ static int restore_untracked(struct object_id *u_tree)
350350

351351
child_process_init(&cp);
352352
cp.git_cmd = 1;
353-
strvec_pushl(&cp.args, "checkout-index", "--all", NULL);
353+
strvec_pushl(&cp.args, "checkout-index", "--all", "--sparse", NULL);
354354
strvec_pushf(&cp.env_array, "GIT_INDEX_FILE=%s",
355355
stash_index_path.buf);
356356

t/perf/p2000-sparse-operations.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ test_perf_on_all () {
107107

108108
test_perf_on_all git status
109109
test_perf_on_all 'git stash && git stash pop'
110+
test_perf_on_all 'echo >>new && git stash -u && git stash pop'
110111
test_perf_on_all git add -A
111112
test_perf_on_all git add .
112113
test_perf_on_all git commit -a -m A

t/t1092-sparse-checkout-compatibility.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,23 +1068,42 @@ test_expect_success 'clean' '
10681068
test_all_match git commit -m "ignore bogus files" &&
10691069
10701070
run_on_sparse mkdir folder1 &&
1071+
run_on_all mkdir -p deep/untracked-deep &&
10711072
run_on_all touch folder1/bogus &&
1073+
run_on_all touch folder1/untracked &&
1074+
run_on_all touch deep/untracked-deep/bogus &&
1075+
run_on_all touch deep/untracked-deep/untracked &&
10721076
10731077
test_all_match git status --porcelain=v2 &&
10741078
test_all_match git clean -f &&
10751079
test_all_match git status --porcelain=v2 &&
10761080
test_sparse_match ls &&
10771081
test_sparse_match ls folder1 &&
1082+
run_on_all test_path_exists folder1/bogus &&
1083+
run_on_all test_path_is_missing folder1/untracked &&
1084+
run_on_all test_path_exists deep/untracked-deep/bogus &&
1085+
run_on_all test_path_exists deep/untracked-deep/untracked &&
1086+
1087+
test_all_match git clean -fd &&
1088+
test_all_match git status --porcelain=v2 &&
1089+
test_sparse_match ls &&
1090+
test_sparse_match ls folder1 &&
1091+
run_on_all test_path_exists folder1/bogus &&
1092+
run_on_all test_path_exists deep/untracked-deep/bogus &&
1093+
run_on_all test_path_is_missing deep/untracked-deep/untracked &&
10781094
10791095
test_all_match git clean -xf &&
10801096
test_all_match git status --porcelain=v2 &&
10811097
test_sparse_match ls &&
10821098
test_sparse_match ls folder1 &&
1099+
run_on_all test_path_is_missing folder1/bogus &&
1100+
run_on_all test_path_exists deep/untracked-deep/bogus &&
10831101
10841102
test_all_match git clean -xdf &&
10851103
test_all_match git status --porcelain=v2 &&
10861104
test_sparse_match ls &&
10871105
test_sparse_match ls folder1 &&
1106+
run_on_all test_path_is_missing deep/untracked-deep/bogus &&
10881107
10891108
test_sparse_match test_path_is_dir folder1
10901109
'
@@ -1202,6 +1221,8 @@ test_expect_success 'sparse-index is not expanded' '
12021221
git -C sparse-index add README.md &&
12031222
ensure_not_expanded diff --staged &&
12041223
1224+
ensure_not_expanded clean -fd &&
1225+
12051226
ensure_not_expanded checkout -f update-deep &&
12061227
(
12071228
sane_unset GIT_TEST_MERGE_ALGORITHM &&
@@ -1280,6 +1301,46 @@ test_expect_success 'sparse index is not expanded: read-tree' '
12801301
ensure_not_expanded read-tree --prefix=deep/deeper2 -u deepest
12811302
'
12821303

1304+
# NEEDSWORK: although the full repository's index is _not_ expanded as part of
1305+
# stash, a temporary index, which is _not_ sparse, is created when stashing and
1306+
# applying a stash of untracked files. As a result, the test reports that it
1307+
# finds an instance of `ensure_full_index`, but it does not carry with it the
1308+
# performance implications of expanding the full repository index.
1309+
test_expect_success 'sparse index is not expanded: stash -u' '
1310+
init_repos &&
1311+
1312+
mkdir -p sparse-index/folder1 &&
1313+
echo >>sparse-index/README.md &&
1314+
echo >>sparse-index/a &&
1315+
echo >>sparse-index/folder1/new &&
1316+
1317+
GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \
1318+
git -C sparse-index stash -u &&
1319+
test_region index ensure_full_index trace2.txt &&
1320+
1321+
GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \
1322+
git -C sparse-index stash pop &&
1323+
test_region index ensure_full_index trace2.txt
1324+
'
1325+
1326+
# NEEDSWORK: similar to `git add`, untracked files outside of the sparse
1327+
# checkout definition are successfully stashed and unstashed.
1328+
test_expect_success 'stash -u outside sparse checkout definition' '
1329+
init_repos &&
1330+
1331+
write_script edit-contents <<-\EOF &&
1332+
echo text >>$1
1333+
EOF
1334+
1335+
run_on_sparse mkdir -p folder1 &&
1336+
run_on_all ../edit-contents folder1/new &&
1337+
test_all_match git stash -u &&
1338+
test_all_match git status --porcelain=v2 &&
1339+
1340+
test_all_match git stash pop -q &&
1341+
test_all_match git status --porcelain=v2
1342+
'
1343+
12831344
# NEEDSWORK: a sparse-checkout behaves differently from a full checkout
12841345
# in this scenario, but it shouldn't.
12851346
test_expect_success 'reset mixed and checkout orphan' '

0 commit comments

Comments
 (0)