]> git.ipfire.org Git - thirdparty/git.git/commitdiff
stash: integrate with sparse index
authorVictoria Dye <vdye@github.com>
Tue, 10 May 2022 23:32:28 +0000 (23:32 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 10 May 2022 23:45:12 +0000 (16:45 -0700)
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>
builtin/stash.c
t/t1092-sparse-checkout-compatibility.sh

index 0c7b6a95882d9405e3cdf4a8d3d2d251dc0588db..1bfba532044ba468b7eb36e122b2228c56a2581e 100644 (file)
@@ -1770,6 +1770,9 @@ int cmd_stash(int argc, const char **argv, const char *prefix)
        argc = parse_options(argc, argv, prefix, options, git_stash_usage,
                             PARSE_OPT_KEEP_UNKNOWN | PARSE_OPT_KEEP_DASHDASH);
 
+       prepare_repo_settings(the_repository);
+       the_repository->settings.command_requires_full_index = 0;
+
        index_file = get_index_file();
        strbuf_addf(&stash_index_path, "%s.stash.%" PRIuMAX, index_file,
                    (uintmax_t)pid);
index 86312b304444f1d14d2bb0ab5cdb5b6e466154c4..75d844cd71df8dad1cff66a9e87c06ccf1942536 100755 (executable)
@@ -1271,7 +1271,10 @@ test_expect_success 'index.sparse disabled inline uses full index' '
 
 ensure_not_expanded () {
        rm -f trace2.txt &&
-       echo >>sparse-index/untracked.txt &&
+       if test -z "$WITHOUT_UNTRACKED_TXT"
+       then
+               echo >>sparse-index/untracked.txt
+       fi &&
 
        if test "$1" = "!"
        then
@@ -1375,6 +1378,30 @@ test_expect_success 'sparse-index is not expanded: merge conflict in cone' '
        )
 '
 
+test_expect_success 'sparse-index is not expanded: stash' '
+       init_repos &&
+
+       echo >>sparse-index/a &&
+       ensure_not_expanded stash &&
+       ensure_not_expanded stash list &&
+       ensure_not_expanded stash show stash@{0} &&
+       ! ensure_not_expanded stash apply stash@{0} &&
+       ensure_not_expanded stash drop stash@{0} &&
+
+       echo >>sparse-index/deep/new &&
+       ! ensure_not_expanded stash -u &&
+       (
+               WITHOUT_UNTRACKED_TXT=1 &&
+               ! ensure_not_expanded stash pop
+       ) &&
+
+       ensure_not_expanded stash create &&
+       oid=$(git -C sparse-index stash create) &&
+       ensure_not_expanded stash store -m "test" $oid &&
+       ensure_not_expanded reset --hard &&
+       ! ensure_not_expanded stash pop
+'
+
 test_expect_success 'sparse index is not expanded: diff' '
        init_repos &&