if (!include_untracked && ps->nr) {
char *ps_matched = xcalloc(ps->nr, 1);
- /* TODO: audit for interaction with sparse-index. */
- ensure_full_index(the_repository->index);
+ if (pathspec_needs_expanded_index(the_repository->index, ps))
+ ensure_full_index(the_repository->index);
for (size_t i = 0; i < the_repository->index->cache_nr; i++)
ce_path_match(the_repository->index, the_repository->index->cache[i], ps,
ps_matched);
ensure_not_expanded stash pop
'
+test_expect_success 'sparse-index is not expanded: stash in-cone pathspec' '
+ init_repos &&
+
+ echo unrelated >>sparse-index/deep/e &&
+ echo literal >>sparse-index/deep/a &&
+ ensure_not_expanded stash push -- deep/a &&
+ test_grep ! literal sparse-index/deep/a &&
+ test_grep unrelated sparse-index/deep/e &&
+ ensure_not_expanded stash pop &&
+ test_grep literal sparse-index/deep/a &&
+
+ echo prefixed >>sparse-index/deep/a &&
+ ensure_not_expanded -C deep stash push -- a &&
+ test_grep ! prefixed sparse-index/deep/a &&
+ test_grep unrelated sparse-index/deep/e &&
+ ensure_not_expanded stash pop &&
+ test_grep prefixed sparse-index/deep/a &&
+
+ echo wildcard >>sparse-index/deep/a &&
+ ensure_not_expanded stash push -- "deep/a*" &&
+ test_grep ! wildcard sparse-index/deep/a &&
+ test_grep unrelated sparse-index/deep/e &&
+ ensure_not_expanded stash pop &&
+ test_grep wildcard sparse-index/deep/a &&
+
+ echo pathspec-file >>sparse-index/deep/a &&
+ echo deep/a >pathspec-file &&
+ ensure_not_expanded stash push --pathspec-from-file=../pathspec-file &&
+ test_grep ! pathspec-file sparse-index/deep/a &&
+ test_grep unrelated sparse-index/deep/e &&
+ ensure_not_expanded stash pop &&
+ test_grep pathspec-file sparse-index/deep/a &&
+
+ echo multiple-a >>sparse-index/deep/a &&
+ echo multiple-e >>sparse-index/deep/e &&
+ ensure_not_expanded stash push -- deep/a deep/e &&
+ test_grep ! multiple-a sparse-index/deep/a &&
+ test_grep ! multiple-e sparse-index/deep/e &&
+ ensure_not_expanded stash pop &&
+ test_grep multiple-a sparse-index/deep/a &&
+ test_grep multiple-e sparse-index/deep/e &&
+
+ echo staged >>sparse-index/deep/a &&
+ git -C sparse-index add deep/a &&
+ ensure_not_expanded stash push --staged -- deep/a &&
+ test_grep ! staged sparse-index/deep/a &&
+ test_grep unrelated sparse-index/deep/e &&
+ ensure_not_expanded stash pop --index &&
+ test_grep staged sparse-index/deep/a &&
+ test_must_fail git -C sparse-index diff --cached --quiet -- deep/a &&
+
+ ensure_not_expanded ! stash push -- deep/does-not-exist &&
+ test_grep "did not match any file" sparse-index-error
+'
+
test_expect_success 'describe tested on all' '
init_repos &&