summaryrefslogtreecommitdiff
path: root/tests/attr
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2019-07-04 11:45:02 +0200
committerPatrick Steinhardt <ps@pks.im>2019-07-04 11:49:16 +0200
commitc87abeca9ee68a89fa3a6776aa7d44f9d14de6e7 (patch)
tree4dce7300c943fc828ec7f0a5edb3efce8cf5cf92 /tests/attr
parent1bbec26d2bbe1852ffb87d0bf9a3a1cabc4df53f (diff)
downloadlibgit2-c87abeca9ee68a89fa3a6776aa7d44f9d14de6e7.tar.gz
tests: attr: add tests for system-level attributes
There were no tests that verified that system-level gitattributes files get handled correctly. In fact, we have recently introduced a regression that caused us to abort if there was a system-level gitattributes file available. Add two tests that verify that we're able to handle system-level gitattributes files. The test attr::repo::sysdir_with_session would've failed without the fix to the described regression.
Diffstat (limited to 'tests/attr')
-rw-r--r--tests/attr/repo.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/attr/repo.c b/tests/attr/repo.c
index 5f50e9017..32f7b66c4 100644
--- a/tests/attr/repo.c
+++ b/tests/attr/repo.c
@@ -2,6 +2,7 @@
#include "fileops.h"
#include "git2/attr.h"
#include "attr.h"
+#include "sysdir.h"
#include "attr_expect.h"
#include "git2/sys/repository.h"
@@ -17,6 +18,7 @@ void test_attr_repo__cleanup(void)
{
cl_git_sandbox_cleanup();
g_repo = NULL;
+ cl_sandbox_set_search_path_defaults();
}
static struct attr_expected get_one_test_cases[] = {
@@ -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_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);
+}