mirror of
https://github.com/git/git
synced 2024-08-27 19:49:21 +00:00
![Torsten Bögershausen](/assets/img/avatar_default.png)
Make it safer to normalize the line endings in a repository. Files that had been commited with CRLF will be commited with LF. The old way to normalize a repo was like this: # Make sure that there are not untracked files $ echo "* text=auto" >.gitattributes $ git read-tree --empty $ git add . $ git commit -m "Introduce end-of-line normalization" The user must make sure that there are no untracked files, otherwise they would have been added and tracked from now on. The new "add --renormalize" does not add untracked files: $ echo "* text=auto" >.gitattributes $ git add --renormalize . $ git commit -m "Introduce end-of-line normalization" Note that "git add --renormalize <pathspec>" is the short form for "git add -u --renormalize <pathspec>". While at it, document that the same renormalization may be needed, whenever a clean filter is added or changed. Helped-By: Junio C Hamano <gitster@pobox.com> Signed-off-by: Torsten Bögershausen <tboegi@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
31 lines
725 B
Bash
Executable file
31 lines
725 B
Bash
Executable file
#!/bin/sh
|
|
|
|
test_description='CRLF renormalization'
|
|
|
|
. ./test-lib.sh
|
|
|
|
test_expect_success setup '
|
|
git config core.autocrlf false &&
|
|
printf "LINEONE\nLINETWO\nLINETHREE\n" >LF.txt &&
|
|
printf "LINEONE\r\nLINETWO\r\nLINETHREE\r\n" >CRLF.txt &&
|
|
printf "LINEONE\r\nLINETWO\nLINETHREE\n" >CRLF_mix_LF.txt &&
|
|
git add . &&
|
|
git commit -m initial
|
|
'
|
|
|
|
test_expect_success 'renormalize CRLF in repo' '
|
|
echo "*.txt text=auto" >.gitattributes &&
|
|
git add --renormalize "*.txt" &&
|
|
cat >expect <<-\EOF &&
|
|
i/lf w/crlf attr/text=auto CRLF.txt
|
|
i/lf w/lf attr/text=auto LF.txt
|
|
i/lf w/mixed attr/text=auto CRLF_mix_LF.txt
|
|
EOF
|
|
git ls-files --eol |
|
|
sed -e "s/ / /g" -e "s/ */ /g" |
|
|
sort >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_done
|