зеркало из https://github.com/microsoft/git.git
t0020: fix ignored exit code inside loops
A loop like: for f in one two; do something $f || break done will correctly break out of the loop when we see a failure of one item, but the resulting exit code will always be zero. We can fix that by putting the loop into a function or subshell, but in this case it is simpler still to just unroll the loop. We do add a helper function, which hopefully makes the end result even more readable (in addition to being shorter). Reported-by: SZEDER Gábor <szeder@ira.uka.de> Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Родитель
ecb590a9de
Коммит
fd7771415b
|
@ -8,6 +8,13 @@ has_cr() {
|
||||||
tr '\015' Q <"$1" | grep Q >/dev/null
|
tr '\015' Q <"$1" | grep Q >/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# add or remove CRs to disk file in-place
|
||||||
|
# usage: munge_cr <append|remove> <file>
|
||||||
|
munge_cr () {
|
||||||
|
"${1}_cr" <"$2" >tmp &&
|
||||||
|
mv tmp "$2"
|
||||||
|
}
|
||||||
|
|
||||||
test_expect_success setup '
|
test_expect_success setup '
|
||||||
|
|
||||||
git config core.autocrlf false &&
|
git config core.autocrlf false &&
|
||||||
|
@ -100,14 +107,9 @@ test_expect_success 'update with autocrlf=input' '
|
||||||
rm -f tmp one dir/two three &&
|
rm -f tmp one dir/two three &&
|
||||||
git read-tree --reset -u HEAD &&
|
git read-tree --reset -u HEAD &&
|
||||||
git config core.autocrlf input &&
|
git config core.autocrlf input &&
|
||||||
|
munge_cr append one &&
|
||||||
for f in one dir/two
|
munge_cr append dir/two &&
|
||||||
do
|
git update-index -- one dir/two &&
|
||||||
append_cr <$f >tmp && mv -f tmp $f &&
|
|
||||||
git update-index -- $f ||
|
|
||||||
break
|
|
||||||
done &&
|
|
||||||
|
|
||||||
differs=$(git diff-index --cached HEAD) &&
|
differs=$(git diff-index --cached HEAD) &&
|
||||||
verbose test -z "$differs"
|
verbose test -z "$differs"
|
||||||
|
|
||||||
|
@ -118,14 +120,9 @@ test_expect_success 'update with autocrlf=true' '
|
||||||
rm -f tmp one dir/two three &&
|
rm -f tmp one dir/two three &&
|
||||||
git read-tree --reset -u HEAD &&
|
git read-tree --reset -u HEAD &&
|
||||||
git config core.autocrlf true &&
|
git config core.autocrlf true &&
|
||||||
|
munge_cr append one &&
|
||||||
for f in one dir/two
|
munge_cr append dir/two &&
|
||||||
do
|
git update-index -- one dir/two &&
|
||||||
append_cr <$f >tmp && mv -f tmp $f &&
|
|
||||||
git update-index -- $f ||
|
|
||||||
break
|
|
||||||
done &&
|
|
||||||
|
|
||||||
differs=$(git diff-index --cached HEAD) &&
|
differs=$(git diff-index --cached HEAD) &&
|
||||||
verbose test -z "$differs"
|
verbose test -z "$differs"
|
||||||
|
|
||||||
|
@ -136,13 +133,9 @@ test_expect_success 'checkout with autocrlf=true' '
|
||||||
rm -f tmp one dir/two three &&
|
rm -f tmp one dir/two three &&
|
||||||
git config core.autocrlf true &&
|
git config core.autocrlf true &&
|
||||||
git read-tree --reset -u HEAD &&
|
git read-tree --reset -u HEAD &&
|
||||||
|
munge_cr remove one &&
|
||||||
for f in one dir/two
|
munge_cr remove dir/two &&
|
||||||
do
|
git update-index -- one dir/two &&
|
||||||
remove_cr <"$f" >tmp && mv -f tmp $f &&
|
|
||||||
verbose git update-index -- $f ||
|
|
||||||
break
|
|
||||||
done &&
|
|
||||||
test "$one" = $(git hash-object --stdin <one) &&
|
test "$one" = $(git hash-object --stdin <one) &&
|
||||||
test "$two" = $(git hash-object --stdin <dir/two) &&
|
test "$two" = $(git hash-object --stdin <dir/two) &&
|
||||||
differs=$(git diff-index --cached HEAD) &&
|
differs=$(git diff-index --cached HEAD) &&
|
||||||
|
@ -154,18 +147,9 @@ test_expect_success 'checkout with autocrlf=input' '
|
||||||
rm -f tmp one dir/two three &&
|
rm -f tmp one dir/two three &&
|
||||||
git config core.autocrlf input &&
|
git config core.autocrlf input &&
|
||||||
git read-tree --reset -u HEAD &&
|
git read-tree --reset -u HEAD &&
|
||||||
|
test_must_fail has_cr one &&
|
||||||
for f in one dir/two
|
test_must_fail has_cr two &&
|
||||||
do
|
git update-index -- one dir/two &&
|
||||||
if has_cr "$f"
|
|
||||||
then
|
|
||||||
echo "Eh? $f"
|
|
||||||
false
|
|
||||||
break
|
|
||||||
else
|
|
||||||
git update-index -- $f
|
|
||||||
fi
|
|
||||||
done &&
|
|
||||||
test "$one" = $(git hash-object --stdin <one) &&
|
test "$one" = $(git hash-object --stdin <one) &&
|
||||||
test "$two" = $(git hash-object --stdin <dir/two) &&
|
test "$two" = $(git hash-object --stdin <dir/two) &&
|
||||||
differs=$(git diff-index --cached HEAD) &&
|
differs=$(git diff-index --cached HEAD) &&
|
||||||
|
|
Загрузка…
Ссылка в новой задаче