summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@microsoft.com>2014-02-09 12:37:16 -0800
committerEdward Thomson <ethomson@microsoft.com>2014-02-09 13:45:38 -0800
commitf77127da12480c65caaddd2af655877978d1f5a7 (patch)
treea744a786718e867306f5e2ba0ecc7e5b4c6a1796
parentfb6f4539d1de1f2c171d6be2e088b5b763f3e5f8 (diff)
downloadlibgit2-f77127da12480c65caaddd2af655877978d1f5a7.tar.gz
Tests for core.autocrlf and .gitattributes
-rw-r--r--tests/checkout/crlf.c119
-rw-r--r--tests/clar_libgit2.c8
-rw-r--r--tests/clar_libgit2.h2
3 files changed, 104 insertions, 25 deletions
diff --git a/tests/checkout/crlf.c b/tests/checkout/crlf.c
index cba79432f..0d78ee039 100644
--- a/tests/checkout/crlf.c
+++ b/tests/checkout/crlf.c
@@ -18,19 +18,6 @@ void test_checkout_crlf__cleanup(void)
cl_git_sandbox_cleanup();
}
-void test_checkout_crlf__detect_crlf_autocrlf_false(void)
-{
- git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
-
- cl_repo_set_bool(g_repo, "core.autocrlf", false);
-
- git_checkout_head(g_repo, &opts);
-
- check_file_contents("./crlf/all-lf", ALL_LF_TEXT_RAW);
- check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_RAW);
-}
-
void test_checkout_crlf__autocrlf_false_index_size_is_unfiltered_size(void)
{
git_index *index;
@@ -100,18 +87,6 @@ void test_checkout_crlf__more_crlf_autocrlf_true(void)
check_file_contents("./crlf/more-crlf", MORE_CRLF_TEXT_AS_CRLF);
}
-void test_checkout_crlf__all_crlf_autocrlf_true(void)
-{
- git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
-
- cl_repo_set_bool(g_repo, "core.autocrlf", true);
-
- git_checkout_head(g_repo, &opts);
-
- check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_RAW);
-}
-
void test_checkout_crlf__autocrlf_true_index_size_is_filtered_size(void)
{
git_index *index;
@@ -229,3 +204,97 @@ void test_checkout_crlf__with_ident(void)
git_index_free(index);
}
+
+void test_checkout_crlf__autocrlf_false_no_attrs(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+
+ cl_repo_set_bool(g_repo, "core.autocrlf", false);
+
+ git_checkout_head(g_repo, &opts);
+
+ check_file_contents("./crlf/all-lf", ALL_LF_TEXT_RAW);
+ check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_RAW);
+}
+
+void test_checkout_crlf__autocrlf_true_no_attrs(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+
+ cl_repo_set_bool(g_repo, "core.autocrlf", true);
+
+ git_checkout_head(g_repo, &opts);
+
+ if (GIT_EOL_NATIVE == GIT_EOL_CRLF) {
+ check_file_contents("./crlf/all-lf", ALL_LF_TEXT_AS_CRLF);
+ check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_AS_CRLF);
+ } else {
+ check_file_contents("./crlf/all-lf", ALL_LF_TEXT_RAW);
+ check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_RAW);
+ }
+}
+
+void test_checkout_crlf__autocrlf_input_no_attrs(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+
+ cl_repo_set_string(g_repo, "core.autocrlf", "input");
+
+ git_checkout_head(g_repo, &opts);
+
+ check_file_contents("./crlf/all-lf", ALL_LF_TEXT_RAW);
+ check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_RAW);
+}
+
+void test_checkout_crlf__autocrlf_false_text_auto_attr(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+
+ cl_git_mkfile("./crlf/.gitattributes", "* text=auto\n");
+
+ cl_repo_set_bool(g_repo, "core.autocrlf", false);
+
+ git_checkout_head(g_repo, &opts);
+
+ check_file_contents("./crlf/all-lf", ALL_LF_TEXT_RAW);
+ check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_RAW);
+}
+
+void test_checkout_crlf__autocrlf_true_text_auto_attr(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+
+ cl_git_mkfile("./crlf/.gitattributes", "* text=auto\n");
+
+ cl_repo_set_bool(g_repo, "core.autocrlf", true);
+
+ git_checkout_head(g_repo, &opts);
+
+ if (GIT_EOL_NATIVE == GIT_EOL_CRLF) {
+ check_file_contents("./crlf/all-lf", ALL_LF_TEXT_AS_CRLF);
+ check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_AS_CRLF);
+ } else {
+ check_file_contents("./crlf/all-lf", ALL_LF_TEXT_RAW);
+ check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_RAW);
+ }
+}
+
+void test_checkout_crlf__autocrlf_input_text_auto_attr(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+
+ cl_git_mkfile("./crlf/.gitattributes", "* text=auto\n");
+
+ cl_repo_set_string(g_repo, "core.autocrlf", "input");
+
+ git_checkout_head(g_repo, &opts);
+
+ check_file_contents("./crlf/all-lf", ALL_LF_TEXT_RAW);
+ check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_RAW);
+}
diff --git a/tests/clar_libgit2.c b/tests/clar_libgit2.c
index 9a37ee4c1..9b062ef78 100644
--- a/tests/clar_libgit2.c
+++ b/tests/clar_libgit2.c
@@ -420,6 +420,14 @@ int cl_repo_get_bool(git_repository *repo, const char *cfg)
return val;
}
+void cl_repo_set_string(git_repository *repo, const char *cfg, const char *value)
+{
+ git_config *config;
+ cl_git_pass(git_repository_config(&config, repo));
+ cl_git_pass(git_config_set_string(config, cfg, value));
+ git_config_free(config);
+}
+
/* this is essentially the code from git__unescape modified slightly */
static size_t strip_cr_from_buf(char *start, size_t len)
{
diff --git a/tests/clar_libgit2.h b/tests/clar_libgit2.h
index b9ef5627e..915111244 100644
--- a/tests/clar_libgit2.h
+++ b/tests/clar_libgit2.h
@@ -116,4 +116,6 @@ void cl_repo_commit_from_index(
void cl_repo_set_bool(git_repository *repo, const char *cfg, int value);
int cl_repo_get_bool(git_repository *repo, const char *cfg);
+void cl_repo_set_string(git_repository *repo, const char *cfg, const char *value);
+
#endif