@@ -661,6 +661,11 @@ int cmd_show(int argc, const char **argv, const char *prefix)
init_log_defaults();
git_config(git_log_config, NULL);
+ if (the_repository->gitdir) {
+ prepare_repo_settings(the_repository);
+ the_repository->settings.command_requires_full_index = 0;
+ }
+
memset(&match_all, 0, sizeof(match_all));
repo_init_revisions(the_repository, &rev, prefix);
git_config(grep_config, &rev.grep_filter);
@@ -1159,12 +1159,21 @@ test_expect_success 'show (cached blobs/trees)' '
test_sparse_match git show :folder1/a &&
# Asking "git show" for directories in the index
- # does not work as implemented. The error message is
- # different for a full checkout and a sparse checkout
- # when the directory is outside of the cone.
+ # had different behavior depending on the existence
+ # of a sparse index.
test_all_match test_must_fail git show :deep/ &&
test_must_fail git -C full-checkout show :folder1/ &&
- test_sparse_match test_must_fail git show :folder1/
+ test_must_fail git -C sparse-checkout show :folder1/ &&
+
+ git -C sparse-index show :folder1/ >actual &&
+ git -C full-checkout show HEAD:folder1 >expect &&
+
+ # The output of "git show" includes the way we referenced the
+ # objects, so strip that out.
+ test_line_count = 4 actual &&
+ tail -n 2 actual >actual-trunc &&
+ tail -n 2 expect >expect-trunc &&
+ test_cmp expect-trunc actual-trunc
'
test_expect_success 'submodule handling' '
@@ -1388,6 +1397,13 @@ test_expect_success 'sparse index is not expanded: diff' '
ensure_not_expanded diff --cached
'
+test_expect_success 'sparse index is not expanded: show' '
+ init_repos &&
+
+ ensure_not_expanded show :a &&
+ ensure_not_expanded show :deep/a
+'
+
test_expect_success 'sparse index is not expanded: update-index' '
init_repos &&