@ -4,21 +4,8 @@ test_description='CRLF conversion'
. ./test-lib.sh
. ./test-lib.sh
q_to_nul () {
has_cr() {
perl -pe 'y/Q/\000/'
tr '\015' Q <"$1" | grep Q >/dev/null
}
q_to_cr () {
tr Q '\015'
}
append_cr () {
sed -e 's/$/Q/' | tr Q '\015'
}
remove_cr () {
tr '\015' Q <"$1" | grep Q >/dev/null &&
tr '\015' Q <"$1" | sed -ne 's/Q$//p'
}
}
test_expect_success setup '
test_expect_success setup '
@ -156,7 +143,7 @@ test_expect_success 'checkout with autocrlf=true' '
for f in one dir/two
for f in one dir/two
do
do
remove_cr "$f" >tmp && mv -f tmp $f &&
remove_cr <"$f" >tmp && mv -f tmp $f &&
git update-index -- $f || {
git update-index -- $f || {
echo "Eh? $f"
echo "Eh? $f"
false
false
@ -180,7 +167,7 @@ test_expect_success 'checkout with autocrlf=input' '
for f in one dir/two
for f in one dir/two
do
do
if remove_cr "$f" >/dev/null
if has_cr "$f"
then
then
echo "Eh? $f"
echo "Eh? $f"
false
false
@ -245,7 +232,7 @@ test_expect_success 'apply patch (autocrlf=true)' '
git read-tree --reset -u HEAD &&
git read-tree --reset -u HEAD &&
git apply patch.file &&
git apply patch.file &&
test "$patched" = "`remove_cr one | git hash-object --stdin`" || {
test "$patched" = "`remove_cr <one | git hash-object --stdin`" || {
echo "Eh? apply without index"
echo "Eh? apply without index"
false
false
}
}
@ -272,7 +259,7 @@ test_expect_success 'apply patch --index (autocrlf=true)' '
git apply --index patch.file &&
git apply --index patch.file &&
test "$patched" = `git rev-parse :one` &&
test "$patched" = `git rev-parse :one` &&
test "$patched" = "`remove_cr one | git hash-object --stdin`" || {
test "$patched" = "`remove_cr <one | git hash-object --stdin`" || {
echo "Eh? apply with --index"
echo "Eh? apply with --index"
false
false
}
}
@ -285,7 +272,7 @@ test_expect_success '.gitattributes says two is binary' '
git config core.autocrlf true &&
git config core.autocrlf true &&
git read-tree --reset -u HEAD &&
git read-tree --reset -u HEAD &&
if remove_cr dir/two >/dev/null
if has_cr dir/two
then
then
echo "Huh?"
echo "Huh?"
false
false
@ -293,7 +280,7 @@ test_expect_success '.gitattributes says two is binary' '
: happy
: happy
fi &&
fi &&
if remove_cr one >/dev/null
if has_cr one
then
then
: happy
: happy
else
else
@ -301,7 +288,7 @@ test_expect_success '.gitattributes says two is binary' '
false
false
fi &&
fi &&
if remove_cr three >/dev/null
if has_cr three
then
then
echo "Huh?"
echo "Huh?"
false
false
@ -316,7 +303,7 @@ test_expect_success '.gitattributes says two is input' '
echo "two crlf=input" >.gitattributes &&
echo "two crlf=input" >.gitattributes &&
git read-tree --reset -u HEAD &&
git read-tree --reset -u HEAD &&
if remove_cr dir/two >/dev/null
if has_cr dir/two
then
then
echo "Huh?"
echo "Huh?"
false
false
@ -331,7 +318,7 @@ test_expect_success '.gitattributes says two and three are text' '
echo "t* crlf" >.gitattributes &&
echo "t* crlf" >.gitattributes &&
git read-tree --reset -u HEAD &&
git read-tree --reset -u HEAD &&
if remove_cr dir/two >/dev/null
if has_cr dir/two
then
then
: happy
: happy
else
else
@ -339,7 +326,7 @@ test_expect_success '.gitattributes says two and three are text' '
false
false
fi &&
fi &&
if remove_cr three >/dev/null
if has_cr three
then
then
: happy
: happy
else
else
@ -357,14 +344,14 @@ test_expect_success 'in-tree .gitattributes (1)' '
rm -rf tmp one dir .gitattributes patch.file three &&
rm -rf tmp one dir .gitattributes patch.file three &&
git read-tree --reset -u HEAD &&
git read-tree --reset -u HEAD &&
if remove_cr one >/dev/null
if has_cr one
then
then
echo "Eh? one should not have CRLF"
echo "Eh? one should not have CRLF"
false
false
else
else
: happy
: happy
fi &&
fi &&
remove_cr three >/dev/null || {
has_cr three || {
echo "Eh? three should still have CRLF"
echo "Eh? three should still have CRLF"
false
false
}
}
@ -376,14 +363,14 @@ test_expect_success 'in-tree .gitattributes (2)' '
git read-tree --reset HEAD &&
git read-tree --reset HEAD &&
git checkout-index -f -q -u -a &&
git checkout-index -f -q -u -a &&
if remove_cr one >/dev/null
if has_cr one
then
then
echo "Eh? one should not have CRLF"
echo "Eh? one should not have CRLF"
false
false
else
else
: happy
: happy
fi &&
fi &&
remove_cr three >/dev/null || {
has_cr three || {
echo "Eh? three should still have CRLF"
echo "Eh? three should still have CRLF"
false
false
}
}
@ -396,14 +383,14 @@ test_expect_success 'in-tree .gitattributes (3)' '
git checkout-index -u .gitattributes &&
git checkout-index -u .gitattributes &&
git checkout-index -u one dir/two three &&
git checkout-index -u one dir/two three &&
if remove_cr one >/dev/null
if has_cr one
then
then
echo "Eh? one should not have CRLF"
echo "Eh? one should not have CRLF"
false
false
else
else
: happy
: happy
fi &&
fi &&
remove_cr three >/dev/null || {
has_cr three || {
echo "Eh? three should still have CRLF"
echo "Eh? three should still have CRLF"
false
false
}
}
@ -416,14 +403,14 @@ test_expect_success 'in-tree .gitattributes (4)' '
git checkout-index -u one dir/two three &&
git checkout-index -u one dir/two three &&
git checkout-index -u .gitattributes &&
git checkout-index -u .gitattributes &&
if remove_cr one >/dev/null
if has_cr one
then
then
echo "Eh? one should not have CRLF"
echo "Eh? one should not have CRLF"
false
false
else
else
: happy
: happy
fi &&
fi &&
remove_cr three >/dev/null || {
has_cr three || {
echo "Eh? three should still have CRLF"
echo "Eh? three should still have CRLF"
false
false
}
}
@ -456,7 +443,7 @@ test_expect_success 'checkout when deleting .gitattributes' '
git checkout master~1 &&
git checkout master~1 &&
git checkout master &&
git checkout master &&
remove_cr .file2 >/dev/null
has_cr .file2
'
'