Skip to content

Commit 82c7a9b

Browse files
pks-ttiennou
authored andcommitted
attr: fix attribute lookup if repo has no common directory
If creating a repository without a common directory (e.g. by using `git_repository_new`), then `git_repository_item_path` will return `GIT_ENOTFOUND` for every file that's usually located in this directory. While we do not care for this case when looking up the "info/attributes" file, we fail to properly ignore these errors when setting up or collecting attributes files. Thus, the gitattributes lookup is broken and will only ever return `GIT_ENOTFOUND`. Fix this issue by properly ignoring `GIT_ENOTFOUND` returned by `git_repository_item_path`.
1 parent 5452e49 commit 82c7a9b

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/attr.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,10 @@ static int attr_setup(git_repository *repo, git_attr_session *attr_session)
335335

336336
if ((error = git_repository_item_path(&path, repo, GIT_REPOSITORY_ITEM_INFO)) < 0 ||
337337
(error = preload_attr_file(repo, attr_session, GIT_ATTR_FILE__FROM_FILE,
338-
path.ptr, GIT_ATTR_FILE_INREPO)) < 0)
339-
goto out;
338+
path.ptr, GIT_ATTR_FILE_INREPO)) < 0) {
339+
if (error != GIT_ENOTFOUND)
340+
goto out;
341+
}
340342

341343
if ((workdir = git_repository_workdir(repo)) != NULL &&
342344
(error = preload_attr_file(repo, attr_session, GIT_ATTR_FILE__FROM_FILE,
@@ -510,15 +512,12 @@ static int collect_attr_files(
510512
* - $GIT_PREFIX/etc/gitattributes
511513
*/
512514

513-
error = git_repository_item_path(&attrfile, repo, GIT_REPOSITORY_ITEM_INFO);
514-
if (error < 0)
515-
goto cleanup;
516-
517-
error = push_attr_file(
518-
repo, attr_session, files, GIT_ATTR_FILE__FROM_FILE,
519-
attrfile.ptr, GIT_ATTR_FILE_INREPO);
520-
if (error < 0)
521-
goto cleanup;
515+
if ((error = git_repository_item_path(&attrfile, repo, GIT_REPOSITORY_ITEM_INFO)) < 0 ||
516+
(error = push_attr_file(repo, attr_session, files, GIT_ATTR_FILE__FROM_FILE,
517+
attrfile.ptr, GIT_ATTR_FILE_INREPO)) < 0) {
518+
if (error != GIT_ENOTFOUND)
519+
goto cleanup;
520+
}
522521

523522
info.repo = repo;
524523
info.attr_session = attr_session;

0 commit comments

Comments
 (0)