Commit de355f234174df291c9c40378da70114c3ba6c5d

Edward Thomson 2015-03-25T13:14:28

Merge pull request #3011 from ethomson/filter_zero_tempbuf Clear temporary buffer when filtering

diff --git a/src/filter.c b/src/filter.c
index 6d0d480..8bd7f4d 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -809,6 +809,9 @@ static int proxy_stream_init(
 	proxy_stream->target = target;
 	proxy_stream->output = temp_buf ? temp_buf : &proxy_stream->temp_buf;
 
+	if (temp_buf)
+		git_buf_clear(temp_buf);
+
 	*out = (git_writestream *)proxy_stream;
 	return 0;
 }
diff --git a/tests/checkout/crlf.c b/tests/checkout/crlf.c
index a7a579e..a9acdf4 100644
--- a/tests/checkout/crlf.c
+++ b/tests/checkout/crlf.c
@@ -347,3 +347,23 @@ void test_checkout_crlf__autocrlf_input_text_auto_attr(void)
 	check_file_contents("./crlf/all-lf", ALL_LF_TEXT_RAW);
 	check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_RAW);
 }
+
+void test_checkout_crlf__can_write_empty_file(void)
+{
+	git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
+	opts.checkout_strategy = GIT_CHECKOUT_FORCE;
+
+	cl_repo_set_bool(g_repo, "core.autocrlf", true);
+
+	git_repository_set_head(g_repo, "refs/heads/empty-files");
+	git_checkout_head(g_repo, &opts);
+
+	check_file_contents("./crlf/test1.txt", "");
+
+	if (GIT_EOL_NATIVE == GIT_EOL_LF)
+		check_file_contents("./crlf/test2.txt", "test2.txt's content\n");
+	else
+		check_file_contents("./crlf/test2.txt", "test2.txt's content\r\n");
+
+	check_file_contents("./crlf/test3.txt", "");
+}
diff --git a/tests/resources/crlf/.gitted/index b/tests/resources/crlf/.gitted/index
new file mode 100644
index 0000000..aadd35e
Binary files /dev/null and b/tests/resources/crlf/.gitted/index differ
diff --git a/tests/resources/crlf/.gitted/objects/16/c72b67861f8524a5bebc05cd20472d3fca00da b/tests/resources/crlf/.gitted/objects/16/c72b67861f8524a5bebc05cd20472d3fca00da
new file mode 100644
index 0000000..e2b1994
Binary files /dev/null and b/tests/resources/crlf/.gitted/objects/16/c72b67861f8524a5bebc05cd20472d3fca00da differ
diff --git a/tests/resources/crlf/.gitted/objects/3f/96bdca0e37616026afaa325c148cec4aa62d04 b/tests/resources/crlf/.gitted/objects/3f/96bdca0e37616026afaa325c148cec4aa62d04
new file mode 100644
index 0000000..a204fc9
Binary files /dev/null and b/tests/resources/crlf/.gitted/objects/3f/96bdca0e37616026afaa325c148cec4aa62d04 differ
diff --git a/tests/resources/crlf/.gitted/objects/47/fbc2c28a18df0dc773276a253eb85c7516ca50 b/tests/resources/crlf/.gitted/objects/47/fbc2c28a18df0dc773276a253eb85c7516ca50
new file mode 100644
index 0000000..d16db96
Binary files /dev/null and b/tests/resources/crlf/.gitted/objects/47/fbc2c28a18df0dc773276a253eb85c7516ca50 differ
diff --git a/tests/resources/crlf/.gitted/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904 b/tests/resources/crlf/.gitted/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904
new file mode 100644
index 0000000..adf6411
Binary files /dev/null and b/tests/resources/crlf/.gitted/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904 differ
diff --git a/tests/resources/crlf/.gitted/objects/6a/e3e9c11a51f0aabebcffcbd5c00f4beed143c9 b/tests/resources/crlf/.gitted/objects/6a/e3e9c11a51f0aabebcffcbd5c00f4beed143c9
new file mode 100644
index 0000000..6c18a3a
Binary files /dev/null and b/tests/resources/crlf/.gitted/objects/6a/e3e9c11a51f0aabebcffcbd5c00f4beed143c9 differ
diff --git a/tests/resources/crlf/.gitted/objects/96/87e444bcbb85645cb496080434c292f1b57182 b/tests/resources/crlf/.gitted/objects/96/87e444bcbb85645cb496080434c292f1b57182
new file mode 100644
index 0000000..5df64d8
--- /dev/null
+++ b/tests/resources/crlf/.gitted/objects/96/87e444bcbb85645cb496080434c292f1b57182
@@ -0,0 +1 @@
+xAJ1@Q9E!T:Y	ޢRMAoGp/m7L*LQ)yEU(JqfP2Q1%L$QS	,xѾoz|xz󰾱I0{S@x轻}_wU+H50'2=T
\ No newline at end of file
diff --git a/tests/resources/crlf/.gitted/objects/97/449da2d225557c558ac244384d487e66c3e591 b/tests/resources/crlf/.gitted/objects/97/449da2d225557c558ac244384d487e66c3e591
new file mode 100644
index 0000000..d3917a4
Binary files /dev/null and b/tests/resources/crlf/.gitted/objects/97/449da2d225557c558ac244384d487e66c3e591 differ
diff --git a/tests/resources/crlf/.gitted/refs/heads/empty-files b/tests/resources/crlf/.gitted/refs/heads/empty-files
new file mode 100644
index 0000000..8f1fe61
--- /dev/null
+++ b/tests/resources/crlf/.gitted/refs/heads/empty-files
@@ -0,0 +1 @@
+9687e444bcbb85645cb496080434c292f1b57182