Skip to content

Commit a75f27a

Browse files
vdyeldennington
authored andcommitted
Merge pull request microsoft#430 from vdye/sparse-index/clean
Sparse index: integrate with `clean` and `stash -u`
2 parents bcdd9df + ab9fe6d commit a75f27a

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

builtin/clean.c

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

1039+
prepare_repo_settings(the_repository);
1040+
the_repository->settings.command_requires_full_index = 0;
1041+
10391042
if (read_cache() < 0)
10401043
die(_("index file corrupt"));
10411044
enable_fscache(active_nr);

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
@@ -1223,23 +1223,42 @@ test_expect_success 'clean' '
12231223
test_all_match git commit -m "ignore bogus files" &&
12241224
12251225
run_on_sparse mkdir folder1 &&
1226+
run_on_all mkdir -p deep/untracked-deep &&
12261227
run_on_all touch folder1/bogus &&
1228+
run_on_all touch folder1/untracked &&
1229+
run_on_all touch deep/untracked-deep/bogus &&
1230+
run_on_all touch deep/untracked-deep/untracked &&
12271231
12281232
test_all_match git status --porcelain=v2 &&
12291233
test_all_match git clean -f &&
12301234
test_all_match git status --porcelain=v2 &&
12311235
test_sparse_match ls &&
12321236
test_sparse_match ls folder1 &&
1237+
run_on_all test_path_exists folder1/bogus &&
1238+
run_on_all test_path_is_missing folder1/untracked &&
1239+
run_on_all test_path_exists deep/untracked-deep/bogus &&
1240+
run_on_all test_path_exists deep/untracked-deep/untracked &&
1241+
1242+
test_all_match git clean -fd &&
1243+
test_all_match git status --porcelain=v2 &&
1244+
test_sparse_match ls &&
1245+
test_sparse_match ls folder1 &&
1246+
run_on_all test_path_exists folder1/bogus &&
1247+
run_on_all test_path_exists deep/untracked-deep/bogus &&
1248+
run_on_all test_path_is_missing deep/untracked-deep/untracked &&
12331249
12341250
test_all_match git clean -xf &&
12351251
test_all_match git status --porcelain=v2 &&
12361252
test_sparse_match ls &&
12371253
test_sparse_match ls folder1 &&
1254+
run_on_all test_path_is_missing folder1/bogus &&
1255+
run_on_all test_path_exists deep/untracked-deep/bogus &&
12381256
12391257
test_all_match git clean -xdf &&
12401258
test_all_match git status --porcelain=v2 &&
12411259
test_sparse_match ls &&
12421260
test_sparse_match ls folder1 &&
1261+
run_on_all test_path_is_missing deep/untracked-deep/bogus &&
12431262
12441263
test_sparse_match test_path_is_dir folder1
12451264
'
@@ -1405,6 +1424,8 @@ test_expect_success 'sparse-index is not expanded' '
14051424
git -C sparse-index add README.md &&
14061425
ensure_not_expanded diff --staged &&
14071426
1427+
ensure_not_expanded clean -fd &&
1428+
14081429
ensure_not_expanded reset base -- deep/a &&
14091430
ensure_not_expanded reset base -- nonexistent-file &&
14101431
ensure_not_expanded reset deepest -- deep &&
@@ -1674,6 +1695,46 @@ test_expect_success 'sparse index is not expanded: read-tree' '
16741695
ensure_not_expanded read-tree --prefix=deep/deeper2 -u deepest
16751696
'
16761697

1698+
# NEEDSWORK: although the full repository's index is _not_ expanded as part of
1699+
# stash, a temporary index, which is _not_ sparse, is created when stashing and
1700+
# applying a stash of untracked files. As a result, the test reports that it
1701+
# finds an instance of `ensure_full_index`, but it does not carry with it the
1702+
# performance implications of expanding the full repository index.
1703+
test_expect_success 'sparse index is not expanded: stash -u' '
1704+
init_repos &&
1705+
1706+
mkdir -p sparse-index/folder1 &&
1707+
echo >>sparse-index/README.md &&
1708+
echo >>sparse-index/a &&
1709+
echo >>sparse-index/folder1/new &&
1710+
1711+
GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \
1712+
git -C sparse-index stash -u &&
1713+
test_region index ensure_full_index trace2.txt &&
1714+
1715+
GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \
1716+
git -C sparse-index stash pop &&
1717+
test_region index ensure_full_index trace2.txt
1718+
'
1719+
1720+
# NEEDSWORK: similar to `git add`, untracked files outside of the sparse
1721+
# checkout definition are successfully stashed and unstashed.
1722+
test_expect_success 'stash -u outside sparse checkout definition' '
1723+
init_repos &&
1724+
1725+
write_script edit-contents <<-\EOF &&
1726+
echo text >>$1
1727+
EOF
1728+
1729+
run_on_sparse mkdir -p folder1 &&
1730+
run_on_all ../edit-contents folder1/new &&
1731+
test_all_match git stash -u &&
1732+
test_all_match git status --porcelain=v2 &&
1733+
1734+
test_all_match git stash pop -q &&
1735+
test_all_match git status --porcelain=v2
1736+
'
1737+
16771738
# NEEDSWORK: a sparse-checkout behaves differently from a full checkout
16781739
# in this scenario, but it shouldn't.
16791740
test_expect_success 'reset mixed and checkout orphan' '

0 commit comments

Comments
 (0)