Unverified Commit 82c7a9bc by Patrick Steinhardt Committed by Etienne Samson

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`.
parent 5452e49f
...@@ -335,8 +335,10 @@ static int attr_setup(git_repository *repo, git_attr_session *attr_session) ...@@ -335,8 +335,10 @@ static int attr_setup(git_repository *repo, git_attr_session *attr_session)
if ((error = git_repository_item_path(&path, repo, GIT_REPOSITORY_ITEM_INFO)) < 0 || if ((error = git_repository_item_path(&path, repo, GIT_REPOSITORY_ITEM_INFO)) < 0 ||
(error = preload_attr_file(repo, attr_session, GIT_ATTR_FILE__FROM_FILE, (error = preload_attr_file(repo, attr_session, GIT_ATTR_FILE__FROM_FILE,
path.ptr, GIT_ATTR_FILE_INREPO)) < 0) path.ptr, GIT_ATTR_FILE_INREPO)) < 0) {
if (error != GIT_ENOTFOUND)
goto out; goto out;
}
if ((workdir = git_repository_workdir(repo)) != NULL && if ((workdir = git_repository_workdir(repo)) != NULL &&
(error = preload_attr_file(repo, attr_session, GIT_ATTR_FILE__FROM_FILE, (error = preload_attr_file(repo, attr_session, GIT_ATTR_FILE__FROM_FILE,
...@@ -510,15 +512,12 @@ static int collect_attr_files( ...@@ -510,15 +512,12 @@ static int collect_attr_files(
* - $GIT_PREFIX/etc/gitattributes * - $GIT_PREFIX/etc/gitattributes
*/ */
error = git_repository_item_path(&attrfile, repo, GIT_REPOSITORY_ITEM_INFO); if ((error = git_repository_item_path(&attrfile, repo, GIT_REPOSITORY_ITEM_INFO)) < 0 ||
if (error < 0) (error = push_attr_file(repo, attr_session, files, GIT_ATTR_FILE__FROM_FILE,
goto cleanup; attrfile.ptr, GIT_ATTR_FILE_INREPO)) < 0) {
if (error != GIT_ENOTFOUND)
error = push_attr_file(
repo, attr_session, files, GIT_ATTR_FILE__FROM_FILE,
attrfile.ptr, GIT_ATTR_FILE_INREPO);
if (error < 0)
goto cleanup; goto cleanup;
}
info.repo = repo; info.repo = repo;
info.attr_session = attr_session; info.attr_session = attr_session;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment