git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/2] t0027: combinations of core.autocrlf, core.eol and text

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 30, 2014, 18:27 UTC
Message-ID
<xmqq61jiz201.fsf@gitster.dls.corp.google.com>
In-Reply-To
<53AFB38E.8000401@web.de>
Torsten Bögershausen <tboegi@web.de> writes:
Show 15 quoted lines
> Historically there are 3 different parameters controlling how line endings
> are handled by Git:
> - core.autocrlf
> - core.eol
> - the "text" attribute in .gitattributes
>
> There are different types of content:
> - (1) Files with only LF
> - (2) Files with only CRLF
> - (3) Files with mixed LF and CRLF
> - (4) Files with LF and/or CRLF with CR not followed by LF
> - (5) Files which are binary (e.g. have NUL bytes)
>
> Recently the question came up, how files with mixed EOLs are handled by Git
> (and libgit2) when they are checked out and core.autocrlf=true.

I have a slight suspicion that it may be better to leave behaviour on some nonsensical combinations (e.g. 3 and 4) as "unspecified", which would mean we shouldn't be able to pick between test_expect_success and test_expect_failure for some of them.

> +test_description='CRLF conversion all combinations'
> +
> +check_files_in_ws()
> +{
(minor) Please have SP between "ws" and "()".
Show 16 quoted lines
> +(
> +	type od >/dev/null &&
> +	printf "line1Q\r\nline2\r\nline3" | q_to_nul >CRLF_nul &&
> +	cat >expect <<-EOF &&
> +	0000000 l i n e 1 \0 \r \n l i n e 2 \r \n l
> +	0000020 i n e 3
> +	0000024
> +EOF
> +	od -c CRLF_nul | sed -e "s/[ 	][	 ]*/ /g" -e "s/ *$//" >actual
> +	test_cmp expect actual &&
> +	rm expect actual
> +) || {
> +		skip_all="od not found or od -c not usable"
> +		exit 0
> +		test_done
> +}

I am not sure how cast-in-stone portable "od -c" output is across platforms in practice. You can use tr to convert NUL, CR and LF to some distinctive and otherwise unused character, just like you use q_to_nul to map NUL to "Q" already. And that would allow you to forget about such portability issues.

Show 11 quoted lines
> +test_expect_success 'setup master' '
> +	echo >.gitattributes &&
> +	git checkout -b master &&
> +	git add .gitattributes &&
> +	git commit -m "add .gitattributes" "" &&
> +	printf "line1\nline2\nline3"     >LF &&
> +	printf "line1\r\nline2\r\nline3" >CRLF &&
> +	printf "line1\r\nline2\nline3"   >CRLF_mix_LF &&
> +	printf "line1\nline2\rline3"     >LF_mix_CR &&
> +	printf "line1\r\nline2\rline3"   >CRLF_mix_CR &&
> +	printf "line1Q\nline2\nline3" | q_to_nul >LF_nul

I do not see why you would want files that end with incomplete lines for these. Please have the line-end for the last line in them.

Previous: Torsten Bögershausen
Message 2 of 2 in “t0027: combinations of core.autocrlf, core.eol and text”
  1. 2/2 t0027: combinations of core.autocrlf, core.eol and textTorsten Bögershausen, Jun 29, 2014
  2. Junio C HamanoJun 30, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.