2007-02-14 23:54:00 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='CRLF conversion'
|
|
|
|
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
2010-01-26 01:33:57 +01:00
|
|
|
has_cr() {
|
|
|
|
tr '\015' Q <"$1" | grep Q >/dev/null
|
2007-02-14 23:54:00 +01:00
|
|
|
}
|
|
|
|
|
2015-03-25 06:28:44 +01:00
|
|
|
# add or remove CRs to disk file in-place
|
|
|
|
# usage: munge_cr <append|remove> <file>
|
|
|
|
munge_cr () {
|
|
|
|
"${1}_cr" <"$2" >tmp &&
|
|
|
|
mv tmp "$2"
|
|
|
|
}
|
|
|
|
|
2007-02-14 23:54:00 +01:00
|
|
|
test_expect_success setup '
|
|
|
|
|
2008-01-18 07:52:40 +01:00
|
|
|
git config core.autocrlf false &&
|
2007-02-14 23:54:00 +01:00
|
|
|
|
|
|
|
for w in Hello world how are you; do echo $w; done >one &&
|
|
|
|
mkdir dir &&
|
|
|
|
for w in I am very very fine thank you; do echo $w; done >dir/two &&
|
2007-04-20 07:37:19 +02:00
|
|
|
for w in Oh here is NULQin text here; do echo $w; done | q_to_nul >three &&
|
2007-02-14 23:54:00 +01:00
|
|
|
git add . &&
|
|
|
|
|
|
|
|
git commit -m initial &&
|
|
|
|
|
2014-04-28 14:57:26 +02:00
|
|
|
one=$(git rev-parse HEAD:one) &&
|
|
|
|
dir=$(git rev-parse HEAD:dir) &&
|
|
|
|
two=$(git rev-parse HEAD:dir/two) &&
|
|
|
|
three=$(git rev-parse HEAD:three) &&
|
2007-02-14 23:54:00 +01:00
|
|
|
|
|
|
|
for w in Some extra lines here; do echo $w; done >>one &&
|
|
|
|
git diff >patch.file &&
|
2014-04-28 14:57:26 +02:00
|
|
|
patched=$(git hash-object --stdin <one) &&
|
2015-03-25 06:31:41 +01:00
|
|
|
git read-tree --reset -u HEAD
|
2007-02-14 23:54:00 +01:00
|
|
|
'
|
|
|
|
|
safecrlf: Add mechanism to warn about irreversible crlf conversions
CRLF conversion bears a slight chance of corrupting data.
autocrlf=true will convert CRLF to LF during commit and LF to
CRLF during checkout. A file that contains a mixture of LF and
CRLF before the commit cannot be recreated by git. For text
files this is the right thing to do: it corrects line endings
such that we have only LF line endings in the repository.
But for binary files that are accidentally classified as text the
conversion can corrupt data.
If you recognize such corruption early you can easily fix it by
setting the conversion type explicitly in .gitattributes. Right
after committing you still have the original file in your work
tree and this file is not yet corrupted. You can explicitly tell
git that this file is binary and git will handle the file
appropriately.
Unfortunately, the desired effect of cleaning up text files with
mixed line endings and the undesired effect of corrupting binary
files cannot be distinguished. In both cases CRLFs are removed
in an irreversible way. For text files this is the right thing
to do because CRLFs are line endings, while for binary files
converting CRLFs corrupts data.
This patch adds a mechanism that can either warn the user about
an irreversible conversion or can even refuse to convert. The
mechanism is controlled by the variable core.safecrlf, with the
following values:
- false: disable safecrlf mechanism
- warn: warn about irreversible conversions
- true: refuse irreversible conversions
The default is to warn. Users are only affected by this default
if core.autocrlf is set. But the current default of git is to
leave core.autocrlf unset, so users will not see warnings unless
they deliberately chose to activate the autocrlf mechanism.
The safecrlf mechanism's details depend on the git command. The
general principles when safecrlf is active (not false) are:
- we warn/error out if files in the work tree can modified in an
irreversible way without giving the user a chance to backup the
original file.
- for read-only operations that do not modify files in the work tree
we do not not print annoying warnings.
There are exceptions. Even though...
- "git add" itself does not touch the files in the work tree, the
next checkout would, so the safety triggers;
- "git apply" to update a text file with a patch does touch the files
in the work tree, but the operation is about text files and CRLF
conversion is about fixing the line ending inconsistencies, so the
safety does not trigger;
- "git diff" itself does not touch the files in the work tree, it is
often run to inspect the changes you intend to next "git add". To
catch potential problems early, safety triggers.
The concept of a safety check was originally proposed in a similar
way by Linus Torvalds. Thanks to Dimitry Potapov for insisting
on getting the naked LF/autocrlf=true case right.
Signed-off-by: Steffen Prohaska <prohaska@zib.de>
2008-02-06 12:25:58 +01:00
|
|
|
test_expect_success 'safecrlf: autocrlf=input, all CRLF' '
|
|
|
|
|
|
|
|
git config core.autocrlf input &&
|
|
|
|
git config core.safecrlf true &&
|
|
|
|
|
|
|
|
for w in I am all CRLF; do echo $w; done | append_cr >allcrlf &&
|
2008-07-12 17:47:52 +02:00
|
|
|
test_must_fail git add allcrlf
|
safecrlf: Add mechanism to warn about irreversible crlf conversions
CRLF conversion bears a slight chance of corrupting data.
autocrlf=true will convert CRLF to LF during commit and LF to
CRLF during checkout. A file that contains a mixture of LF and
CRLF before the commit cannot be recreated by git. For text
files this is the right thing to do: it corrects line endings
such that we have only LF line endings in the repository.
But for binary files that are accidentally classified as text the
conversion can corrupt data.
If you recognize such corruption early you can easily fix it by
setting the conversion type explicitly in .gitattributes. Right
after committing you still have the original file in your work
tree and this file is not yet corrupted. You can explicitly tell
git that this file is binary and git will handle the file
appropriately.
Unfortunately, the desired effect of cleaning up text files with
mixed line endings and the undesired effect of corrupting binary
files cannot be distinguished. In both cases CRLFs are removed
in an irreversible way. For text files this is the right thing
to do because CRLFs are line endings, while for binary files
converting CRLFs corrupts data.
This patch adds a mechanism that can either warn the user about
an irreversible conversion or can even refuse to convert. The
mechanism is controlled by the variable core.safecrlf, with the
following values:
- false: disable safecrlf mechanism
- warn: warn about irreversible conversions
- true: refuse irreversible conversions
The default is to warn. Users are only affected by this default
if core.autocrlf is set. But the current default of git is to
leave core.autocrlf unset, so users will not see warnings unless
they deliberately chose to activate the autocrlf mechanism.
The safecrlf mechanism's details depend on the git command. The
general principles when safecrlf is active (not false) are:
- we warn/error out if files in the work tree can modified in an
irreversible way without giving the user a chance to backup the
original file.
- for read-only operations that do not modify files in the work tree
we do not not print annoying warnings.
There are exceptions. Even though...
- "git add" itself does not touch the files in the work tree, the
next checkout would, so the safety triggers;
- "git apply" to update a text file with a patch does touch the files
in the work tree, but the operation is about text files and CRLF
conversion is about fixing the line ending inconsistencies, so the
safety does not trigger;
- "git diff" itself does not touch the files in the work tree, it is
often run to inspect the changes you intend to next "git add". To
catch potential problems early, safety triggers.
The concept of a safety check was originally proposed in a similar
way by Linus Torvalds. Thanks to Dimitry Potapov for insisting
on getting the naked LF/autocrlf=true case right.
Signed-off-by: Steffen Prohaska <prohaska@zib.de>
2008-02-06 12:25:58 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'safecrlf: autocrlf=input, mixed LF/CRLF' '
|
|
|
|
|
|
|
|
git config core.autocrlf input &&
|
|
|
|
git config core.safecrlf true &&
|
|
|
|
|
|
|
|
for w in Oh here is CRLFQ in text; do echo $w; done | q_to_cr >mixed &&
|
2008-07-12 17:47:52 +02:00
|
|
|
test_must_fail git add mixed
|
safecrlf: Add mechanism to warn about irreversible crlf conversions
CRLF conversion bears a slight chance of corrupting data.
autocrlf=true will convert CRLF to LF during commit and LF to
CRLF during checkout. A file that contains a mixture of LF and
CRLF before the commit cannot be recreated by git. For text
files this is the right thing to do: it corrects line endings
such that we have only LF line endings in the repository.
But for binary files that are accidentally classified as text the
conversion can corrupt data.
If you recognize such corruption early you can easily fix it by
setting the conversion type explicitly in .gitattributes. Right
after committing you still have the original file in your work
tree and this file is not yet corrupted. You can explicitly tell
git that this file is binary and git will handle the file
appropriately.
Unfortunately, the desired effect of cleaning up text files with
mixed line endings and the undesired effect of corrupting binary
files cannot be distinguished. In both cases CRLFs are removed
in an irreversible way. For text files this is the right thing
to do because CRLFs are line endings, while for binary files
converting CRLFs corrupts data.
This patch adds a mechanism that can either warn the user about
an irreversible conversion or can even refuse to convert. The
mechanism is controlled by the variable core.safecrlf, with the
following values:
- false: disable safecrlf mechanism
- warn: warn about irreversible conversions
- true: refuse irreversible conversions
The default is to warn. Users are only affected by this default
if core.autocrlf is set. But the current default of git is to
leave core.autocrlf unset, so users will not see warnings unless
they deliberately chose to activate the autocrlf mechanism.
The safecrlf mechanism's details depend on the git command. The
general principles when safecrlf is active (not false) are:
- we warn/error out if files in the work tree can modified in an
irreversible way without giving the user a chance to backup the
original file.
- for read-only operations that do not modify files in the work tree
we do not not print annoying warnings.
There are exceptions. Even though...
- "git add" itself does not touch the files in the work tree, the
next checkout would, so the safety triggers;
- "git apply" to update a text file with a patch does touch the files
in the work tree, but the operation is about text files and CRLF
conversion is about fixing the line ending inconsistencies, so the
safety does not trigger;
- "git diff" itself does not touch the files in the work tree, it is
often run to inspect the changes you intend to next "git add". To
catch potential problems early, safety triggers.
The concept of a safety check was originally proposed in a similar
way by Linus Torvalds. Thanks to Dimitry Potapov for insisting
on getting the naked LF/autocrlf=true case right.
Signed-off-by: Steffen Prohaska <prohaska@zib.de>
2008-02-06 12:25:58 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'safecrlf: autocrlf=true, all LF' '
|
|
|
|
|
|
|
|
git config core.autocrlf true &&
|
|
|
|
git config core.safecrlf true &&
|
|
|
|
|
|
|
|
for w in I am all LF; do echo $w; done >alllf &&
|
2008-07-12 17:47:52 +02:00
|
|
|
test_must_fail git add alllf
|
safecrlf: Add mechanism to warn about irreversible crlf conversions
CRLF conversion bears a slight chance of corrupting data.
autocrlf=true will convert CRLF to LF during commit and LF to
CRLF during checkout. A file that contains a mixture of LF and
CRLF before the commit cannot be recreated by git. For text
files this is the right thing to do: it corrects line endings
such that we have only LF line endings in the repository.
But for binary files that are accidentally classified as text the
conversion can corrupt data.
If you recognize such corruption early you can easily fix it by
setting the conversion type explicitly in .gitattributes. Right
after committing you still have the original file in your work
tree and this file is not yet corrupted. You can explicitly tell
git that this file is binary and git will handle the file
appropriately.
Unfortunately, the desired effect of cleaning up text files with
mixed line endings and the undesired effect of corrupting binary
files cannot be distinguished. In both cases CRLFs are removed
in an irreversible way. For text files this is the right thing
to do because CRLFs are line endings, while for binary files
converting CRLFs corrupts data.
This patch adds a mechanism that can either warn the user about
an irreversible conversion or can even refuse to convert. The
mechanism is controlled by the variable core.safecrlf, with the
following values:
- false: disable safecrlf mechanism
- warn: warn about irreversible conversions
- true: refuse irreversible conversions
The default is to warn. Users are only affected by this default
if core.autocrlf is set. But the current default of git is to
leave core.autocrlf unset, so users will not see warnings unless
they deliberately chose to activate the autocrlf mechanism.
The safecrlf mechanism's details depend on the git command. The
general principles when safecrlf is active (not false) are:
- we warn/error out if files in the work tree can modified in an
irreversible way without giving the user a chance to backup the
original file.
- for read-only operations that do not modify files in the work tree
we do not not print annoying warnings.
There are exceptions. Even though...
- "git add" itself does not touch the files in the work tree, the
next checkout would, so the safety triggers;
- "git apply" to update a text file with a patch does touch the files
in the work tree, but the operation is about text files and CRLF
conversion is about fixing the line ending inconsistencies, so the
safety does not trigger;
- "git diff" itself does not touch the files in the work tree, it is
often run to inspect the changes you intend to next "git add". To
catch potential problems early, safety triggers.
The concept of a safety check was originally proposed in a similar
way by Linus Torvalds. Thanks to Dimitry Potapov for insisting
on getting the naked LF/autocrlf=true case right.
Signed-off-by: Steffen Prohaska <prohaska@zib.de>
2008-02-06 12:25:58 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'safecrlf: autocrlf=true mixed LF/CRLF' '
|
|
|
|
|
|
|
|
git config core.autocrlf true &&
|
|
|
|
git config core.safecrlf true &&
|
|
|
|
|
|
|
|
for w in Oh here is CRLFQ in text; do echo $w; done | q_to_cr >mixed &&
|
2008-07-12 17:47:52 +02:00
|
|
|
test_must_fail git add mixed
|
safecrlf: Add mechanism to warn about irreversible crlf conversions
CRLF conversion bears a slight chance of corrupting data.
autocrlf=true will convert CRLF to LF during commit and LF to
CRLF during checkout. A file that contains a mixture of LF and
CRLF before the commit cannot be recreated by git. For text
files this is the right thing to do: it corrects line endings
such that we have only LF line endings in the repository.
But for binary files that are accidentally classified as text the
conversion can corrupt data.
If you recognize such corruption early you can easily fix it by
setting the conversion type explicitly in .gitattributes. Right
after committing you still have the original file in your work
tree and this file is not yet corrupted. You can explicitly tell
git that this file is binary and git will handle the file
appropriately.
Unfortunately, the desired effect of cleaning up text files with
mixed line endings and the undesired effect of corrupting binary
files cannot be distinguished. In both cases CRLFs are removed
in an irreversible way. For text files this is the right thing
to do because CRLFs are line endings, while for binary files
converting CRLFs corrupts data.
This patch adds a mechanism that can either warn the user about
an irreversible conversion or can even refuse to convert. The
mechanism is controlled by the variable core.safecrlf, with the
following values:
- false: disable safecrlf mechanism
- warn: warn about irreversible conversions
- true: refuse irreversible conversions
The default is to warn. Users are only affected by this default
if core.autocrlf is set. But the current default of git is to
leave core.autocrlf unset, so users will not see warnings unless
they deliberately chose to activate the autocrlf mechanism.
The safecrlf mechanism's details depend on the git command. The
general principles when safecrlf is active (not false) are:
- we warn/error out if files in the work tree can modified in an
irreversible way without giving the user a chance to backup the
original file.
- for read-only operations that do not modify files in the work tree
we do not not print annoying warnings.
There are exceptions. Even though...
- "git add" itself does not touch the files in the work tree, the
next checkout would, so the safety triggers;
- "git apply" to update a text file with a patch does touch the files
in the work tree, but the operation is about text files and CRLF
conversion is about fixing the line ending inconsistencies, so the
safety does not trigger;
- "git diff" itself does not touch the files in the work tree, it is
often run to inspect the changes you intend to next "git add". To
catch potential problems early, safety triggers.
The concept of a safety check was originally proposed in a similar
way by Linus Torvalds. Thanks to Dimitry Potapov for insisting
on getting the naked LF/autocrlf=true case right.
Signed-off-by: Steffen Prohaska <prohaska@zib.de>
2008-02-06 12:25:58 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'safecrlf: print warning only once' '
|
|
|
|
|
|
|
|
git config core.autocrlf input &&
|
|
|
|
git config core.safecrlf warn &&
|
|
|
|
|
|
|
|
for w in I am all LF; do echo $w; done >doublewarn &&
|
|
|
|
git add doublewarn &&
|
|
|
|
git commit -m "nowarn" &&
|
|
|
|
for w in Oh here is CRLFQ in text; do echo $w; done | q_to_cr >doublewarn &&
|
2016-10-17 15:15:27 +02:00
|
|
|
git add doublewarn 2>err &&
|
|
|
|
if test_have_prereq C_LOCALE_OUTPUT
|
|
|
|
then
|
|
|
|
test $(grep "CRLF will be replaced by LF" err | wc -l) = 1
|
|
|
|
fi
|
safecrlf: Add mechanism to warn about irreversible crlf conversions
CRLF conversion bears a slight chance of corrupting data.
autocrlf=true will convert CRLF to LF during commit and LF to
CRLF during checkout. A file that contains a mixture of LF and
CRLF before the commit cannot be recreated by git. For text
files this is the right thing to do: it corrects line endings
such that we have only LF line endings in the repository.
But for binary files that are accidentally classified as text the
conversion can corrupt data.
If you recognize such corruption early you can easily fix it by
setting the conversion type explicitly in .gitattributes. Right
after committing you still have the original file in your work
tree and this file is not yet corrupted. You can explicitly tell
git that this file is binary and git will handle the file
appropriately.
Unfortunately, the desired effect of cleaning up text files with
mixed line endings and the undesired effect of corrupting binary
files cannot be distinguished. In both cases CRLFs are removed
in an irreversible way. For text files this is the right thing
to do because CRLFs are line endings, while for binary files
converting CRLFs corrupts data.
This patch adds a mechanism that can either warn the user about
an irreversible conversion or can even refuse to convert. The
mechanism is controlled by the variable core.safecrlf, with the
following values:
- false: disable safecrlf mechanism
- warn: warn about irreversible conversions
- true: refuse irreversible conversions
The default is to warn. Users are only affected by this default
if core.autocrlf is set. But the current default of git is to
leave core.autocrlf unset, so users will not see warnings unless
they deliberately chose to activate the autocrlf mechanism.
The safecrlf mechanism's details depend on the git command. The
general principles when safecrlf is active (not false) are:
- we warn/error out if files in the work tree can modified in an
irreversible way without giving the user a chance to backup the
original file.
- for read-only operations that do not modify files in the work tree
we do not not print annoying warnings.
There are exceptions. Even though...
- "git add" itself does not touch the files in the work tree, the
next checkout would, so the safety triggers;
- "git apply" to update a text file with a patch does touch the files
in the work tree, but the operation is about text files and CRLF
conversion is about fixing the line ending inconsistencies, so the
safety does not trigger;
- "git diff" itself does not touch the files in the work tree, it is
often run to inspect the changes you intend to next "git add". To
catch potential problems early, safety triggers.
The concept of a safety check was originally proposed in a similar
way by Linus Torvalds. Thanks to Dimitry Potapov for insisting
on getting the naked LF/autocrlf=true case right.
Signed-off-by: Steffen Prohaska <prohaska@zib.de>
2008-02-06 12:25:58 +01:00
|
|
|
'
|
|
|
|
|
2013-06-24 23:35:04 +02:00
|
|
|
|
|
|
|
test_expect_success 'safecrlf: git diff demotes safecrlf=true to warn' '
|
|
|
|
git config core.autocrlf input &&
|
|
|
|
git config core.safecrlf true &&
|
|
|
|
git diff HEAD
|
|
|
|
'
|
|
|
|
|
|
|
|
|
2018-06-04 22:17:42 +02:00
|
|
|
test_expect_success 'safecrlf: no warning with safecrlf=false' '
|
|
|
|
git config core.autocrlf input &&
|
|
|
|
git config core.safecrlf false &&
|
|
|
|
|
|
|
|
for w in I am all CRLF; do echo $w; done | append_cr >allcrlf &&
|
|
|
|
git add allcrlf 2>err &&
|
|
|
|
test_must_be_empty err
|
|
|
|
'
|
|
|
|
|
|
|
|
|
safecrlf: Add mechanism to warn about irreversible crlf conversions
CRLF conversion bears a slight chance of corrupting data.
autocrlf=true will convert CRLF to LF during commit and LF to
CRLF during checkout. A file that contains a mixture of LF and
CRLF before the commit cannot be recreated by git. For text
files this is the right thing to do: it corrects line endings
such that we have only LF line endings in the repository.
But for binary files that are accidentally classified as text the
conversion can corrupt data.
If you recognize such corruption early you can easily fix it by
setting the conversion type explicitly in .gitattributes. Right
after committing you still have the original file in your work
tree and this file is not yet corrupted. You can explicitly tell
git that this file is binary and git will handle the file
appropriately.
Unfortunately, the desired effect of cleaning up text files with
mixed line endings and the undesired effect of corrupting binary
files cannot be distinguished. In both cases CRLFs are removed
in an irreversible way. For text files this is the right thing
to do because CRLFs are line endings, while for binary files
converting CRLFs corrupts data.
This patch adds a mechanism that can either warn the user about
an irreversible conversion or can even refuse to convert. The
mechanism is controlled by the variable core.safecrlf, with the
following values:
- false: disable safecrlf mechanism
- warn: warn about irreversible conversions
- true: refuse irreversible conversions
The default is to warn. Users are only affected by this default
if core.autocrlf is set. But the current default of git is to
leave core.autocrlf unset, so users will not see warnings unless
they deliberately chose to activate the autocrlf mechanism.
The safecrlf mechanism's details depend on the git command. The
general principles when safecrlf is active (not false) are:
- we warn/error out if files in the work tree can modified in an
irreversible way without giving the user a chance to backup the
original file.
- for read-only operations that do not modify files in the work tree
we do not not print annoying warnings.
There are exceptions. Even though...
- "git add" itself does not touch the files in the work tree, the
next checkout would, so the safety triggers;
- "git apply" to update a text file with a patch does touch the files
in the work tree, but the operation is about text files and CRLF
conversion is about fixing the line ending inconsistencies, so the
safety does not trigger;
- "git diff" itself does not touch the files in the work tree, it is
often run to inspect the changes you intend to next "git add". To
catch potential problems early, safety triggers.
The concept of a safety check was originally proposed in a similar
way by Linus Torvalds. Thanks to Dimitry Potapov for insisting
on getting the naked LF/autocrlf=true case right.
Signed-off-by: Steffen Prohaska <prohaska@zib.de>
2008-02-06 12:25:58 +01:00
|
|
|
test_expect_success 'switch off autocrlf, safecrlf, reset HEAD' '
|
|
|
|
git config core.autocrlf false &&
|
|
|
|
git config core.safecrlf false &&
|
|
|
|
git reset --hard HEAD^
|
|
|
|
'
|
|
|
|
|
2007-02-14 23:54:00 +01:00
|
|
|
test_expect_success 'update with autocrlf=input' '
|
|
|
|
|
2007-04-20 07:37:19 +02:00
|
|
|
rm -f tmp one dir/two three &&
|
2007-02-14 23:54:00 +01:00
|
|
|
git read-tree --reset -u HEAD &&
|
2008-01-18 07:52:40 +01:00
|
|
|
git config core.autocrlf input &&
|
2015-03-25 06:28:44 +01:00
|
|
|
munge_cr append one &&
|
|
|
|
munge_cr append dir/two &&
|
|
|
|
git update-index -- one dir/two &&
|
2014-04-28 14:57:26 +02:00
|
|
|
differs=$(git diff-index --cached HEAD) &&
|
2015-03-20 11:13:08 +01:00
|
|
|
verbose test -z "$differs"
|
2007-02-14 23:54:00 +01:00
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'update with autocrlf=true' '
|
|
|
|
|
2007-04-20 07:37:19 +02:00
|
|
|
rm -f tmp one dir/two three &&
|
2007-02-14 23:54:00 +01:00
|
|
|
git read-tree --reset -u HEAD &&
|
2008-01-18 07:52:40 +01:00
|
|
|
git config core.autocrlf true &&
|
2015-03-25 06:28:44 +01:00
|
|
|
munge_cr append one &&
|
|
|
|
munge_cr append dir/two &&
|
|
|
|
git update-index -- one dir/two &&
|
2014-04-28 14:57:26 +02:00
|
|
|
differs=$(git diff-index --cached HEAD) &&
|
2015-03-20 11:13:08 +01:00
|
|
|
verbose test -z "$differs"
|
2007-02-14 23:54:00 +01:00
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'checkout with autocrlf=true' '
|
|
|
|
|
2007-04-20 07:37:19 +02:00
|
|
|
rm -f tmp one dir/two three &&
|
2008-01-18 07:52:40 +01:00
|
|
|
git config core.autocrlf true &&
|
2007-02-14 23:54:00 +01:00
|
|
|
git read-tree --reset -u HEAD &&
|
2015-03-25 06:28:44 +01:00
|
|
|
munge_cr remove one &&
|
|
|
|
munge_cr remove dir/two &&
|
|
|
|
git update-index -- one dir/two &&
|
2014-04-28 14:57:26 +02:00
|
|
|
test "$one" = $(git hash-object --stdin <one) &&
|
|
|
|
test "$two" = $(git hash-object --stdin <dir/two) &&
|
|
|
|
differs=$(git diff-index --cached HEAD) &&
|
2015-03-20 11:13:08 +01:00
|
|
|
verbose test -z "$differs"
|
2007-02-14 23:54:00 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'checkout with autocrlf=input' '
|
|
|
|
|
2007-04-20 07:37:19 +02:00
|
|
|
rm -f tmp one dir/two three &&
|
2008-01-18 07:52:40 +01:00
|
|
|
git config core.autocrlf input &&
|
2007-02-14 23:54:00 +01:00
|
|
|
git read-tree --reset -u HEAD &&
|
2019-12-20 19:15:53 +01:00
|
|
|
! has_cr one &&
|
|
|
|
! has_cr dir/two &&
|
2015-03-25 06:28:44 +01:00
|
|
|
git update-index -- one dir/two &&
|
2014-04-28 14:57:26 +02:00
|
|
|
test "$one" = $(git hash-object --stdin <one) &&
|
|
|
|
test "$two" = $(git hash-object --stdin <dir/two) &&
|
|
|
|
differs=$(git diff-index --cached HEAD) &&
|
2015-03-20 11:13:08 +01:00
|
|
|
verbose test -z "$differs"
|
2007-02-14 23:54:00 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'apply patch (autocrlf=input)' '
|
|
|
|
|
2007-04-20 07:37:19 +02:00
|
|
|
rm -f tmp one dir/two three &&
|
2008-01-18 07:52:40 +01:00
|
|
|
git config core.autocrlf input &&
|
2007-02-14 23:54:00 +01:00
|
|
|
git read-tree --reset -u HEAD &&
|
|
|
|
|
|
|
|
git apply patch.file &&
|
2015-03-20 11:13:08 +01:00
|
|
|
verbose test "$patched" = "$(git hash-object --stdin <one)"
|
2007-02-14 23:54:00 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'apply patch --cached (autocrlf=input)' '
|
|
|
|
|
2007-04-20 07:37:19 +02:00
|
|
|
rm -f tmp one dir/two three &&
|
2008-01-18 07:52:40 +01:00
|
|
|
git config core.autocrlf input &&
|
2007-02-14 23:54:00 +01:00
|
|
|
git read-tree --reset -u HEAD &&
|
|
|
|
|
|
|
|
git apply --cached patch.file &&
|
2015-03-20 11:13:08 +01:00
|
|
|
verbose test "$patched" = $(git rev-parse :one)
|
2007-02-14 23:54:00 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'apply patch --index (autocrlf=input)' '
|
|
|
|
|
2007-04-20 07:37:19 +02:00
|
|
|
rm -f tmp one dir/two three &&
|
2008-01-18 07:52:40 +01:00
|
|
|
git config core.autocrlf input &&
|
2007-02-14 23:54:00 +01:00
|
|
|
git read-tree --reset -u HEAD &&
|
|
|
|
|
|
|
|
git apply --index patch.file &&
|
2015-03-20 11:13:08 +01:00
|
|
|
verbose test "$patched" = $(git rev-parse :one) &&
|
|
|
|
verbose test "$patched" = $(git hash-object --stdin <one)
|
2007-02-14 23:54:00 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'apply patch (autocrlf=true)' '
|
|
|
|
|
2007-04-20 07:37:19 +02:00
|
|
|
rm -f tmp one dir/two three &&
|
2008-01-18 07:52:40 +01:00
|
|
|
git config core.autocrlf true &&
|
2007-02-14 23:54:00 +01:00
|
|
|
git read-tree --reset -u HEAD &&
|
|
|
|
|
|
|
|
git apply patch.file &&
|
2015-03-20 11:13:08 +01:00
|
|
|
verbose test "$patched" = "$(remove_cr <one | git hash-object --stdin)"
|
2007-02-14 23:54:00 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'apply patch --cached (autocrlf=true)' '
|
|
|
|
|
2007-04-20 07:37:19 +02:00
|
|
|
rm -f tmp one dir/two three &&
|
2008-01-18 07:52:40 +01:00
|
|
|
git config core.autocrlf true &&
|
2007-02-14 23:54:00 +01:00
|
|
|
git read-tree --reset -u HEAD &&
|
|
|
|
|
|
|
|
git apply --cached patch.file &&
|
2015-03-20 11:13:08 +01:00
|
|
|
verbose test "$patched" = $(git rev-parse :one)
|
2007-02-14 23:54:00 +01:00
|
|
|
'
|
|
|
|
|
2007-02-17 21:37:25 +01:00
|
|
|
test_expect_success 'apply patch --index (autocrlf=true)' '
|
|
|
|
|
2007-04-20 07:37:19 +02:00
|
|
|
rm -f tmp one dir/two three &&
|
2008-01-18 07:52:40 +01:00
|
|
|
git config core.autocrlf true &&
|
2007-02-17 21:37:25 +01:00
|
|
|
git read-tree --reset -u HEAD &&
|
|
|
|
|
|
|
|
git apply --index patch.file &&
|
2015-03-20 11:13:08 +01:00
|
|
|
verbose test "$patched" = $(git rev-parse :one) &&
|
|
|
|
verbose test "$patched" = "$(remove_cr <one | git hash-object --stdin)"
|
2007-02-17 21:37:25 +01:00
|
|
|
'
|
|
|
|
|
2007-04-13 07:30:05 +02:00
|
|
|
test_expect_success '.gitattributes says two is binary' '
|
|
|
|
|
2007-04-20 07:37:19 +02:00
|
|
|
rm -f tmp one dir/two three &&
|
2007-04-15 23:56:09 +02:00
|
|
|
echo "two -crlf" >.gitattributes &&
|
2008-01-18 07:52:40 +01:00
|
|
|
git config core.autocrlf true &&
|
2007-04-13 07:30:05 +02:00
|
|
|
git read-tree --reset -u HEAD &&
|
|
|
|
|
2019-12-20 19:15:53 +01:00
|
|
|
! has_cr dir/two &&
|
2015-03-25 06:31:41 +01:00
|
|
|
verbose has_cr one &&
|
2019-12-20 19:15:53 +01:00
|
|
|
! has_cr three
|
2007-04-20 07:37:19 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success '.gitattributes says two is input' '
|
|
|
|
|
|
|
|
rm -f tmp one dir/two three &&
|
|
|
|
echo "two crlf=input" >.gitattributes &&
|
|
|
|
git read-tree --reset -u HEAD &&
|
|
|
|
|
2019-12-20 19:15:53 +01:00
|
|
|
! has_cr dir/two
|
2007-04-20 07:37:19 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success '.gitattributes says two and three are text' '
|
|
|
|
|
|
|
|
rm -f tmp one dir/two three &&
|
|
|
|
echo "t* crlf" >.gitattributes &&
|
|
|
|
git read-tree --reset -u HEAD &&
|
|
|
|
|
2015-03-20 11:13:08 +01:00
|
|
|
verbose has_cr dir/two &&
|
|
|
|
verbose has_cr three
|
2007-04-13 07:30:05 +02:00
|
|
|
'
|
|
|
|
|
2007-08-14 10:41:02 +02:00
|
|
|
test_expect_success 'in-tree .gitattributes (1)' '
|
|
|
|
|
|
|
|
echo "one -crlf" >>.gitattributes &&
|
|
|
|
git add .gitattributes &&
|
|
|
|
git commit -m "Add .gitattributes" &&
|
|
|
|
|
|
|
|
rm -rf tmp one dir .gitattributes patch.file three &&
|
|
|
|
git read-tree --reset -u HEAD &&
|
|
|
|
|
2019-12-20 19:15:53 +01:00
|
|
|
! has_cr one &&
|
2015-03-20 11:13:08 +01:00
|
|
|
verbose has_cr three
|
2007-08-14 10:41:02 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'in-tree .gitattributes (2)' '
|
|
|
|
|
|
|
|
rm -rf tmp one dir .gitattributes patch.file three &&
|
|
|
|
git read-tree --reset HEAD &&
|
|
|
|
git checkout-index -f -q -u -a &&
|
|
|
|
|
2019-12-20 19:15:53 +01:00
|
|
|
! has_cr one &&
|
2015-03-20 11:13:08 +01:00
|
|
|
verbose has_cr three
|
2007-08-14 10:41:02 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'in-tree .gitattributes (3)' '
|
|
|
|
|
|
|
|
rm -rf tmp one dir .gitattributes patch.file three &&
|
|
|
|
git read-tree --reset HEAD &&
|
|
|
|
git checkout-index -u .gitattributes &&
|
|
|
|
git checkout-index -u one dir/two three &&
|
|
|
|
|
2019-12-20 19:15:53 +01:00
|
|
|
! has_cr one &&
|
2015-03-20 11:13:08 +01:00
|
|
|
verbose has_cr three
|
2007-08-14 10:41:02 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'in-tree .gitattributes (4)' '
|
|
|
|
|
|
|
|
rm -rf tmp one dir .gitattributes patch.file three &&
|
|
|
|
git read-tree --reset HEAD &&
|
|
|
|
git checkout-index -u one dir/two three &&
|
|
|
|
git checkout-index -u .gitattributes &&
|
|
|
|
|
2019-12-20 19:15:53 +01:00
|
|
|
! has_cr one &&
|
2015-03-20 11:13:08 +01:00
|
|
|
verbose has_cr three
|
2007-08-14 10:41:02 +02:00
|
|
|
'
|
|
|
|
|
2009-03-20 10:32:09 +01:00
|
|
|
test_expect_success 'checkout with existing .gitattributes' '
|
|
|
|
|
|
|
|
git config core.autocrlf true &&
|
|
|
|
git config --unset core.safecrlf &&
|
|
|
|
echo ".file2 -crlfQ" | q_to_cr >> .gitattributes &&
|
|
|
|
git add .gitattributes &&
|
|
|
|
git commit -m initial &&
|
|
|
|
echo ".file -crlfQ" | q_to_cr >> .gitattributes &&
|
|
|
|
echo "contents" > .file &&
|
|
|
|
git add .gitattributes .file &&
|
|
|
|
git commit -m second &&
|
|
|
|
|
|
|
|
git checkout master~1 &&
|
|
|
|
git checkout master &&
|
|
|
|
test "$(git diff-files --raw)" = ""
|
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'checkout when deleting .gitattributes' '
|
|
|
|
|
|
|
|
git rm .gitattributes &&
|
|
|
|
echo "contentsQ" | q_to_cr > .file2 &&
|
|
|
|
git add .file2 &&
|
2010-10-31 08:30:58 +01:00
|
|
|
git commit -m third &&
|
2009-03-20 10:32:09 +01:00
|
|
|
|
|
|
|
git checkout master~1 &&
|
|
|
|
git checkout master &&
|
2010-01-26 01:33:57 +01:00
|
|
|
has_cr .file2
|
2009-03-20 10:32:09 +01:00
|
|
|
|
|
|
|
'
|
|
|
|
|
2007-10-18 22:02:35 +02:00
|
|
|
test_expect_success 'invalid .gitattributes (must not crash)' '
|
|
|
|
|
|
|
|
echo "three +crlf" >>.gitattributes &&
|
|
|
|
git diff
|
|
|
|
|
|
|
|
'
|
autocrlf: Make it work also for un-normalized repositories
Previously, autocrlf would only work well for normalized
repositories. Any text files that contained CRLF in the repository
would cause problems, and would be modified when handled with
core.autocrlf set.
Change autocrlf to not do any conversions to files that in the
repository already contain a CR. git with autocrlf set will never
create such a file, or change a LF only file to contain CRs, so the
(new) assumption is that if a file contains a CR, it is intentional,
and autocrlf should not change that.
The following sequence should now always be a NOP even with autocrlf
set (assuming a clean working directory):
git checkout <something>
touch *
git add -A . (will add nothing)
git commit (nothing to commit)
Previously this would break for any text file containing a CR.
Some of you may have been folowing Eyvind's excellent thread about
trying to make end-of-line translation in git a bit smoother.
I decided to attack the problem from a different angle: Is it possible
to make autocrlf behave non-destructively for all the previous problem cases?
Stealing the problem from Eyvind's initial mail (paraphrased and
summarized a bit):
1. Setting autocrlf globally is a pain since autocrlf does not work well
with CRLF in the repo
2. Setting it in individual repos is hard since you do it "too late"
(the clone will get it wrong)
3. If someone checks in a file with CRLF later, you get into problems again
4. If a repository once has contained CRLF, you can't tell autocrlf
at which commit everything is sane again
5. autocrlf does needless work if you know that all your users want
the same EOL style.
I belive that this patch makes autocrlf a safe (and good) default
setting for Windows, and this solves problems 1-4 (it solves 2 by being
set by default, which is early enough for clone).
I implemented it by looking for CR charactes in the index, and
aborting any conversion attempt if this is found.
Signed-off-by: Finn Arne Gangstad <finag@pvv.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-05-12 00:37:57 +02:00
|
|
|
# Some more tests here to add new autocrlf functionality.
|
|
|
|
# We want to have a known state here, so start a bit from scratch
|
|
|
|
|
|
|
|
test_expect_success 'setting up for new autocrlf tests' '
|
|
|
|
git config core.autocrlf false &&
|
|
|
|
git config core.safecrlf false &&
|
|
|
|
rm -rf .????* * &&
|
|
|
|
for w in I am all LF; do echo $w; done >alllf &&
|
|
|
|
for w in Oh here is CRLFQ in text; do echo $w; done | q_to_cr >mixed &&
|
|
|
|
for w in I am all CRLF; do echo $w; done | append_cr >allcrlf &&
|
|
|
|
git add -A . &&
|
|
|
|
git commit -m "alllf, allcrlf and mixed only" &&
|
|
|
|
git tag -a -m "message" autocrlf-checkpoint
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'report no change after setting autocrlf' '
|
|
|
|
git config core.autocrlf true &&
|
|
|
|
touch * &&
|
|
|
|
git diff --exit-code
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'files are clean after checkout' '
|
|
|
|
rm * &&
|
|
|
|
git checkout -f &&
|
|
|
|
git diff --exit-code
|
|
|
|
'
|
|
|
|
|
|
|
|
cr_to_Q_no_NL () {
|
|
|
|
tr '\015' Q | tr -d '\012'
|
|
|
|
}
|
|
|
|
|
|
|
|
test_expect_success 'LF only file gets CRLF with autocrlf' '
|
|
|
|
test "$(cr_to_Q_no_NL < alllf)" = "IQamQallQLFQ"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'Mixed file is still mixed with autocrlf' '
|
|
|
|
test "$(cr_to_Q_no_NL < mixed)" = "OhhereisCRLFQintext"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'CRLF only file has CRLF with autocrlf' '
|
|
|
|
test "$(cr_to_Q_no_NL < allcrlf)" = "IQamQallQCRLFQ"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'New CRLF file gets LF in repo' '
|
|
|
|
tr -d "\015" < alllf | append_cr > alllf2 &&
|
|
|
|
git add alllf2 &&
|
|
|
|
git commit -m "alllf2 added" &&
|
|
|
|
git config core.autocrlf false &&
|
|
|
|
rm * &&
|
|
|
|
git checkout -f &&
|
|
|
|
test_cmp alllf alllf2
|
|
|
|
'
|
2007-10-18 22:02:35 +02:00
|
|
|
|
2007-02-14 23:54:00 +01:00
|
|
|
test_done
|