attr.c: read .gitattributes from index as well.

This makes .gitattributes files to be read from the index when
they are not checked out to the work tree.  This is in line with
the way we always allowed low-level tools to operate in sparsely
checked out work tree in a reasonable way.

It swaps the order of new file creation and converting the blob
to work tree representation; otherwise when we are in the middle
of checking out .gitattributes we would notice an empty but
unwritten .gitattributes file in the work tree and will ignore
the copy in the index.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Junio C Hamano
2007-08-14 01:41:02 -07:00
parent a44131181a
commit 1a9d7e9b48
3 changed files with 150 additions and 11 deletions

View File

@ -290,4 +290,85 @@ test_expect_success '.gitattributes says two and three are text' '
fi
'
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 &&
if remove_cr one >/dev/null
then
echo "Eh? one should not have CRLF"
false
else
: happy
fi &&
remove_cr three >/dev/null || {
echo "Eh? three should still have CRLF"
false
}
'
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 &&
if remove_cr one >/dev/null
then
echo "Eh? one should not have CRLF"
false
else
: happy
fi &&
remove_cr three >/dev/null || {
echo "Eh? three should still have CRLF"
false
}
'
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 &&
if remove_cr one >/dev/null
then
echo "Eh? one should not have CRLF"
false
else
: happy
fi &&
remove_cr three >/dev/null || {
echo "Eh? three should still have CRLF"
false
}
'
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 &&
if remove_cr one >/dev/null
then
echo "Eh? one should not have CRLF"
false
else
: happy
fi &&
remove_cr three >/dev/null || {
echo "Eh? three should still have CRLF"
false
}
'
test_done