Unverified Commit 5c87b5a8 by Patrick Steinhardt Committed by GitHub

Merge pull request #5152 from csware/attr-system-attr-file

Fix Regression: attr: Correctly load system attr file (on Windows)
parents c4c1500a c87abeca
...@@ -333,6 +333,7 @@ static int attr_setup(git_repository *repo, git_attr_session *attr_session) ...@@ -333,6 +333,7 @@ static int attr_setup(git_repository *repo, git_attr_session *attr_session)
NULL, git_repository_attr_cache(repo)->cfg_attr_file)) < 0) NULL, git_repository_attr_cache(repo)->cfg_attr_file)) < 0)
goto out; goto out;
git_buf_clear(&path); /* git_repository_item_path expects an empty buffer, because it uses git_buf_set */
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) {
......
...@@ -919,6 +919,7 @@ int git_attr_session__init(git_attr_session *session, git_repository *repo) ...@@ -919,6 +919,7 @@ int git_attr_session__init(git_attr_session *session, git_repository *repo)
{ {
assert(repo); assert(repo);
memset(session, 0, sizeof(*session));
session->key = git_atomic_inc(&repo->attr_session_key); session->key = git_atomic_inc(&repo->attr_session_key);
return 0; return 0;
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include "fileops.h" #include "fileops.h"
#include "git2/attr.h" #include "git2/attr.h"
#include "attr.h" #include "attr.h"
#include "sysdir.h"
#include "attr_expect.h" #include "attr_expect.h"
#include "git2/sys/repository.h" #include "git2/sys/repository.h"
...@@ -17,6 +18,7 @@ void test_attr_repo__cleanup(void) ...@@ -17,6 +18,7 @@ void test_attr_repo__cleanup(void)
{ {
cl_git_sandbox_cleanup(); cl_git_sandbox_cleanup();
g_repo = NULL; g_repo = NULL;
cl_sandbox_set_search_path_defaults();
} }
static struct attr_expected get_one_test_cases[] = { static struct attr_expected get_one_test_cases[] = {
...@@ -376,3 +378,46 @@ void test_attr_repo__bare_repo_with_index(void) ...@@ -376,3 +378,46 @@ void test_attr_repo__bare_repo_with_index(void)
cl_assert(GIT_ATTR_IS_FALSE(values[2])); cl_assert(GIT_ATTR_IS_FALSE(values[2]));
cl_assert(GIT_ATTR_IS_UNSPECIFIED(values[3])); cl_assert(GIT_ATTR_IS_UNSPECIFIED(values[3]));
} }
void test_attr_repo__sysdir(void)
{
git_buf sysdir = GIT_BUF_INIT;
const char *value;
cl_git_pass(p_mkdir("system", 0777));
cl_git_rewritefile("system/gitattributes", "file merge=foo");
cl_git_pass(git_buf_joinpath(&sysdir, clar_sandbox_path(), "system"));
cl_git_pass(git_sysdir_set(GIT_SYSDIR_SYSTEM, sysdir.ptr));
g_repo = cl_git_sandbox_reopen();
cl_git_pass(git_attr_get(&value, g_repo, 0, "file", "merge"));
cl_assert_equal_s(value, "foo");
cl_git_pass(p_unlink("system/gitattributes"));
cl_git_pass(p_rmdir("system"));
git_buf_dispose(&sysdir);
}
void test_attr_repo__sysdir_with_session(void)
{
const char *values[2], *attrs[2] = { "foo", "bar" };
git_buf sysdir = GIT_BUF_INIT;
git_attr_session session;
cl_git_pass(p_mkdir("system", 0777));
cl_git_rewritefile("system/gitattributes", "file foo=1 bar=2");
cl_git_pass(git_buf_joinpath(&sysdir, clar_sandbox_path(), "system"));
cl_git_pass(git_sysdir_set(GIT_SYSDIR_SYSTEM, sysdir.ptr));
g_repo = cl_git_sandbox_reopen();
cl_git_pass(git_attr_session__init(&session, g_repo));
cl_git_pass(git_attr_get_many_with_session(values, g_repo, &session, 0, "file", ARRAY_SIZE(attrs), attrs));
cl_assert_equal_s(values[0], "1");
cl_assert_equal_s(values[1], "2");
cl_git_pass(p_unlink("system/gitattributes"));
cl_git_pass(p_rmdir("system"));
git_buf_dispose(&sysdir);
git_attr_session__free(&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