stash: integrate with sparse index

Enable sparse index in 'git stash' by disabling 'command_requires_full_index'. With sparse index enabled, some subcommands of 'stash' work without expanding the index, e.g., 'git stash', 'git stash list', 'git stash drop', etc. Others ensure the index is expanded either directly (as in the case of 'git stash [pop|apply]', where the call to 'merge_recursive_generic()' in 'do_apply_stash()' triggers the expansion), or in a command called internally by stash (e.g., 'git update-index' in 'git stash -u'). So, in addition to enabling sparse index, add tests to 't1092' demonstrating which variants of 'git stash' expand the index, and which do not. Finally, add the option to skip writing 'untracked.txt' in 'ensure_not_expanded', and use that option to successfully apply stashed untracked files without a conflict in 'untracked.txt'. Signed-off-by: Victoria Dye <vdye@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Victoria Dye committed May 10, 2022 at 23:32 UTC 3a58792adece081ee84e9827c4d90daf759ceb76
2 files changed +31 -1
builtin/stash.c
+3
@@ -1770,6 +1770,9 @@ int cmd_stash(int argc, const char **argv, const char *prefix)
1770 argc = parse_options(argc, argv, prefix, options, git_stash_usage,
1771 PARSE_OPT_KEEP_UNKNOWN | PARSE_OPT_KEEP_DASHDASH);
1772
1773 + prepare_repo_settings(the_repository);
1774 + the_repository->settings.command_requires_full_index = 0;
1775 +
1776 index_file = get_index_file();
1777 strbuf_addf(&stash_index_path, "%s.stash.%" PRIuMAX, index_file,
1778 (uintmax_t)pid);
t/t1092-sparse-checkout-compatibility.sh
+28 -1
@@ -1271,7 +1271,10 @@ test_expect_success 'index.sparse disabled inline uses full index' '
1271
1272 ensure_not_expanded () {
1273 rm -f trace2.txt &&
1274 - echo >>sparse-index/untracked.txt &&
1274 + if test -z "$WITHOUT_UNTRACKED_TXT"
1275 + then
1276 + echo >>sparse-index/untracked.txt
1277 + fi &&
1278
1279 if test "$1" = "!"
1280 then
@@ -1375,6 +1378,30 @@ test_expect_success 'sparse-index is not expanded: merge conflict in cone' '
1378 )
1379 '
1380
1381 +test_expect_success 'sparse-index is not expanded: stash' '
1382 + init_repos &&
1383 +
1384 + echo >>sparse-index/a &&
1385 + ensure_not_expanded stash &&
1386 + ensure_not_expanded stash list &&
1387 + ensure_not_expanded stash show stash@{0} &&
1388 + ! ensure_not_expanded stash apply stash@{0} &&
1389 + ensure_not_expanded stash drop stash@{0} &&
1390 +
1391 + echo >>sparse-index/deep/new &&
1392 + ! ensure_not_expanded stash -u &&
1393 + (
1394 + WITHOUT_UNTRACKED_TXT=1 &&
1395 + ! ensure_not_expanded stash pop
1396 + ) &&
1397 +
1398 + ensure_not_expanded stash create &&
1399 + oid=$(git -C sparse-index stash create) &&
1400 + ensure_not_expanded stash store -m "test" $oid &&
1401 + ensure_not_expanded reset --hard &&
1402 + ! ensure_not_expanded stash pop
1403 +'
1404 +
1405 test_expect_success 'sparse index is not expanded: diff' '
1406 init_repos &&
1407