summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2019-07-21 11:44:11 +0100
committerEdward Thomson <ethomson@edwardthomson.com>2019-08-11 20:47:59 +0100
commitc66f7605e500f446329995706f63fe5300b16f39 (patch)
treea9728f7030997b4566512930a919a5ef6a979884
parentfa1a4c77f5f2c504f900035496e1b483acac412b (diff)
downloadlibgit2-c66f7605e500f446329995706f63fe5300b16f39.tar.gz
filter: ensure system attributes are read
By default, `/etc/gitattributes` (or the system equivalent) is read to provide attributes. Ensure that, by default, this is read when filtering blobs.
-rw-r--r--tests/filter/systemattrs.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/filter/systemattrs.c b/tests/filter/systemattrs.c
new file mode 100644
index 000000000..bb3a4dac4
--- /dev/null
+++ b/tests/filter/systemattrs.c
@@ -0,0 +1,54 @@
+#include "clar_libgit2.h"
+#include "crlf.h"
+#include "path.h"
+
+static git_repository *g_repo = NULL;
+static git_buf system_attr_path = GIT_BUF_INIT;
+
+void test_filter_systemattrs__initialize(void)
+{
+ g_repo = cl_git_sandbox_init("crlf");
+ cl_must_pass(p_unlink("crlf/.gitattributes"));
+
+ cl_git_pass(git_libgit2_opts(
+ GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_SYSTEM, &system_attr_path));
+ cl_git_pass(git_buf_joinpath(&system_attr_path,
+ system_attr_path.ptr, "gitattributes"));
+
+ cl_git_mkfile(system_attr_path.ptr,
+ "*.txt text\n"
+ "*.bin binary\n"
+ "*.crlf text eol=crlf\n"
+ "*.lf text eol=lf\n");
+}
+
+void test_filter_systemattrs__cleanup(void)
+{
+ cl_must_pass(p_unlink(system_attr_path.ptr));
+ git_buf_dispose(&system_attr_path);
+
+ cl_git_sandbox_cleanup();
+}
+
+void test_filter_systemattrs__reads_system_attributes(void)
+{
+ git_blob *blob;
+ git_buf buf = { 0 };
+
+ cl_git_pass(git_revparse_single(
+ (git_object **)&blob, g_repo, "799770d")); /* all-lf */
+
+ cl_assert_equal_s(ALL_LF_TEXT_RAW, git_blob_rawcontent(blob));
+
+ cl_git_pass(git_blob_filter(&buf, blob, "file.bin", NULL));
+ cl_assert_equal_s(ALL_LF_TEXT_RAW, buf.ptr);
+
+ cl_git_pass(git_blob_filter(&buf, blob, "file.crlf", NULL));
+ cl_assert_equal_s(ALL_LF_TEXT_AS_CRLF, buf.ptr);
+
+ cl_git_pass(git_blob_filter(&buf, blob, "file.lf", NULL));
+ cl_assert_equal_s(ALL_LF_TEXT_AS_LF, buf.ptr);
+
+ git_buf_dispose(&buf);
+ git_blob_free(blob);
+}