tests: attr: implement tests to verify attribute rewriting behaviour Implement some tests that verify that we are correctly updating gitattributes when rewriting or unlinking the corresponding files.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
diff --git a/tests/attr/macro.c b/tests/attr/macro.c
index 606984e..79e8225 100644
--- a/tests/attr/macro.c
+++ b/tests/attr/macro.c
@@ -89,3 +89,36 @@ void test_attr_macro__bad_macros(void)
cl_assert_equal_s("hahaha", values[4]);
cl_assert(GIT_ATTR_IS_TRUE(values[5]));
}
+
+void test_attr_macro__macros_in_root_wd_apply(void)
+{
+ const char *value;
+
+ g_repo = cl_git_sandbox_init("empty_standard_repo");
+
+ cl_git_pass(p_mkdir("empty_standard_repo/dir", 0777));
+ cl_git_rewritefile("empty_standard_repo/.gitattributes", "[attr]customattr key=value\n");
+ cl_git_rewritefile("empty_standard_repo/dir/.gitattributes", "file customattr\n");
+
+ cl_git_pass(git_attr_get(&value, g_repo, 0, "dir/file", "key"));
+ cl_assert_equal_s(value, "value");
+}
+
+void test_attr_macro__changing_macro_in_root_wd_updates_attributes(void)
+{
+ const char *value;
+
+ g_repo = cl_git_sandbox_init("empty_standard_repo");
+
+ cl_git_rewritefile("empty_standard_repo/.gitattributes",
+ "[attr]customattr key=first\n"
+ "file customattr\n");
+ cl_git_pass(git_attr_get(&value, g_repo, 0, "file", "key"));
+ cl_assert_equal_s(value, "first");
+
+ cl_git_rewritefile("empty_standard_repo/.gitattributes",
+ "[attr]customattr key=second\n"
+ "file customattr\n");
+ cl_git_pass(git_attr_get(&value, g_repo, 0, "file", "key"));
+ cl_assert_equal_s(value, "second");
+}
diff --git a/tests/attr/repo.c b/tests/attr/repo.c
index 442e55c..93d61b1 100644
--- a/tests/attr/repo.c
+++ b/tests/attr/repo.c
@@ -351,3 +351,55 @@ void test_attr_repo__sysdir_with_session(void)
git_buf_dispose(&sysdir);
git_attr_session__free(&session);
}
+
+void test_attr_repo__rewrite(void)
+{
+ const char *value;
+
+ cl_git_rewritefile("attr/.gitattributes", "file.txt foo=first\n");
+ cl_git_pass(git_attr_get(&value, g_repo, 0, "file.txt", "foo"));
+ cl_assert_equal_s(value, "first");
+
+ cl_git_rewritefile("attr/.gitattributes", "file.txt foo=second\n");
+ cl_git_pass(git_attr_get(&value, g_repo, 0, "file.txt", "foo"));
+ cl_assert_equal_s(value, "second");
+
+ cl_git_rewritefile("attr/.gitattributes", "file.txt other=value\n");
+ cl_git_pass(git_attr_get(&value, g_repo, 0, "file.txt", "foo"));
+ cl_assert_equal_p(value, NULL);
+}
+
+void test_attr_repo__rewrite_sysdir(void)
+{
+ git_buf sysdir = GIT_BUF_INIT;
+ const char *value;
+
+ cl_git_pass(p_mkdir("system", 0777));
+ 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_rewritefile("system/gitattributes", "file foo=first");
+ cl_git_pass(git_attr_get(&value, g_repo, 0, "file", "foo"));
+ cl_assert_equal_s(value, "first");
+
+ cl_git_rewritefile("system/gitattributes", "file foo=second");
+ cl_git_pass(git_attr_get(&value, g_repo, 0, "file", "foo"));
+ cl_assert_equal_s(value, "second");
+
+ git_buf_dispose(&sysdir);
+}
+
+void test_attr_repo__unlink(void)
+{
+ const char *value;
+
+ cl_git_rewritefile("attr/.gitattributes", "file.txt foo=value1\n");
+ cl_git_pass(git_attr_get(&value, g_repo, 0, "file.txt", "foo"));
+ cl_assert_equal_s(value, "value1");
+
+ cl_git_pass(p_unlink("attr/.gitattributes"));
+
+ cl_git_pass(git_attr_get(&value, g_repo, 0, "file.txt", "foo"));
+ cl_assert_equal_p(value, NULL);
+}