Update core.autocrlf = true behavior
When core.autocrlf = true, always insert CRLF line endings for
text files that don't have explicit attributes set.
diff --git a/src/crlf.c b/src/crlf.c
index b25c02cc..4958acf 100644
--- a/src/crlf.c
+++ b/src/crlf.c
@@ -183,7 +183,8 @@
switch (ca->eol) {
case GIT_EOL_UNSET:
- return GIT_EOL_NATIVE == GIT_EOL_CRLF ? "\r\n" : "\n";
+ return (ca->auto_crlf == GIT_AUTO_CRLF_TRUE) ? "\r\n" :
+ (GIT_EOL_NATIVE == GIT_EOL_CRLF) ? "\r\n" : "\n";
case GIT_EOL_CRLF:
return "\r\n";
diff --git a/tests-clar/checkout/crlf.c b/tests-clar/checkout/crlf.c
index 9a4cbd3..cea3d11 100644
--- a/tests-clar/checkout/crlf.c
+++ b/tests-clar/checkout/crlf.c
@@ -62,11 +62,7 @@
git_checkout_head(g_repo, &opts);
- if (GIT_EOL_NATIVE == GIT_EOL_LF)
- check_file_contents("./crlf/all-lf", ALL_LF_TEXT_RAW);
- else
- check_file_contents("./crlf/all-lf", ALL_LF_TEXT_AS_CRLF);
-
+ check_file_contents("./crlf/all-lf", ALL_LF_TEXT_AS_CRLF);
check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_RAW);
}
@@ -79,10 +75,7 @@
git_checkout_head(g_repo, &opts);
- if (GIT_EOL_NATIVE == GIT_EOL_LF)
- check_file_contents("./crlf/more-lf", MORE_LF_TEXT_RAW);
- else
- check_file_contents("./crlf/more-lf", MORE_LF_TEXT_AS_CRLF);
+ check_file_contents("./crlf/more-lf", MORE_LF_TEXT_AS_CRLF);
}
void test_checkout_crlf__more_crlf_autocrlf_true(void)
@@ -94,10 +87,7 @@
git_checkout_head(g_repo, &opts);
- if (GIT_EOL_NATIVE == GIT_EOL_LF)
- check_file_contents("./crlf/more-crlf", MORE_CRLF_TEXT_RAW);
- else
- check_file_contents("./crlf/more-crlf", MORE_CRLF_TEXT_AS_CRLF);
+ check_file_contents("./crlf/more-crlf", MORE_CRLF_TEXT_AS_CRLF);
}
void test_checkout_crlf__all_crlf_autocrlf_true(void)
@@ -126,11 +116,7 @@
git_repository_index(&index, g_repo);
cl_assert((entry = git_index_get_bypath(index, "all-lf", 0)) != NULL);
-
- if (GIT_EOL_NATIVE == GIT_EOL_LF)
- cl_assert_equal_sz(strlen(ALL_LF_TEXT_RAW), entry->file_size);
- else
- cl_assert_equal_sz(strlen(ALL_LF_TEXT_AS_CRLF), entry->file_size);
+ cl_assert_equal_sz(strlen(ALL_LF_TEXT_AS_CRLF), entry->file_size);
cl_assert((entry = git_index_get_bypath(index, "all-crlf", 0)) != NULL);
cl_assert_equal_sz(strlen(ALL_CRLF_TEXT_RAW), entry->file_size);
diff --git a/tests-clar/filter/crlf.c b/tests-clar/filter/crlf.c
index c9fb9cd..1f27e42 100644
--- a/tests-clar/filter/crlf.c
+++ b/tests-clar/filter/crlf.c
@@ -36,11 +36,8 @@
cl_git_pass(git_filter_list_apply_to_data(&out, fl, &in));
-#ifdef GIT_WIN32
+ /* core.autocrlf is on so we should always get \r\n */
cl_assert_equal_s("Some text\r\nRight here\r\n", out.ptr);
-#else
- cl_assert_equal_s("Some text\nRight here\n", out.ptr);
-#endif
git_filter_list_free(fl);
git_buf_free(&out);