diff options
author | Patrick Steinhardt <ps@pks.im> | 2019-06-26 14:49:24 +0200 |
---|---|---|
committer | Etienne Samson <samson.etienne@gmail.com> | 2019-06-26 14:49:24 +0200 |
commit | 82c7a9bcc6801aaa94dd63ab1add230dbc896211 (patch) | |
tree | 43fbda548865727050c543e058142d4f620db12d /src/attr.c | |
parent | 5452e49fce21f726bec19519da7f012e3f19e736 (diff) | |
download | libgit2-82c7a9bcc6801aaa94dd63ab1add230dbc896211.tar.gz |
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`.
Diffstat (limited to 'src/attr.c')
-rw-r--r-- | src/attr.c | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/src/attr.c b/src/attr.c index d9ddcfb5a..f50d28c1e 100644 --- a/src/attr.c +++ b/src/attr.c @@ -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 || (error = preload_attr_file(repo, attr_session, GIT_ATTR_FILE__FROM_FILE, - path.ptr, GIT_ATTR_FILE_INREPO)) < 0) - goto out; + path.ptr, GIT_ATTR_FILE_INREPO)) < 0) { + if (error != GIT_ENOTFOUND) + goto out; + } if ((workdir = git_repository_workdir(repo)) != NULL && (error = preload_attr_file(repo, attr_session, GIT_ATTR_FILE__FROM_FILE, @@ -510,15 +512,12 @@ static int collect_attr_files( * - $GIT_PREFIX/etc/gitattributes */ - error = git_repository_item_path(&attrfile, repo, GIT_REPOSITORY_ITEM_INFO); - if (error < 0) - goto cleanup; - - error = push_attr_file( - repo, attr_session, files, GIT_ATTR_FILE__FROM_FILE, - attrfile.ptr, GIT_ATTR_FILE_INREPO); - if (error < 0) - goto cleanup; + if ((error = git_repository_item_path(&attrfile, repo, GIT_REPOSITORY_ITEM_INFO)) < 0 || + (error = push_attr_file(repo, attr_session, files, GIT_ATTR_FILE__FROM_FILE, + attrfile.ptr, GIT_ATTR_FILE_INREPO)) < 0) { + if (error != GIT_ENOTFOUND) + goto cleanup; + } info.repo = repo; info.attr_session = attr_session; |