attr: ignore missing index

This commit is contained in:
Kevin Saul
2023-12-15 11:41:46 +13:00
parent d1bdf2a8b9
commit f5793057fa
2 changed files with 30 additions and 1 deletions

View File

@@ -424,9 +424,13 @@ static int attr_setup(
goto out;
if ((error = git_repository_index__weakptr(&idx, repo)) < 0 ||
(error = preload_attr_source(repo, attr_session, &index_source)) < 0)
(error = preload_attr_source(repo, attr_session, &index_source)) < 0) {
if (error != GIT_ENOTFOUND)
goto out;
error = 0;
}
if ((opts && (opts->flags & GIT_ATTR_CHECK_INCLUDE_HEAD) != 0) &&
(error = preload_attr_source(repo, attr_session, &head_source)) < 0)
goto out;

View File

@@ -309,6 +309,31 @@ void test_attr_repo__bare_repo_with_index(void)
cl_assert(GIT_ATTR_IS_UNSPECIFIED(values[3]));
}
void test_attr_repo__inmemory_repo_without_index(void)
{
const char *names[1] = { "fake" };
const char *values[1];
git_repository *inmemory;
git_index *index = NULL;
/* setup bare in-memory repo without index */
#ifdef GIT_EXPERIMENTAL_SHA256
cl_git_pass(git_repository_new(&inmemory, GIT_OID_SHA1));
#else
cl_git_pass(git_repository_new(&inmemory));
#endif
cl_assert(git_repository_is_bare(inmemory));
/* verify repo isn't given an index upfront in future */
git_repository_index(&index, inmemory);
cl_assert(!index);
/* check attributes can be queried without error due to missing index */
cl_git_pass(git_attr_get_many(values, inmemory, 0, "fake.txt", 1, names));
git_repository_free(inmemory);
}
void test_attr_repo__sysdir(void)
{
git_str sysdir = GIT_STR_INIT;