diff options
author | Russell Belfer <rb@github.com> | 2014-05-06 16:01:49 -0700 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2014-05-06 16:01:49 -0700 |
commit | 5269008cf632efcd6a16f6160ec44244ce442400 (patch) | |
tree | ad3be5bcf12e9c046fab24fac3063e22b6843d5c /tests | |
parent | 6e9afb97d14545f9cea292f581de89d610ae8c07 (diff) | |
download | libgit2-5269008cf632efcd6a16f6160ec44244ce442400.tar.gz |
Add filter options and ALLOW_UNSAFE
Diff and status do not want core.safecrlf to actually raise an
error regardless of the setting, so this extends the filter API
with an additional options flags parameter and adds a flag so that
filters can be applied with GIT_FILTER_OPT_ALLOW_UNSAFE, indicating
that unsafe filter application should be downgraded from a failure
to a warning.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/filter/crlf.c | 55 | ||||
-rw-r--r-- | tests/filter/custom.c | 15 | ||||
-rw-r--r-- | tests/filter/ident.c | 6 | ||||
-rw-r--r-- | tests/object/blob/filter.c | 2 |
4 files changed, 64 insertions, 14 deletions
diff --git a/tests/filter/crlf.c b/tests/filter/crlf.c index 75320efee..66c267e31 100644 --- a/tests/filter/crlf.c +++ b/tests/filter/crlf.c @@ -25,7 +25,8 @@ void test_filter_crlf__to_worktree(void) git_filter *crlf; git_buf in = { 0 }, out = { 0 }; - cl_git_pass(git_filter_list_new(&fl, g_repo, GIT_FILTER_TO_WORKTREE)); + cl_git_pass(git_filter_list_new( + &fl, g_repo, GIT_FILTER_TO_WORKTREE, 0)); crlf = git_filter_lookup(GIT_FILTER_CRLF); cl_assert(crlf != NULL); @@ -53,7 +54,8 @@ void test_filter_crlf__to_odb(void) git_filter *crlf; git_buf in = { 0 }, out = { 0 }; - cl_git_pass(git_filter_list_new(&fl, g_repo, GIT_FILTER_TO_ODB)); + cl_git_pass(git_filter_list_new( + &fl, g_repo, GIT_FILTER_TO_ODB, 0)); crlf = git_filter_lookup(GIT_FILTER_CRLF); cl_assert(crlf != NULL); @@ -79,7 +81,8 @@ void test_filter_crlf__with_safecrlf(void) cl_repo_set_bool(g_repo, "core.safecrlf", true); - cl_git_pass(git_filter_list_new(&fl, g_repo, GIT_FILTER_TO_ODB)); + cl_git_pass(git_filter_list_new( + &fl, g_repo, GIT_FILTER_TO_ODB, 0)); crlf = git_filter_lookup(GIT_FILTER_CRLF); cl_assert(crlf != NULL); @@ -111,13 +114,57 @@ void test_filter_crlf__with_safecrlf(void) git_buf_free(&out); } +void test_filter_crlf__with_safecrlf_and_unsafe_allowed(void) +{ + git_filter_list *fl; + git_filter *crlf; + git_buf in = {0}, out = GIT_BUF_INIT; + + cl_repo_set_bool(g_repo, "core.safecrlf", true); + + cl_git_pass(git_filter_list_new( + &fl, g_repo, GIT_FILTER_TO_ODB, GIT_FILTER_OPT_ALLOW_UNSAFE)); + + crlf = git_filter_lookup(GIT_FILTER_CRLF); + cl_assert(crlf != NULL); + + cl_git_pass(git_filter_list_push(fl, crlf, NULL)); + + /* Normalized \r\n succeeds with safecrlf */ + in.ptr = "Normal\r\nCRLF\r\nline-endings.\r\n"; + in.size = strlen(in.ptr); + + cl_git_pass(git_filter_list_apply_to_data(&out, fl, &in)); + cl_assert_equal_s("Normal\nCRLF\nline-endings.\n", out.ptr); + + /* Mix of line endings fails with safecrlf, but allowed to pass */ + in.ptr = "Mixed\nup\r\nLF\nand\r\nCRLF\nline-endings.\r\n"; + in.size = strlen(in.ptr); + + cl_git_pass(git_filter_list_apply_to_data(&out, fl, &in)); + /* TODO: check for warning */ + cl_assert_equal_s("Mixed\nup\nLF\nand\nCRLF\nline-endings.\n", out.ptr); + + /* Normalized \n fails with safecrlf, but allowed to pass */ + in.ptr = "Normal\nLF\nonly\nline-endings.\n"; + in.size = strlen(in.ptr); + + cl_git_pass(git_filter_list_apply_to_data(&out, fl, &in)); + /* TODO: check for warning */ + cl_assert_equal_s("Normal\nLF\nonly\nline-endings.\n", out.ptr); + + git_filter_list_free(fl); + git_buf_free(&out); +} + void test_filter_crlf__no_safecrlf(void) { git_filter_list *fl; git_filter *crlf; git_buf in = {0}, out = GIT_BUF_INIT; - cl_git_pass(git_filter_list_new(&fl, g_repo, GIT_FILTER_TO_ODB)); + cl_git_pass(git_filter_list_new( + &fl, g_repo, GIT_FILTER_TO_ODB, 0)); crlf = git_filter_lookup(GIT_FILTER_CRLF); cl_assert(crlf != NULL); diff --git a/tests/filter/custom.c b/tests/filter/custom.c index 70524010e..0fd7c3744 100644 --- a/tests/filter/custom.c +++ b/tests/filter/custom.c @@ -194,7 +194,7 @@ void test_filter_custom__to_odb(void) git_buf in = GIT_BUF_INIT_CONST(workdir_data, strlen(workdir_data)); cl_git_pass(git_filter_list_load( - &fl, g_repo, NULL, "herofile", GIT_FILTER_TO_ODB)); + &fl, g_repo, NULL, "herofile", GIT_FILTER_TO_ODB, 0)); cl_git_pass(git_filter_list_apply_to_data(&out, fl, &in)); @@ -215,7 +215,7 @@ void test_filter_custom__to_workdir(void) bitflipped_and_reversed_data, BITFLIPPED_AND_REVERSED_DATA_LEN); cl_git_pass(git_filter_list_load( - &fl, g_repo, NULL, "herofile", GIT_FILTER_TO_WORKTREE)); + &fl, g_repo, NULL, "herofile", GIT_FILTER_TO_WORKTREE, 0)); cl_git_pass(git_filter_list_apply_to_data(&out, fl, &in)); @@ -233,13 +233,13 @@ void test_filter_custom__can_register_a_custom_filter_in_the_repository(void) git_filter_list *fl; cl_git_pass(git_filter_list_load( - &fl, g_repo, NULL, "herofile", GIT_FILTER_TO_WORKTREE)); + &fl, g_repo, NULL, "herofile", GIT_FILTER_TO_WORKTREE, 0)); /* expect: bitflip, reverse, crlf */ cl_assert_equal_sz(3, git_filter_list_length(fl)); git_filter_list_free(fl); cl_git_pass(git_filter_list_load( - &fl, g_repo, NULL, "herocorp", GIT_FILTER_TO_WORKTREE)); + &fl, g_repo, NULL, "herocorp", GIT_FILTER_TO_WORKTREE, 0)); /* expect: bitflip, reverse - possibly crlf depending on global config */ { size_t flen = git_filter_list_length(fl); @@ -248,19 +248,20 @@ void test_filter_custom__can_register_a_custom_filter_in_the_repository(void) git_filter_list_free(fl); cl_git_pass(git_filter_list_load( - &fl, g_repo, NULL, "hero.bin", GIT_FILTER_TO_WORKTREE)); + &fl, g_repo, NULL, "hero.bin", GIT_FILTER_TO_WORKTREE, 0)); /* expect: bitflip, reverse */ cl_assert_equal_sz(2, git_filter_list_length(fl)); git_filter_list_free(fl); cl_git_pass(git_filter_list_load( - &fl, g_repo, NULL, "heroflip", GIT_FILTER_TO_WORKTREE)); + &fl, g_repo, NULL, "heroflip", GIT_FILTER_TO_WORKTREE, 0)); /* expect: bitflip (because of -reverse) */ cl_assert_equal_sz(1, git_filter_list_length(fl)); git_filter_list_free(fl); cl_git_pass(git_filter_list_load( - &fl, g_repo, NULL, "doesntapplytome.bin", GIT_FILTER_TO_WORKTREE)); + &fl, g_repo, NULL, "doesntapplytome.bin", + GIT_FILTER_TO_WORKTREE, 0)); /* expect: none */ cl_assert_equal_sz(0, git_filter_list_length(fl)); git_filter_list_free(fl); diff --git a/tests/filter/ident.c b/tests/filter/ident.c index 2c8e6abea..2c9a3eb68 100644 --- a/tests/filter/ident.c +++ b/tests/filter/ident.c @@ -39,7 +39,8 @@ void test_filter_ident__to_worktree(void) git_filter_list *fl; git_filter *ident; - cl_git_pass(git_filter_list_new(&fl, g_repo, GIT_FILTER_TO_WORKTREE)); + cl_git_pass(git_filter_list_new( + &fl, g_repo, GIT_FILTER_TO_WORKTREE, 0)); ident = git_filter_lookup(GIT_FILTER_IDENT); cl_assert(ident != NULL); @@ -78,7 +79,8 @@ void test_filter_ident__to_odb(void) git_filter_list *fl; git_filter *ident; - cl_git_pass(git_filter_list_new(&fl, g_repo, GIT_FILTER_TO_ODB)); + cl_git_pass(git_filter_list_new( + &fl, g_repo, GIT_FILTER_TO_ODB, 0)); ident = git_filter_lookup(GIT_FILTER_IDENT); cl_assert(ident != NULL); diff --git a/tests/object/blob/filter.c b/tests/object/blob/filter.c index 0b2d6bf9e..9798055cd 100644 --- a/tests/object/blob/filter.c +++ b/tests/object/blob/filter.c @@ -121,7 +121,7 @@ void test_object_blob_filter__to_odb(void) cl_git_append2file("empty_standard_repo/.gitattributes", "*.txt text\n"); cl_git_pass(git_filter_list_load( - &fl, g_repo, NULL, "filename.txt", GIT_FILTER_TO_ODB)); + &fl, g_repo, NULL, "filename.txt", GIT_FILTER_TO_ODB, 0)); cl_assert(fl != NULL); for (i = 0; i < CRLF_NUM_TEST_OBJECTS; i++) { |