summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-10-28 15:22:41 -0700
committerRussell Belfer <rb@github.com>2013-10-28 15:22:41 -0700
commitb83fd07880307106deb0ac7cb0d415d85c27f465 (patch)
tree2c22478c3cddba6aa55a1c2c980816a069999d21
parent99e96906f5682cb2841c11e983bd337267d4813e (diff)
downloadlibgit2-topic/CRLF_blob_filtered_content.tar.gz
Update core.autocrlf = true behaviortopic/CRLF_blob_filtered_content
When core.autocrlf = true, always insert CRLF line endings for text files that don't have explicit attributes set.
-rw-r--r--src/crlf.c3
-rw-r--r--tests-clar/checkout/crlf.c22
-rw-r--r--tests-clar/filter/crlf.c5
3 files changed, 7 insertions, 23 deletions
diff --git a/src/crlf.c b/src/crlf.c
index b25c02cce..4958acf64 100644
--- a/src/crlf.c
+++ b/src/crlf.c
@@ -183,7 +183,8 @@ static const char *line_ending(struct crlf_attrs *ca)
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 9a4cbd313..cea3d111a 100644
--- a/tests-clar/checkout/crlf.c
+++ b/tests-clar/checkout/crlf.c
@@ -62,11 +62,7 @@ void test_checkout_crlf__detect_crlf_autocrlf_true(void)
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 @@ void test_checkout_crlf__more_lf_autocrlf_true(void)
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 @@ void test_checkout_crlf__more_crlf_autocrlf_true(void)
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 @@ void test_checkout_crlf__autocrlf_true_index_size_is_filtered_size(void)
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 c9fb9cd7f..1f27e42e8 100644
--- a/tests-clar/filter/crlf.c
+++ b/tests-clar/filter/crlf.c
@@ -36,11 +36,8 @@ void test_filter_crlf__to_worktree(void)
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);