2007-04-22 04:09:02 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='blob conversion via gitattributes'
|
|
|
|
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
2016-11-11 18:31:48 +01:00
|
|
|
TEST_ROOT="$PWD"
|
2016-11-02 19:18:25 +01:00
|
|
|
PATH=$TEST_ROOT:$PATH
|
2016-10-17 01:20:37 +02:00
|
|
|
|
2016-11-02 19:17:51 +01:00
|
|
|
write_script <<\EOF "$TEST_ROOT/rot13.sh"
|
2008-03-11 18:40:45 +01:00
|
|
|
tr \
|
|
|
|
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' \
|
|
|
|
'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM'
|
2007-04-21 12:14:13 +02:00
|
|
|
EOF
|
2016-10-17 01:20:37 +02:00
|
|
|
|
2016-11-02 19:20:22 +01:00
|
|
|
write_script rot13-filter.pl "$PERL_PATH" \
|
|
|
|
<"$TEST_DIRECTORY"/t0021/rot13-filter.pl
|
2016-10-17 01:20:37 +02:00
|
|
|
|
|
|
|
generate_random_characters () {
|
|
|
|
LEN=$1
|
|
|
|
NAME=$2
|
2018-03-24 08:44:42 +01:00
|
|
|
test-tool genrandom some-seed $LEN |
|
2016-10-17 01:20:37 +02:00
|
|
|
perl -pe "s/./chr((ord($&) % 26) + ord('a'))/sge" >"$TEST_ROOT/$NAME"
|
|
|
|
}
|
|
|
|
|
|
|
|
file_size () {
|
2019-01-29 15:19:33 +01:00
|
|
|
test-tool path-utils file-size "$1"
|
2016-10-17 01:20:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
filter_git () {
|
2017-06-01 10:22:00 +02:00
|
|
|
rm -f *.log &&
|
2016-11-11 22:07:37 +01:00
|
|
|
git "$@"
|
2016-10-17 01:20:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Compare two files and ensure that `clean` and `smudge` respectively are
|
|
|
|
# called at least once if specified in the `expect` file. The actual
|
|
|
|
# invocation count is not relevant because their number can vary.
|
2019-11-27 13:54:04 +01:00
|
|
|
# c.f. http://lore.kernel.org/git/xmqqshv18i8i.fsf@gitster.mtv.corp.google.com/
|
2016-10-17 01:20:37 +02:00
|
|
|
test_cmp_count () {
|
|
|
|
expect=$1
|
|
|
|
actual=$2
|
|
|
|
for FILE in "$expect" "$actual"
|
|
|
|
do
|
2016-11-03 21:12:13 +01:00
|
|
|
sort "$FILE" | uniq -c |
|
2017-06-01 10:21:59 +02:00
|
|
|
sed -e "s/^ *[0-9][0-9]*[ ]*IN: /x IN: /" >"$FILE.tmp"
|
2016-10-17 01:20:37 +02:00
|
|
|
done &&
|
2017-06-01 10:21:59 +02:00
|
|
|
test_cmp "$expect.tmp" "$actual.tmp" &&
|
|
|
|
rm "$expect.tmp" "$actual.tmp"
|
2016-10-17 01:20:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Compare two files but exclude all `clean` invocations because Git can
|
|
|
|
# call `clean` zero or more times.
|
2019-11-27 13:54:04 +01:00
|
|
|
# c.f. http://lore.kernel.org/git/xmqqshv18i8i.fsf@gitster.mtv.corp.google.com/
|
2016-10-17 01:20:37 +02:00
|
|
|
test_cmp_exclude_clean () {
|
|
|
|
expect=$1
|
|
|
|
actual=$2
|
|
|
|
for FILE in "$expect" "$actual"
|
|
|
|
do
|
2017-06-01 10:21:59 +02:00
|
|
|
grep -v "IN: clean" "$FILE" >"$FILE.tmp"
|
2016-10-17 01:20:37 +02:00
|
|
|
done &&
|
2017-06-01 10:21:59 +02:00
|
|
|
test_cmp "$expect.tmp" "$actual.tmp" &&
|
|
|
|
rm "$expect.tmp" "$actual.tmp"
|
2016-10-17 01:20:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Check that the contents of two files are equal and that their rot13 version
|
|
|
|
# is equal to the committed content.
|
|
|
|
test_cmp_committed_rot13 () {
|
|
|
|
test_cmp "$1" "$2" &&
|
2016-11-02 19:18:25 +01:00
|
|
|
rot13.sh <"$1" >expected &&
|
2016-10-17 01:20:37 +02:00
|
|
|
git cat-file blob :"$2" >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
}
|
2007-04-21 12:14:13 +02:00
|
|
|
|
2007-04-22 04:09:02 +02:00
|
|
|
test_expect_success setup '
|
2007-04-21 12:14:13 +02:00
|
|
|
git config filter.rot13.smudge ./rot13.sh &&
|
|
|
|
git config filter.rot13.clean ./rot13.sh &&
|
|
|
|
|
2007-04-22 04:09:02 +02:00
|
|
|
{
|
2007-04-21 12:14:13 +02:00
|
|
|
echo "*.t filter=rot13"
|
2007-04-22 04:09:02 +02:00
|
|
|
echo "*.i ident"
|
|
|
|
} >.gitattributes &&
|
|
|
|
|
|
|
|
{
|
|
|
|
echo a b c d e f g h i j k l m
|
|
|
|
echo n o p q r s t u v w x y z
|
2007-05-14 15:37:25 +02:00
|
|
|
echo '\''$Id$'\''
|
2007-04-22 04:09:02 +02:00
|
|
|
} >test &&
|
|
|
|
cat test >test.t &&
|
|
|
|
cat test >test.o &&
|
|
|
|
cat test >test.i &&
|
|
|
|
git add test test.t test.i &&
|
|
|
|
rm -f test test.t test.i &&
|
2016-10-17 01:20:37 +02:00
|
|
|
git checkout -- test test.t test.i &&
|
|
|
|
|
|
|
|
echo "content-test2" >test2.o &&
|
2016-12-03 20:45:16 +01:00
|
|
|
echo "content-test3 - filename with special characters" >"test3 '\''sq'\'',\$x=.o"
|
2007-04-22 04:09:02 +02:00
|
|
|
'
|
|
|
|
|
2007-05-14 15:37:25 +02:00
|
|
|
script='s/^\$Id: \([0-9a-f]*\) \$/\1/p'
|
2007-04-22 04:09:02 +02:00
|
|
|
|
|
|
|
test_expect_success check '
|
|
|
|
|
2016-10-17 01:20:26 +02:00
|
|
|
test_cmp test.o test &&
|
|
|
|
test_cmp test.o test.t &&
|
2007-04-22 04:09:02 +02:00
|
|
|
|
|
|
|
# ident should be stripped in the repository
|
|
|
|
git diff --raw --exit-code :test :test.i &&
|
|
|
|
id=$(git rev-parse --verify :test) &&
|
|
|
|
embedded=$(sed -ne "$script" test.i) &&
|
2007-10-19 21:48:04 +02:00
|
|
|
test "z$id" = "z$embedded" &&
|
|
|
|
|
2016-10-17 01:20:26 +02:00
|
|
|
git cat-file blob :test.t >test.r &&
|
2007-10-19 21:48:04 +02:00
|
|
|
|
2016-10-17 01:20:26 +02:00
|
|
|
./rot13.sh <test.o >test.t &&
|
|
|
|
test_cmp test.r test.t
|
2007-04-22 04:09:02 +02:00
|
|
|
'
|
|
|
|
|
2007-05-27 12:52:11 +02:00
|
|
|
# If an expanded ident ever gets into the repository, we want to make sure that
|
|
|
|
# it is collapsed before being expanded again on checkout
|
|
|
|
test_expect_success expanded_in_repo '
|
|
|
|
{
|
|
|
|
echo "File with expanded keywords"
|
|
|
|
echo "\$Id\$"
|
|
|
|
echo "\$Id:\$"
|
|
|
|
echo "\$Id: 0000000000000000000000000000000000000000 \$"
|
|
|
|
echo "\$Id: NoSpaceAtEnd\$"
|
|
|
|
echo "\$Id:NoSpaceAtFront \$"
|
|
|
|
echo "\$Id:NoSpaceAtEitherEnd\$"
|
|
|
|
echo "\$Id: NoTerminatingSymbol"
|
2010-04-06 14:46:37 +02:00
|
|
|
echo "\$Id: Foreign Commit With Spaces \$"
|
2011-05-25 03:02:48 +02:00
|
|
|
} >expanded-keywords.0 &&
|
2007-05-27 12:52:11 +02:00
|
|
|
|
2011-05-25 03:02:48 +02:00
|
|
|
{
|
|
|
|
cat expanded-keywords.0 &&
|
|
|
|
printf "\$Id: NoTerminatingSymbolAtEOF"
|
|
|
|
} >expanded-keywords &&
|
|
|
|
cat expanded-keywords >expanded-keywords-crlf &&
|
|
|
|
git add expanded-keywords expanded-keywords-crlf &&
|
2011-05-21 23:25:06 +02:00
|
|
|
git commit -m "File with keywords expanded" &&
|
|
|
|
id=$(git rev-parse --verify :expanded-keywords) &&
|
|
|
|
|
2007-05-27 12:52:11 +02:00
|
|
|
{
|
|
|
|
echo "File with expanded keywords"
|
2011-05-21 23:25:06 +02:00
|
|
|
echo "\$Id: $id \$"
|
|
|
|
echo "\$Id: $id \$"
|
|
|
|
echo "\$Id: $id \$"
|
|
|
|
echo "\$Id: $id \$"
|
|
|
|
echo "\$Id: $id \$"
|
|
|
|
echo "\$Id: $id \$"
|
2007-05-27 12:52:11 +02:00
|
|
|
echo "\$Id: NoTerminatingSymbol"
|
2010-04-06 14:46:38 +02:00
|
|
|
echo "\$Id: Foreign Commit With Spaces \$"
|
2011-05-25 03:02:48 +02:00
|
|
|
} >expected-output.0 &&
|
|
|
|
{
|
|
|
|
cat expected-output.0 &&
|
2011-05-21 23:25:06 +02:00
|
|
|
printf "\$Id: NoTerminatingSymbolAtEOF"
|
2011-05-25 03:02:48 +02:00
|
|
|
} >expected-output &&
|
|
|
|
{
|
|
|
|
append_cr <expected-output.0 &&
|
|
|
|
printf "\$Id: NoTerminatingSymbolAtEOF"
|
|
|
|
} >expected-output-crlf &&
|
|
|
|
{
|
|
|
|
echo "expanded-keywords ident"
|
|
|
|
echo "expanded-keywords-crlf ident text eol=crlf"
|
|
|
|
} >>.gitattributes &&
|
2007-05-27 12:52:11 +02:00
|
|
|
|
2011-05-25 03:02:48 +02:00
|
|
|
rm -f expanded-keywords expanded-keywords-crlf &&
|
2007-05-27 12:52:11 +02:00
|
|
|
|
|
|
|
git checkout -- expanded-keywords &&
|
2018-10-05 23:54:04 +02:00
|
|
|
test_cmp expected-output expanded-keywords &&
|
2011-05-25 03:02:48 +02:00
|
|
|
|
|
|
|
git checkout -- expanded-keywords-crlf &&
|
2018-10-05 23:54:04 +02:00
|
|
|
test_cmp expected-output-crlf expanded-keywords-crlf
|
2007-05-27 12:52:11 +02:00
|
|
|
'
|
|
|
|
|
2010-12-22 15:40:13 +01:00
|
|
|
# The use of %f in a filter definition is expanded to the path to
|
|
|
|
# the filename being smudged or cleaned. It must be shell escaped.
|
|
|
|
# First, set up some interesting file names and pet them in
|
|
|
|
# .gitattributes.
|
|
|
|
test_expect_success 'filter shell-escaped filenames' '
|
|
|
|
cat >argc.sh <<-EOF &&
|
|
|
|
#!$SHELL_PATH
|
2010-12-23 00:18:47 +01:00
|
|
|
cat >/dev/null
|
2010-12-22 15:40:13 +01:00
|
|
|
echo argc: \$# "\$@"
|
|
|
|
EOF
|
|
|
|
normal=name-no-magic &&
|
|
|
|
special="name with '\''sq'\'' and \$x" &&
|
|
|
|
echo some test text >"$normal" &&
|
|
|
|
echo some test text >"$special" &&
|
|
|
|
git add "$normal" "$special" &&
|
|
|
|
git commit -q -m "add files" &&
|
|
|
|
echo "name* filter=argc" >.gitattributes &&
|
|
|
|
|
|
|
|
# delete the files and check them out again, using a smudge filter
|
|
|
|
# that will count the args and echo the command-line back to us
|
2016-10-17 01:20:26 +02:00
|
|
|
test_config filter.argc.smudge "sh ./argc.sh %f" &&
|
2010-12-22 15:40:13 +01:00
|
|
|
rm "$normal" "$special" &&
|
|
|
|
git checkout -- "$normal" "$special" &&
|
|
|
|
|
|
|
|
# make sure argc.sh counted the right number of args
|
|
|
|
echo "argc: 1 $normal" >expect &&
|
|
|
|
test_cmp expect "$normal" &&
|
|
|
|
echo "argc: 1 $special" >expect &&
|
|
|
|
test_cmp expect "$special" &&
|
|
|
|
|
|
|
|
# do the same thing, but with more args in the filter expression
|
2016-10-17 01:20:26 +02:00
|
|
|
test_config filter.argc.smudge "sh ./argc.sh %f --my-extra-arg" &&
|
2010-12-22 15:40:13 +01:00
|
|
|
rm "$normal" "$special" &&
|
|
|
|
git checkout -- "$normal" "$special" &&
|
|
|
|
|
|
|
|
# make sure argc.sh counted the right number of args
|
|
|
|
echo "argc: 2 $normal --my-extra-arg" >expect &&
|
|
|
|
test_cmp expect "$normal" &&
|
|
|
|
echo "argc: 2 $special --my-extra-arg" >expect &&
|
|
|
|
test_cmp expect "$special" &&
|
|
|
|
:
|
|
|
|
'
|
|
|
|
|
2014-08-26 17:23:25 +02:00
|
|
|
test_expect_success 'required filter should filter data' '
|
2016-10-17 01:20:26 +02:00
|
|
|
test_config filter.required.smudge ./rot13.sh &&
|
|
|
|
test_config filter.required.clean ./rot13.sh &&
|
|
|
|
test_config filter.required.required true &&
|
Add a setting to require a filter to be successful
By default, a missing filter driver or a failure from the filter driver is
not an error, but merely makes the filter operation a no-op pass through.
This is useful to massage the content into a shape that is more convenient
for the platform, filesystem, and the user to use, and the content filter
mechanism is not used to turn something unusable into usable.
However, we could also use of the content filtering mechanism and store
the content that cannot be directly used in the repository (e.g. a UUID
that refers to the true content stored outside git, or an encrypted
content) and turn it into a usable form upon checkout (e.g. download the
external content, or decrypt the encrypted content). For such a use case,
the content cannot be used when filter driver fails, and we need a way to
tell Git to abort the whole operation for such a failing or missing filter
driver.
Add a new "filter.<driver>.required" configuration variable to mark the
second use case. When it is set, git will abort the operation when the
filter driver does not exist or exits with a non-zero status code.
Signed-off-by: Jehan Bing <jehan@orb.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-02-17 02:19:03 +01:00
|
|
|
|
|
|
|
echo "*.r filter=required" >.gitattributes &&
|
|
|
|
|
2014-08-26 17:23:25 +02:00
|
|
|
cat test.o >test.r &&
|
Add a setting to require a filter to be successful
By default, a missing filter driver or a failure from the filter driver is
not an error, but merely makes the filter operation a no-op pass through.
This is useful to massage the content into a shape that is more convenient
for the platform, filesystem, and the user to use, and the content filter
mechanism is not used to turn something unusable into usable.
However, we could also use of the content filtering mechanism and store
the content that cannot be directly used in the repository (e.g. a UUID
that refers to the true content stored outside git, or an encrypted
content) and turn it into a usable form upon checkout (e.g. download the
external content, or decrypt the encrypted content). For such a use case,
the content cannot be used when filter driver fails, and we need a way to
tell Git to abort the whole operation for such a failing or missing filter
driver.
Add a new "filter.<driver>.required" configuration variable to mark the
second use case. When it is set, git will abort the operation when the
filter driver does not exist or exits with a non-zero status code.
Signed-off-by: Jehan Bing <jehan@orb.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-02-17 02:19:03 +01:00
|
|
|
git add test.r &&
|
2014-08-26 17:23:25 +02:00
|
|
|
|
Add a setting to require a filter to be successful
By default, a missing filter driver or a failure from the filter driver is
not an error, but merely makes the filter operation a no-op pass through.
This is useful to massage the content into a shape that is more convenient
for the platform, filesystem, and the user to use, and the content filter
mechanism is not used to turn something unusable into usable.
However, we could also use of the content filtering mechanism and store
the content that cannot be directly used in the repository (e.g. a UUID
that refers to the true content stored outside git, or an encrypted
content) and turn it into a usable form upon checkout (e.g. download the
external content, or decrypt the encrypted content). For such a use case,
the content cannot be used when filter driver fails, and we need a way to
tell Git to abort the whole operation for such a failing or missing filter
driver.
Add a new "filter.<driver>.required" configuration variable to mark the
second use case. When it is set, git will abort the operation when the
filter driver does not exist or exits with a non-zero status code.
Signed-off-by: Jehan Bing <jehan@orb.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-02-17 02:19:03 +01:00
|
|
|
rm -f test.r &&
|
2014-08-26 17:23:25 +02:00
|
|
|
git checkout -- test.r &&
|
2016-10-17 01:20:26 +02:00
|
|
|
test_cmp test.o test.r &&
|
2014-08-26 17:23:25 +02:00
|
|
|
|
|
|
|
./rot13.sh <test.o >expected &&
|
|
|
|
git cat-file blob :test.r >actual &&
|
2016-10-17 01:20:26 +02:00
|
|
|
test_cmp expected actual
|
Add a setting to require a filter to be successful
By default, a missing filter driver or a failure from the filter driver is
not an error, but merely makes the filter operation a no-op pass through.
This is useful to massage the content into a shape that is more convenient
for the platform, filesystem, and the user to use, and the content filter
mechanism is not used to turn something unusable into usable.
However, we could also use of the content filtering mechanism and store
the content that cannot be directly used in the repository (e.g. a UUID
that refers to the true content stored outside git, or an encrypted
content) and turn it into a usable form upon checkout (e.g. download the
external content, or decrypt the encrypted content). For such a use case,
the content cannot be used when filter driver fails, and we need a way to
tell Git to abort the whole operation for such a failing or missing filter
driver.
Add a new "filter.<driver>.required" configuration variable to mark the
second use case. When it is set, git will abort the operation when the
filter driver does not exist or exits with a non-zero status code.
Signed-off-by: Jehan Bing <jehan@orb.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-02-17 02:19:03 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'required filter smudge failure' '
|
2016-10-17 01:20:26 +02:00
|
|
|
test_config filter.failsmudge.smudge false &&
|
|
|
|
test_config filter.failsmudge.clean cat &&
|
|
|
|
test_config filter.failsmudge.required true &&
|
Add a setting to require a filter to be successful
By default, a missing filter driver or a failure from the filter driver is
not an error, but merely makes the filter operation a no-op pass through.
This is useful to massage the content into a shape that is more convenient
for the platform, filesystem, and the user to use, and the content filter
mechanism is not used to turn something unusable into usable.
However, we could also use of the content filtering mechanism and store
the content that cannot be directly used in the repository (e.g. a UUID
that refers to the true content stored outside git, or an encrypted
content) and turn it into a usable form upon checkout (e.g. download the
external content, or decrypt the encrypted content). For such a use case,
the content cannot be used when filter driver fails, and we need a way to
tell Git to abort the whole operation for such a failing or missing filter
driver.
Add a new "filter.<driver>.required" configuration variable to mark the
second use case. When it is set, git will abort the operation when the
filter driver does not exist or exits with a non-zero status code.
Signed-off-by: Jehan Bing <jehan@orb.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-02-17 02:19:03 +01:00
|
|
|
|
|
|
|
echo "*.fs filter=failsmudge" >.gitattributes &&
|
|
|
|
|
|
|
|
echo test >test.fs &&
|
|
|
|
git add test.fs &&
|
|
|
|
rm -f test.fs &&
|
|
|
|
test_must_fail git checkout -- test.fs
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'required filter clean failure' '
|
2016-10-17 01:20:26 +02:00
|
|
|
test_config filter.failclean.smudge cat &&
|
|
|
|
test_config filter.failclean.clean false &&
|
|
|
|
test_config filter.failclean.required true &&
|
Add a setting to require a filter to be successful
By default, a missing filter driver or a failure from the filter driver is
not an error, but merely makes the filter operation a no-op pass through.
This is useful to massage the content into a shape that is more convenient
for the platform, filesystem, and the user to use, and the content filter
mechanism is not used to turn something unusable into usable.
However, we could also use of the content filtering mechanism and store
the content that cannot be directly used in the repository (e.g. a UUID
that refers to the true content stored outside git, or an encrypted
content) and turn it into a usable form upon checkout (e.g. download the
external content, or decrypt the encrypted content). For such a use case,
the content cannot be used when filter driver fails, and we need a way to
tell Git to abort the whole operation for such a failing or missing filter
driver.
Add a new "filter.<driver>.required" configuration variable to mark the
second use case. When it is set, git will abort the operation when the
filter driver does not exist or exits with a non-zero status code.
Signed-off-by: Jehan Bing <jehan@orb.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-02-17 02:19:03 +01:00
|
|
|
|
|
|
|
echo "*.fc filter=failclean" >.gitattributes &&
|
|
|
|
|
|
|
|
echo test >test.fc &&
|
|
|
|
test_must_fail git add test.fc
|
|
|
|
'
|
|
|
|
|
2014-08-26 17:23:25 +02:00
|
|
|
test_expect_success 'filtering large input to small output should use little memory' '
|
2016-10-17 01:20:26 +02:00
|
|
|
test_config filter.devnull.clean "cat >/dev/null" &&
|
|
|
|
test_config filter.devnull.required true &&
|
2014-08-26 17:23:25 +02:00
|
|
|
for i in $(test_seq 1 30); do printf "%1048576d" 1; done >30MB &&
|
|
|
|
echo "30MB filter=devnull" >.gitattributes &&
|
|
|
|
GIT_MMAP_LIMIT=1m GIT_ALLOC_LIMIT=1m git add 30MB
|
|
|
|
'
|
|
|
|
|
2015-05-19 20:08:23 +02:00
|
|
|
test_expect_success 'filter that does not read is fine' '
|
2018-03-24 08:44:42 +01:00
|
|
|
test-tool genrandom foo $((128 * 1024 + 1)) >big &&
|
2015-05-19 20:08:23 +02:00
|
|
|
echo "big filter=epipe" >.gitattributes &&
|
2016-10-17 01:20:26 +02:00
|
|
|
test_config filter.epipe.clean "echo xyzzy" &&
|
2015-05-19 20:08:23 +02:00
|
|
|
git add big &&
|
|
|
|
git cat-file blob :big >actual &&
|
|
|
|
echo xyzzy >expect &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
xread, xwrite: limit size of IO to 8MB
Checking out 2GB or more through an external filter (see test) fails
on Mac OS X 10.8.4 (12E55) for a 64-bit executable with:
error: read from external filter cat failed
error: cannot feed the input to external filter cat
error: cat died of signal 13
error: external filter cat failed 141
error: external filter cat failed
The reason is that read() immediately returns with EINVAL when asked
to read more than 2GB. According to POSIX [1], if the value of
nbyte passed to read() is greater than SSIZE_MAX, the result is
implementation-defined. The write function has the same restriction
[2]. Since OS X still supports running 32-bit executables, the
32-bit limit (SSIZE_MAX = INT_MAX = 2GB - 1) seems to be also
imposed on 64-bit executables under certain conditions. For write,
the problem has been addressed earlier [6c642a].
Address the problem for read() and write() differently, by limiting
size of IO chunks unconditionally on all platforms in xread() and
xwrite(). Large chunks only cause problems, like causing latencies
when killing the process, even if OS X was not buggy. Doing IO in
reasonably sized smaller chunks should have no negative impact on
performance.
The compat wrapper clipped_write() introduced earlier [6c642a] is
not needed anymore. It will be reverted in a separate commit. The
new test catches read and write problems.
Note that 'git add' exits with 0 even if it prints filtering errors
to stderr. The test, therefore, checks stderr. 'git add' should
probably be changed (sometime in another commit) to exit with
nonzero if filtering fails. The test could then be changed to use
test_must_fail.
Thanks to the following people for suggestions and testing:
Johannes Sixt <j6t@kdbg.org>
John Keeping <john@keeping.me.uk>
Jonathan Nieder <jrnieder@gmail.com>
Kyle J. McKay <mackyle@gmail.com>
Linus Torvalds <torvalds@linux-foundation.org>
Torsten Bögershausen <tboegi@web.de>
[1] http://pubs.opengroup.org/onlinepubs/009695399/functions/read.html
[2] http://pubs.opengroup.org/onlinepubs/009695399/functions/write.html
[6c642a] commit 6c642a878688adf46b226903858b53e2d31ac5c3
compate/clipped-write.c: large write(2) fails on Mac OS X/XNU
Signed-off-by: Steffen Prohaska <prohaska@zib.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-08-20 08:43:54 +02:00
|
|
|
test_expect_success EXPENSIVE 'filter large file' '
|
2016-10-17 01:20:26 +02:00
|
|
|
test_config filter.largefile.smudge cat &&
|
|
|
|
test_config filter.largefile.clean cat &&
|
xread, xwrite: limit size of IO to 8MB
Checking out 2GB or more through an external filter (see test) fails
on Mac OS X 10.8.4 (12E55) for a 64-bit executable with:
error: read from external filter cat failed
error: cannot feed the input to external filter cat
error: cat died of signal 13
error: external filter cat failed 141
error: external filter cat failed
The reason is that read() immediately returns with EINVAL when asked
to read more than 2GB. According to POSIX [1], if the value of
nbyte passed to read() is greater than SSIZE_MAX, the result is
implementation-defined. The write function has the same restriction
[2]. Since OS X still supports running 32-bit executables, the
32-bit limit (SSIZE_MAX = INT_MAX = 2GB - 1) seems to be also
imposed on 64-bit executables under certain conditions. For write,
the problem has been addressed earlier [6c642a].
Address the problem for read() and write() differently, by limiting
size of IO chunks unconditionally on all platforms in xread() and
xwrite(). Large chunks only cause problems, like causing latencies
when killing the process, even if OS X was not buggy. Doing IO in
reasonably sized smaller chunks should have no negative impact on
performance.
The compat wrapper clipped_write() introduced earlier [6c642a] is
not needed anymore. It will be reverted in a separate commit. The
new test catches read and write problems.
Note that 'git add' exits with 0 even if it prints filtering errors
to stderr. The test, therefore, checks stderr. 'git add' should
probably be changed (sometime in another commit) to exit with
nonzero if filtering fails. The test could then be changed to use
test_must_fail.
Thanks to the following people for suggestions and testing:
Johannes Sixt <j6t@kdbg.org>
John Keeping <john@keeping.me.uk>
Jonathan Nieder <jrnieder@gmail.com>
Kyle J. McKay <mackyle@gmail.com>
Linus Torvalds <torvalds@linux-foundation.org>
Torsten Bögershausen <tboegi@web.de>
[1] http://pubs.opengroup.org/onlinepubs/009695399/functions/read.html
[2] http://pubs.opengroup.org/onlinepubs/009695399/functions/write.html
[6c642a] commit 6c642a878688adf46b226903858b53e2d31ac5c3
compate/clipped-write.c: large write(2) fails on Mac OS X/XNU
Signed-off-by: Steffen Prohaska <prohaska@zib.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-08-20 08:43:54 +02:00
|
|
|
for i in $(test_seq 1 2048); do printf "%1048576d" 1; done >2GB &&
|
|
|
|
echo "2GB filter=largefile" >.gitattributes &&
|
|
|
|
git add 2GB 2>err &&
|
2016-10-17 01:20:26 +02:00
|
|
|
test_must_be_empty err &&
|
xread, xwrite: limit size of IO to 8MB
Checking out 2GB or more through an external filter (see test) fails
on Mac OS X 10.8.4 (12E55) for a 64-bit executable with:
error: read from external filter cat failed
error: cannot feed the input to external filter cat
error: cat died of signal 13
error: external filter cat failed 141
error: external filter cat failed
The reason is that read() immediately returns with EINVAL when asked
to read more than 2GB. According to POSIX [1], if the value of
nbyte passed to read() is greater than SSIZE_MAX, the result is
implementation-defined. The write function has the same restriction
[2]. Since OS X still supports running 32-bit executables, the
32-bit limit (SSIZE_MAX = INT_MAX = 2GB - 1) seems to be also
imposed on 64-bit executables under certain conditions. For write,
the problem has been addressed earlier [6c642a].
Address the problem for read() and write() differently, by limiting
size of IO chunks unconditionally on all platforms in xread() and
xwrite(). Large chunks only cause problems, like causing latencies
when killing the process, even if OS X was not buggy. Doing IO in
reasonably sized smaller chunks should have no negative impact on
performance.
The compat wrapper clipped_write() introduced earlier [6c642a] is
not needed anymore. It will be reverted in a separate commit. The
new test catches read and write problems.
Note that 'git add' exits with 0 even if it prints filtering errors
to stderr. The test, therefore, checks stderr. 'git add' should
probably be changed (sometime in another commit) to exit with
nonzero if filtering fails. The test could then be changed to use
test_must_fail.
Thanks to the following people for suggestions and testing:
Johannes Sixt <j6t@kdbg.org>
John Keeping <john@keeping.me.uk>
Jonathan Nieder <jrnieder@gmail.com>
Kyle J. McKay <mackyle@gmail.com>
Linus Torvalds <torvalds@linux-foundation.org>
Torsten Bögershausen <tboegi@web.de>
[1] http://pubs.opengroup.org/onlinepubs/009695399/functions/read.html
[2] http://pubs.opengroup.org/onlinepubs/009695399/functions/write.html
[6c642a] commit 6c642a878688adf46b226903858b53e2d31ac5c3
compate/clipped-write.c: large write(2) fails on Mac OS X/XNU
Signed-off-by: Steffen Prohaska <prohaska@zib.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-08-20 08:43:54 +02:00
|
|
|
rm -f 2GB &&
|
|
|
|
git checkout -- 2GB 2>err &&
|
2016-10-17 01:20:26 +02:00
|
|
|
test_must_be_empty err
|
xread, xwrite: limit size of IO to 8MB
Checking out 2GB or more through an external filter (see test) fails
on Mac OS X 10.8.4 (12E55) for a 64-bit executable with:
error: read from external filter cat failed
error: cannot feed the input to external filter cat
error: cat died of signal 13
error: external filter cat failed 141
error: external filter cat failed
The reason is that read() immediately returns with EINVAL when asked
to read more than 2GB. According to POSIX [1], if the value of
nbyte passed to read() is greater than SSIZE_MAX, the result is
implementation-defined. The write function has the same restriction
[2]. Since OS X still supports running 32-bit executables, the
32-bit limit (SSIZE_MAX = INT_MAX = 2GB - 1) seems to be also
imposed on 64-bit executables under certain conditions. For write,
the problem has been addressed earlier [6c642a].
Address the problem for read() and write() differently, by limiting
size of IO chunks unconditionally on all platforms in xread() and
xwrite(). Large chunks only cause problems, like causing latencies
when killing the process, even if OS X was not buggy. Doing IO in
reasonably sized smaller chunks should have no negative impact on
performance.
The compat wrapper clipped_write() introduced earlier [6c642a] is
not needed anymore. It will be reverted in a separate commit. The
new test catches read and write problems.
Note that 'git add' exits with 0 even if it prints filtering errors
to stderr. The test, therefore, checks stderr. 'git add' should
probably be changed (sometime in another commit) to exit with
nonzero if filtering fails. The test could then be changed to use
test_must_fail.
Thanks to the following people for suggestions and testing:
Johannes Sixt <j6t@kdbg.org>
John Keeping <john@keeping.me.uk>
Jonathan Nieder <jrnieder@gmail.com>
Kyle J. McKay <mackyle@gmail.com>
Linus Torvalds <torvalds@linux-foundation.org>
Torsten Bögershausen <tboegi@web.de>
[1] http://pubs.opengroup.org/onlinepubs/009695399/functions/read.html
[2] http://pubs.opengroup.org/onlinepubs/009695399/functions/write.html
[6c642a] commit 6c642a878688adf46b226903858b53e2d31ac5c3
compate/clipped-write.c: large write(2) fails on Mac OS X/XNU
Signed-off-by: Steffen Prohaska <prohaska@zib.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-08-20 08:43:54 +02:00
|
|
|
'
|
|
|
|
|
sha1_file: pass empty buffer to index empty file
`git add` of an empty file with a filter pops complaints from
`copy_fd` about a bad file descriptor.
This traces back to these lines in sha1_file.c:index_core:
if (!size) {
ret = index_mem(sha1, NULL, size, type, path, flags);
The problem here is that content to be added to the index can be
supplied from an fd, or from a memory buffer, or from a pathname. This
call is supplying a NULL buffer pointer and a zero size.
Downstream logic takes the complete absence of a buffer to mean the
data is to be found elsewhere -- for instance, these, from convert.c:
if (params->src) {
write_err = (write_in_full(child_process.in, params->src, params->size) < 0);
} else {
write_err = copy_fd(params->fd, child_process.in);
}
~If there's a buffer, write from that, otherwise the data must be coming
from an open fd.~
Perfectly reasonable logic in a routine that's going to write from
either a buffer or an fd.
So change `index_core` to supply an empty buffer when indexing an empty
file.
There's a patch out there that instead changes the logic quoted above to
take a `-1` fd to mean "use the buffer", but it seems to me that the
distinction between a missing buffer and an empty one carries intrinsic
semantics, where the logic change is adapting the code to handle
incorrect arguments.
Signed-off-by: Jim Hill <gjthill@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-05-18 02:41:45 +02:00
|
|
|
test_expect_success "filter: clean empty file" '
|
2016-10-17 01:20:26 +02:00
|
|
|
test_config filter.in-repo-header.clean "echo cleaned && cat" &&
|
|
|
|
test_config filter.in-repo-header.smudge "sed 1d" &&
|
sha1_file: pass empty buffer to index empty file
`git add` of an empty file with a filter pops complaints from
`copy_fd` about a bad file descriptor.
This traces back to these lines in sha1_file.c:index_core:
if (!size) {
ret = index_mem(sha1, NULL, size, type, path, flags);
The problem here is that content to be added to the index can be
supplied from an fd, or from a memory buffer, or from a pathname. This
call is supplying a NULL buffer pointer and a zero size.
Downstream logic takes the complete absence of a buffer to mean the
data is to be found elsewhere -- for instance, these, from convert.c:
if (params->src) {
write_err = (write_in_full(child_process.in, params->src, params->size) < 0);
} else {
write_err = copy_fd(params->fd, child_process.in);
}
~If there's a buffer, write from that, otherwise the data must be coming
from an open fd.~
Perfectly reasonable logic in a routine that's going to write from
either a buffer or an fd.
So change `index_core` to supply an empty buffer when indexing an empty
file.
There's a patch out there that instead changes the logic quoted above to
take a `-1` fd to mean "use the buffer", but it seems to me that the
distinction between a missing buffer and an empty one carries intrinsic
semantics, where the logic change is adapting the code to handle
incorrect arguments.
Signed-off-by: Jim Hill <gjthill@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-05-18 02:41:45 +02:00
|
|
|
|
|
|
|
echo "empty-in-worktree filter=in-repo-header" >>.gitattributes &&
|
|
|
|
>empty-in-worktree &&
|
|
|
|
|
|
|
|
echo cleaned >expected &&
|
|
|
|
git add empty-in-worktree &&
|
|
|
|
git show :empty-in-worktree >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success "filter: smudge empty file" '
|
2016-10-17 01:20:26 +02:00
|
|
|
test_config filter.empty-in-repo.clean "cat >/dev/null" &&
|
|
|
|
test_config filter.empty-in-repo.smudge "echo smudged && cat" &&
|
sha1_file: pass empty buffer to index empty file
`git add` of an empty file with a filter pops complaints from
`copy_fd` about a bad file descriptor.
This traces back to these lines in sha1_file.c:index_core:
if (!size) {
ret = index_mem(sha1, NULL, size, type, path, flags);
The problem here is that content to be added to the index can be
supplied from an fd, or from a memory buffer, or from a pathname. This
call is supplying a NULL buffer pointer and a zero size.
Downstream logic takes the complete absence of a buffer to mean the
data is to be found elsewhere -- for instance, these, from convert.c:
if (params->src) {
write_err = (write_in_full(child_process.in, params->src, params->size) < 0);
} else {
write_err = copy_fd(params->fd, child_process.in);
}
~If there's a buffer, write from that, otherwise the data must be coming
from an open fd.~
Perfectly reasonable logic in a routine that's going to write from
either a buffer or an fd.
So change `index_core` to supply an empty buffer when indexing an empty
file.
There's a patch out there that instead changes the logic quoted above to
take a `-1` fd to mean "use the buffer", but it seems to me that the
distinction between a missing buffer and an empty one carries intrinsic
semantics, where the logic change is adapting the code to handle
incorrect arguments.
Signed-off-by: Jim Hill <gjthill@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-05-18 02:41:45 +02:00
|
|
|
|
|
|
|
echo "empty-in-repo filter=empty-in-repo" >>.gitattributes &&
|
|
|
|
echo dead data walking >empty-in-repo &&
|
|
|
|
git add empty-in-repo &&
|
|
|
|
|
|
|
|
echo smudged >expected &&
|
|
|
|
git checkout-index --prefix=filtered- empty-in-repo &&
|
|
|
|
test_cmp expected filtered-empty-in-repo
|
|
|
|
'
|
|
|
|
|
2016-01-29 09:21:37 +01:00
|
|
|
test_expect_success 'disable filter with empty override' '
|
|
|
|
test_config_global filter.disable.smudge false &&
|
|
|
|
test_config_global filter.disable.clean false &&
|
|
|
|
test_config filter.disable.smudge false &&
|
|
|
|
test_config filter.disable.clean false &&
|
|
|
|
|
|
|
|
echo "*.disable filter=disable" >.gitattributes &&
|
|
|
|
|
|
|
|
echo test >test.disable &&
|
|
|
|
git -c filter.disable.clean= add test.disable 2>err &&
|
|
|
|
test_must_be_empty err &&
|
|
|
|
rm -f test.disable &&
|
|
|
|
git -c filter.disable.smudge= checkout -- test.disable 2>err &&
|
|
|
|
test_must_be_empty err
|
|
|
|
'
|
|
|
|
|
diff: do not reuse worktree files that need "clean" conversion
When accessing a blob for a diff, we may try to reuse file
contents in the working tree, under the theory that it is
faster to mmap those file contents than it would be to
extract the content from the object database.
When we have to filter those contents, though, that
assumption does not hold. Even for our internal conversions
like CRLF, we have to allocate and fill a new buffer anyway.
But much worse, for external clean filters we have to exec
an arbitrary script, and we have no idea how expensive it
may be to run.
So let's skip this optimization when conversion into git's
"clean" form is required. This applies whenever the
"want_file" flag is false. When it's true, the caller
actually wants the smudged worktree contents, which the
reused file by definition already has (in fact, this is a
key optimization going the other direction, since reusing
the worktree file there lets us skip smudge filters).
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-07-22 17:27:53 +02:00
|
|
|
test_expect_success 'diff does not reuse worktree files that need cleaning' '
|
|
|
|
test_config filter.counter.clean "echo . >>count; sed s/^/clean:/" &&
|
|
|
|
echo "file filter=counter" >.gitattributes &&
|
|
|
|
test_commit one file &&
|
|
|
|
test_commit two file &&
|
|
|
|
|
|
|
|
>count &&
|
|
|
|
git diff-tree -p HEAD &&
|
|
|
|
test_line_count = 0 count
|
|
|
|
'
|
|
|
|
|
2016-10-17 01:20:37 +02:00
|
|
|
test_expect_success PERL 'required process filter should filter data' '
|
2017-06-01 10:22:00 +02:00
|
|
|
test_config_global filter.protocol.process "rot13-filter.pl debug.log clean smudge" &&
|
2016-10-17 01:20:37 +02:00
|
|
|
test_config_global filter.protocol.required true &&
|
|
|
|
rm -rf repo &&
|
|
|
|
mkdir repo &&
|
|
|
|
(
|
|
|
|
cd repo &&
|
|
|
|
git init &&
|
|
|
|
|
|
|
|
echo "*.r filter=protocol" >.gitattributes &&
|
|
|
|
git add . &&
|
2016-12-04 14:37:31 +01:00
|
|
|
git commit -m "test commit 1" &&
|
2016-10-17 01:20:37 +02:00
|
|
|
git branch empty-branch &&
|
|
|
|
|
|
|
|
cp "$TEST_ROOT/test.o" test.r &&
|
|
|
|
cp "$TEST_ROOT/test2.o" test2.r &&
|
|
|
|
mkdir testsubdir &&
|
2016-12-03 20:45:16 +01:00
|
|
|
cp "$TEST_ROOT/test3 '\''sq'\'',\$x=.o" "testsubdir/test3 '\''sq'\'',\$x=.r" &&
|
2016-10-17 01:20:37 +02:00
|
|
|
>test4-empty.r &&
|
|
|
|
|
|
|
|
S=$(file_size test.r) &&
|
|
|
|
S2=$(file_size test2.r) &&
|
2016-12-03 20:45:16 +01:00
|
|
|
S3=$(file_size "testsubdir/test3 '\''sq'\'',\$x=.r") &&
|
2016-10-17 01:20:37 +02:00
|
|
|
|
|
|
|
filter_git add . &&
|
|
|
|
cat >expected.log <<-EOF &&
|
|
|
|
START
|
|
|
|
init handshake complete
|
|
|
|
IN: clean test.r $S [OK] -- OUT: $S . [OK]
|
|
|
|
IN: clean test2.r $S2 [OK] -- OUT: $S2 . [OK]
|
|
|
|
IN: clean test4-empty.r 0 [OK] -- OUT: 0 [OK]
|
2016-12-03 20:45:16 +01:00
|
|
|
IN: clean testsubdir/test3 '\''sq'\'',\$x=.r $S3 [OK] -- OUT: $S3 . [OK]
|
2016-10-17 01:20:37 +02:00
|
|
|
STOP
|
|
|
|
EOF
|
2017-06-01 10:22:00 +02:00
|
|
|
test_cmp_count expected.log debug.log &&
|
2016-10-17 01:20:37 +02:00
|
|
|
|
2016-12-18 13:37:48 +01:00
|
|
|
git commit -m "test commit 2" &&
|
2016-12-03 20:45:16 +01:00
|
|
|
rm -f test2.r "testsubdir/test3 '\''sq'\'',\$x=.r" &&
|
2016-10-17 01:20:37 +02:00
|
|
|
|
|
|
|
filter_git checkout --quiet --no-progress . &&
|
|
|
|
cat >expected.log <<-EOF &&
|
|
|
|
START
|
|
|
|
init handshake complete
|
|
|
|
IN: smudge test2.r $S2 [OK] -- OUT: $S2 . [OK]
|
2016-12-03 20:45:16 +01:00
|
|
|
IN: smudge testsubdir/test3 '\''sq'\'',\$x=.r $S3 [OK] -- OUT: $S3 . [OK]
|
2016-10-17 01:20:37 +02:00
|
|
|
STOP
|
|
|
|
EOF
|
2017-06-01 10:22:00 +02:00
|
|
|
test_cmp_exclude_clean expected.log debug.log &&
|
2016-10-17 01:20:37 +02:00
|
|
|
|
2019-08-22 21:22:40 +02:00
|
|
|
# Make sure that the file appears dirty, so checkout below has to
|
|
|
|
# run the configured filter.
|
|
|
|
touch test.r &&
|
2016-10-17 01:20:37 +02:00
|
|
|
filter_git checkout --quiet --no-progress empty-branch &&
|
|
|
|
cat >expected.log <<-EOF &&
|
|
|
|
START
|
|
|
|
init handshake complete
|
|
|
|
IN: clean test.r $S [OK] -- OUT: $S . [OK]
|
|
|
|
STOP
|
|
|
|
EOF
|
2017-06-01 10:22:00 +02:00
|
|
|
test_cmp_exclude_clean expected.log debug.log &&
|
2016-10-17 01:20:37 +02:00
|
|
|
|
|
|
|
filter_git checkout --quiet --no-progress master &&
|
|
|
|
cat >expected.log <<-EOF &&
|
|
|
|
START
|
|
|
|
init handshake complete
|
|
|
|
IN: smudge test.r $S [OK] -- OUT: $S . [OK]
|
|
|
|
IN: smudge test2.r $S2 [OK] -- OUT: $S2 . [OK]
|
|
|
|
IN: smudge test4-empty.r 0 [OK] -- OUT: 0 [OK]
|
2016-12-03 20:45:16 +01:00
|
|
|
IN: smudge testsubdir/test3 '\''sq'\'',\$x=.r $S3 [OK] -- OUT: $S3 . [OK]
|
2016-10-17 01:20:37 +02:00
|
|
|
STOP
|
|
|
|
EOF
|
2017-06-01 10:22:00 +02:00
|
|
|
test_cmp_exclude_clean expected.log debug.log &&
|
2016-10-17 01:20:37 +02:00
|
|
|
|
|
|
|
test_cmp_committed_rot13 "$TEST_ROOT/test.o" test.r &&
|
|
|
|
test_cmp_committed_rot13 "$TEST_ROOT/test2.o" test2.r &&
|
2016-12-03 20:45:16 +01:00
|
|
|
test_cmp_committed_rot13 "$TEST_ROOT/test3 '\''sq'\'',\$x=.o" "testsubdir/test3 '\''sq'\'',\$x=.r"
|
2016-10-17 01:20:37 +02:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success PERL 'required process filter takes precedence' '
|
|
|
|
test_config_global filter.protocol.clean false &&
|
2017-06-01 10:22:00 +02:00
|
|
|
test_config_global filter.protocol.process "rot13-filter.pl debug.log clean" &&
|
2016-10-17 01:20:37 +02:00
|
|
|
test_config_global filter.protocol.required true &&
|
|
|
|
rm -rf repo &&
|
|
|
|
mkdir repo &&
|
|
|
|
(
|
|
|
|
cd repo &&
|
|
|
|
git init &&
|
|
|
|
|
|
|
|
echo "*.r filter=protocol" >.gitattributes &&
|
|
|
|
cp "$TEST_ROOT/test.o" test.r &&
|
|
|
|
S=$(file_size test.r) &&
|
|
|
|
|
|
|
|
# Check that the process filter is invoked here
|
|
|
|
filter_git add . &&
|
|
|
|
cat >expected.log <<-EOF &&
|
|
|
|
START
|
|
|
|
init handshake complete
|
|
|
|
IN: clean test.r $S [OK] -- OUT: $S . [OK]
|
|
|
|
STOP
|
|
|
|
EOF
|
2017-06-01 10:22:00 +02:00
|
|
|
test_cmp_count expected.log debug.log
|
2016-10-17 01:20:37 +02:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success PERL 'required process filter should be used only for "clean" operation only' '
|
2017-06-01 10:22:00 +02:00
|
|
|
test_config_global filter.protocol.process "rot13-filter.pl debug.log clean" &&
|
2016-10-17 01:20:37 +02:00
|
|
|
rm -rf repo &&
|
|
|
|
mkdir repo &&
|
|
|
|
(
|
|
|
|
cd repo &&
|
|
|
|
git init &&
|
|
|
|
|
|
|
|
echo "*.r filter=protocol" >.gitattributes &&
|
|
|
|
cp "$TEST_ROOT/test.o" test.r &&
|
|
|
|
S=$(file_size test.r) &&
|
|
|
|
|
|
|
|
filter_git add . &&
|
|
|
|
cat >expected.log <<-EOF &&
|
|
|
|
START
|
|
|
|
init handshake complete
|
|
|
|
IN: clean test.r $S [OK] -- OUT: $S . [OK]
|
|
|
|
STOP
|
|
|
|
EOF
|
2017-06-01 10:22:00 +02:00
|
|
|
test_cmp_count expected.log debug.log &&
|
2016-10-17 01:20:37 +02:00
|
|
|
|
|
|
|
rm test.r &&
|
|
|
|
|
|
|
|
filter_git checkout --quiet --no-progress . &&
|
|
|
|
# If the filter would be used for "smudge", too, we would see
|
|
|
|
# "IN: smudge test.r 57 [OK] -- OUT: 57 . [OK]" here
|
|
|
|
cat >expected.log <<-EOF &&
|
|
|
|
START
|
|
|
|
init handshake complete
|
|
|
|
STOP
|
|
|
|
EOF
|
2017-06-01 10:22:00 +02:00
|
|
|
test_cmp_exclude_clean expected.log debug.log
|
2016-10-17 01:20:37 +02:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success PERL 'required process filter should process multiple packets' '
|
2017-06-01 10:22:00 +02:00
|
|
|
test_config_global filter.protocol.process "rot13-filter.pl debug.log clean smudge" &&
|
2016-10-17 01:20:37 +02:00
|
|
|
test_config_global filter.protocol.required true &&
|
|
|
|
|
|
|
|
rm -rf repo &&
|
|
|
|
mkdir repo &&
|
|
|
|
(
|
|
|
|
cd repo &&
|
|
|
|
git init &&
|
|
|
|
|
|
|
|
# Generate data requiring 1, 2, 3 packets
|
|
|
|
S=65516 && # PKTLINE_DATA_MAXLEN -> Maximal size of a packet
|
|
|
|
generate_random_characters $(($S )) 1pkt_1__.file &&
|
|
|
|
generate_random_characters $(($S +1)) 2pkt_1+1.file &&
|
|
|
|
generate_random_characters $(($S*2-1)) 2pkt_2-1.file &&
|
|
|
|
generate_random_characters $(($S*2 )) 2pkt_2__.file &&
|
|
|
|
generate_random_characters $(($S*2+1)) 3pkt_2+1.file &&
|
|
|
|
|
|
|
|
for FILE in "$TEST_ROOT"/*.file
|
|
|
|
do
|
|
|
|
cp "$FILE" . &&
|
2016-11-02 19:18:25 +01:00
|
|
|
rot13.sh <"$FILE" >"$FILE.rot13"
|
2016-10-17 01:20:37 +02:00
|
|
|
done &&
|
|
|
|
|
|
|
|
echo "*.file filter=protocol" >.gitattributes &&
|
|
|
|
filter_git add *.file .gitattributes &&
|
|
|
|
cat >expected.log <<-EOF &&
|
|
|
|
START
|
|
|
|
init handshake complete
|
|
|
|
IN: clean 1pkt_1__.file $(($S )) [OK] -- OUT: $(($S )) . [OK]
|
|
|
|
IN: clean 2pkt_1+1.file $(($S +1)) [OK] -- OUT: $(($S +1)) .. [OK]
|
|
|
|
IN: clean 2pkt_2-1.file $(($S*2-1)) [OK] -- OUT: $(($S*2-1)) .. [OK]
|
|
|
|
IN: clean 2pkt_2__.file $(($S*2 )) [OK] -- OUT: $(($S*2 )) .. [OK]
|
|
|
|
IN: clean 3pkt_2+1.file $(($S*2+1)) [OK] -- OUT: $(($S*2+1)) ... [OK]
|
|
|
|
STOP
|
|
|
|
EOF
|
2017-06-01 10:22:00 +02:00
|
|
|
test_cmp_count expected.log debug.log &&
|
2016-10-17 01:20:37 +02:00
|
|
|
|
|
|
|
rm -f *.file &&
|
|
|
|
|
|
|
|
filter_git checkout --quiet --no-progress -- *.file &&
|
|
|
|
cat >expected.log <<-EOF &&
|
|
|
|
START
|
|
|
|
init handshake complete
|
|
|
|
IN: smudge 1pkt_1__.file $(($S )) [OK] -- OUT: $(($S )) . [OK]
|
|
|
|
IN: smudge 2pkt_1+1.file $(($S +1)) [OK] -- OUT: $(($S +1)) .. [OK]
|
|
|
|
IN: smudge 2pkt_2-1.file $(($S*2-1)) [OK] -- OUT: $(($S*2-1)) .. [OK]
|
|
|
|
IN: smudge 2pkt_2__.file $(($S*2 )) [OK] -- OUT: $(($S*2 )) .. [OK]
|
|
|
|
IN: smudge 3pkt_2+1.file $(($S*2+1)) [OK] -- OUT: $(($S*2+1)) ... [OK]
|
|
|
|
STOP
|
|
|
|
EOF
|
2017-06-01 10:22:00 +02:00
|
|
|
test_cmp_exclude_clean expected.log debug.log &&
|
2016-10-17 01:20:37 +02:00
|
|
|
|
|
|
|
for FILE in *.file
|
|
|
|
do
|
|
|
|
test_cmp_committed_rot13 "$TEST_ROOT/$FILE" $FILE
|
|
|
|
done
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success PERL 'required process filter with clean error should fail' '
|
2017-06-01 10:22:00 +02:00
|
|
|
test_config_global filter.protocol.process "rot13-filter.pl debug.log clean smudge" &&
|
2016-10-17 01:20:37 +02:00
|
|
|
test_config_global filter.protocol.required true &&
|
|
|
|
rm -rf repo &&
|
|
|
|
mkdir repo &&
|
|
|
|
(
|
|
|
|
cd repo &&
|
|
|
|
git init &&
|
|
|
|
|
|
|
|
echo "*.r filter=protocol" >.gitattributes &&
|
|
|
|
|
|
|
|
cp "$TEST_ROOT/test.o" test.r &&
|
|
|
|
echo "this is going to fail" >clean-write-fail.r &&
|
|
|
|
echo "content-test3-subdir" >test3.r &&
|
|
|
|
|
|
|
|
test_must_fail git add .
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success PERL 'process filter should restart after unexpected write failure' '
|
2017-06-01 10:22:00 +02:00
|
|
|
test_config_global filter.protocol.process "rot13-filter.pl debug.log clean smudge" &&
|
2016-10-17 01:20:37 +02:00
|
|
|
rm -rf repo &&
|
|
|
|
mkdir repo &&
|
|
|
|
(
|
|
|
|
cd repo &&
|
|
|
|
git init &&
|
|
|
|
|
|
|
|
echo "*.r filter=protocol" >.gitattributes &&
|
|
|
|
|
|
|
|
cp "$TEST_ROOT/test.o" test.r &&
|
|
|
|
cp "$TEST_ROOT/test2.o" test2.r &&
|
|
|
|
echo "this is going to fail" >smudge-write-fail.o &&
|
|
|
|
cp smudge-write-fail.o smudge-write-fail.r &&
|
|
|
|
|
|
|
|
S=$(file_size test.r) &&
|
|
|
|
S2=$(file_size test2.r) &&
|
|
|
|
SF=$(file_size smudge-write-fail.r) &&
|
|
|
|
|
|
|
|
git add . &&
|
|
|
|
rm -f *.r &&
|
|
|
|
|
2017-06-01 10:22:00 +02:00
|
|
|
rm -f debug.log &&
|
2016-10-17 01:20:37 +02:00
|
|
|
git checkout --quiet --no-progress . 2>git-stderr.log &&
|
|
|
|
|
|
|
|
grep "smudge write error at" git-stderr.log &&
|
2018-07-21 09:49:29 +02:00
|
|
|
test_i18ngrep "error: external filter" git-stderr.log &&
|
2016-10-17 01:20:37 +02:00
|
|
|
|
|
|
|
cat >expected.log <<-EOF &&
|
|
|
|
START
|
|
|
|
init handshake complete
|
2017-06-28 23:29:49 +02:00
|
|
|
IN: smudge smudge-write-fail.r $SF [OK] -- [WRITE FAIL]
|
2016-10-17 01:20:37 +02:00
|
|
|
START
|
|
|
|
init handshake complete
|
|
|
|
IN: smudge test.r $S [OK] -- OUT: $S . [OK]
|
|
|
|
IN: smudge test2.r $S2 [OK] -- OUT: $S2 . [OK]
|
|
|
|
STOP
|
|
|
|
EOF
|
2017-06-01 10:22:00 +02:00
|
|
|
test_cmp_exclude_clean expected.log debug.log &&
|
2016-10-17 01:20:37 +02:00
|
|
|
|
|
|
|
test_cmp_committed_rot13 "$TEST_ROOT/test.o" test.r &&
|
|
|
|
test_cmp_committed_rot13 "$TEST_ROOT/test2.o" test2.r &&
|
|
|
|
|
|
|
|
# Smudge failed
|
|
|
|
! test_cmp smudge-write-fail.o smudge-write-fail.r &&
|
2016-11-02 19:18:25 +01:00
|
|
|
rot13.sh <smudge-write-fail.o >expected &&
|
2016-10-17 01:20:37 +02:00
|
|
|
git cat-file blob :smudge-write-fail.r >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success PERL 'process filter should not be restarted if it signals an error' '
|
2017-06-01 10:22:00 +02:00
|
|
|
test_config_global filter.protocol.process "rot13-filter.pl debug.log clean smudge" &&
|
2016-10-17 01:20:37 +02:00
|
|
|
rm -rf repo &&
|
|
|
|
mkdir repo &&
|
|
|
|
(
|
|
|
|
cd repo &&
|
|
|
|
git init &&
|
|
|
|
|
|
|
|
echo "*.r filter=protocol" >.gitattributes &&
|
|
|
|
|
|
|
|
cp "$TEST_ROOT/test.o" test.r &&
|
|
|
|
cp "$TEST_ROOT/test2.o" test2.r &&
|
|
|
|
echo "this will cause an error" >error.o &&
|
|
|
|
cp error.o error.r &&
|
|
|
|
|
|
|
|
S=$(file_size test.r) &&
|
|
|
|
S2=$(file_size test2.r) &&
|
|
|
|
SE=$(file_size error.r) &&
|
|
|
|
|
|
|
|
git add . &&
|
|
|
|
rm -f *.r &&
|
|
|
|
|
|
|
|
filter_git checkout --quiet --no-progress . &&
|
|
|
|
cat >expected.log <<-EOF &&
|
|
|
|
START
|
|
|
|
init handshake complete
|
2017-06-28 23:29:49 +02:00
|
|
|
IN: smudge error.r $SE [OK] -- [ERROR]
|
2016-10-17 01:20:37 +02:00
|
|
|
IN: smudge test.r $S [OK] -- OUT: $S . [OK]
|
|
|
|
IN: smudge test2.r $S2 [OK] -- OUT: $S2 . [OK]
|
|
|
|
STOP
|
|
|
|
EOF
|
2017-06-01 10:22:00 +02:00
|
|
|
test_cmp_exclude_clean expected.log debug.log &&
|
2016-10-17 01:20:37 +02:00
|
|
|
|
|
|
|
test_cmp_committed_rot13 "$TEST_ROOT/test.o" test.r &&
|
|
|
|
test_cmp_committed_rot13 "$TEST_ROOT/test2.o" test2.r &&
|
|
|
|
test_cmp error.o error.r
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success PERL 'process filter abort stops processing of all further files' '
|
2017-06-01 10:22:00 +02:00
|
|
|
test_config_global filter.protocol.process "rot13-filter.pl debug.log clean smudge" &&
|
2016-10-17 01:20:37 +02:00
|
|
|
rm -rf repo &&
|
|
|
|
mkdir repo &&
|
|
|
|
(
|
|
|
|
cd repo &&
|
|
|
|
git init &&
|
|
|
|
|
|
|
|
echo "*.r filter=protocol" >.gitattributes &&
|
|
|
|
|
|
|
|
cp "$TEST_ROOT/test.o" test.r &&
|
|
|
|
cp "$TEST_ROOT/test2.o" test2.r &&
|
|
|
|
echo "error this blob and all future blobs" >abort.o &&
|
|
|
|
cp abort.o abort.r &&
|
|
|
|
|
|
|
|
SA=$(file_size abort.r) &&
|
|
|
|
|
|
|
|
git add . &&
|
|
|
|
rm -f *.r &&
|
|
|
|
|
|
|
|
# Note: This test assumes that Git filters files in alphabetical
|
|
|
|
# order ("abort.r" before "test.r").
|
|
|
|
filter_git checkout --quiet --no-progress . &&
|
|
|
|
cat >expected.log <<-EOF &&
|
|
|
|
START
|
|
|
|
init handshake complete
|
2017-06-28 23:29:49 +02:00
|
|
|
IN: smudge abort.r $SA [OK] -- [ABORT]
|
2016-10-17 01:20:37 +02:00
|
|
|
STOP
|
|
|
|
EOF
|
2017-06-01 10:22:00 +02:00
|
|
|
test_cmp_exclude_clean expected.log debug.log &&
|
2016-10-17 01:20:37 +02:00
|
|
|
|
|
|
|
test_cmp "$TEST_ROOT/test.o" test.r &&
|
|
|
|
test_cmp "$TEST_ROOT/test2.o" test2.r &&
|
|
|
|
test_cmp abort.o abort.r
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success PERL 'invalid process filter must fail (and not hang!)' '
|
|
|
|
test_config_global filter.protocol.process cat &&
|
|
|
|
test_config_global filter.protocol.required true &&
|
|
|
|
rm -rf repo &&
|
|
|
|
mkdir repo &&
|
|
|
|
(
|
|
|
|
cd repo &&
|
|
|
|
git init &&
|
|
|
|
|
|
|
|
echo "*.r filter=protocol" >.gitattributes &&
|
|
|
|
|
|
|
|
cp "$TEST_ROOT/test.o" test.r &&
|
|
|
|
test_must_fail git add . 2>git-stderr.log &&
|
2017-07-26 20:17:29 +02:00
|
|
|
grep "expected git-filter-server" git-stderr.log
|
2016-10-17 01:20:37 +02:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2017-06-30 22:41:28 +02:00
|
|
|
test_expect_success PERL 'delayed checkout in process filter' '
|
|
|
|
test_config_global filter.a.process "rot13-filter.pl a.log clean smudge delay" &&
|
|
|
|
test_config_global filter.a.required true &&
|
|
|
|
test_config_global filter.b.process "rot13-filter.pl b.log clean smudge delay" &&
|
|
|
|
test_config_global filter.b.required true &&
|
|
|
|
|
|
|
|
rm -rf repo &&
|
|
|
|
mkdir repo &&
|
|
|
|
(
|
|
|
|
cd repo &&
|
|
|
|
git init &&
|
|
|
|
echo "*.a filter=a" >.gitattributes &&
|
|
|
|
echo "*.b filter=b" >>.gitattributes &&
|
|
|
|
cp "$TEST_ROOT/test.o" test.a &&
|
|
|
|
cp "$TEST_ROOT/test.o" test-delay10.a &&
|
|
|
|
cp "$TEST_ROOT/test.o" test-delay11.a &&
|
|
|
|
cp "$TEST_ROOT/test.o" test-delay20.a &&
|
|
|
|
cp "$TEST_ROOT/test.o" test-delay10.b &&
|
|
|
|
git add . &&
|
|
|
|
git commit -m "test commit"
|
|
|
|
) &&
|
|
|
|
|
|
|
|
S=$(file_size "$TEST_ROOT/test.o") &&
|
|
|
|
cat >a.exp <<-EOF &&
|
|
|
|
START
|
|
|
|
init handshake complete
|
|
|
|
IN: smudge test.a $S [OK] -- OUT: $S . [OK]
|
|
|
|
IN: smudge test-delay10.a $S [OK] -- [DELAYED]
|
|
|
|
IN: smudge test-delay11.a $S [OK] -- [DELAYED]
|
|
|
|
IN: smudge test-delay20.a $S [OK] -- [DELAYED]
|
|
|
|
IN: list_available_blobs test-delay10.a test-delay11.a [OK]
|
|
|
|
IN: smudge test-delay10.a 0 [OK] -- OUT: $S . [OK]
|
|
|
|
IN: smudge test-delay11.a 0 [OK] -- OUT: $S . [OK]
|
|
|
|
IN: list_available_blobs test-delay20.a [OK]
|
|
|
|
IN: smudge test-delay20.a 0 [OK] -- OUT: $S . [OK]
|
|
|
|
IN: list_available_blobs [OK]
|
|
|
|
STOP
|
|
|
|
EOF
|
|
|
|
cat >b.exp <<-EOF &&
|
|
|
|
START
|
|
|
|
init handshake complete
|
|
|
|
IN: smudge test-delay10.b $S [OK] -- [DELAYED]
|
|
|
|
IN: list_available_blobs test-delay10.b [OK]
|
|
|
|
IN: smudge test-delay10.b 0 [OK] -- OUT: $S . [OK]
|
|
|
|
IN: list_available_blobs [OK]
|
|
|
|
STOP
|
|
|
|
EOF
|
|
|
|
|
|
|
|
rm -rf repo-cloned &&
|
|
|
|
filter_git clone repo repo-cloned &&
|
|
|
|
test_cmp_count a.exp repo-cloned/a.log &&
|
|
|
|
test_cmp_count b.exp repo-cloned/b.log &&
|
|
|
|
|
|
|
|
(
|
|
|
|
cd repo-cloned &&
|
|
|
|
test_cmp_committed_rot13 "$TEST_ROOT/test.o" test.a &&
|
|
|
|
test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay10.a &&
|
|
|
|
test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay11.a &&
|
|
|
|
test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay20.a &&
|
|
|
|
test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay10.b &&
|
|
|
|
|
|
|
|
rm *.a *.b &&
|
|
|
|
filter_git checkout . &&
|
|
|
|
test_cmp_count ../a.exp a.log &&
|
|
|
|
test_cmp_count ../b.exp b.log &&
|
|
|
|
|
|
|
|
test_cmp_committed_rot13 "$TEST_ROOT/test.o" test.a &&
|
|
|
|
test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay10.a &&
|
|
|
|
test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay11.a &&
|
|
|
|
test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay20.a &&
|
|
|
|
test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay10.b
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success PERL 'missing file in delayed checkout' '
|
|
|
|
test_config_global filter.bug.process "rot13-filter.pl bug.log clean smudge delay" &&
|
|
|
|
test_config_global filter.bug.required true &&
|
|
|
|
|
|
|
|
rm -rf repo &&
|
|
|
|
mkdir repo &&
|
|
|
|
(
|
|
|
|
cd repo &&
|
|
|
|
git init &&
|
|
|
|
echo "*.a filter=bug" >.gitattributes &&
|
2018-07-02 02:23:55 +02:00
|
|
|
cp "$TEST_ROOT/test.o" missing-delay.a &&
|
2017-06-30 22:41:28 +02:00
|
|
|
git add . &&
|
|
|
|
git commit -m "test commit"
|
|
|
|
) &&
|
|
|
|
|
|
|
|
rm -rf repo-cloned &&
|
|
|
|
test_must_fail git clone repo repo-cloned 2>git-stderr.log &&
|
|
|
|
grep "error: .missing-delay\.a. was not filtered properly" git-stderr.log
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success PERL 'invalid file in delayed checkout' '
|
|
|
|
test_config_global filter.bug.process "rot13-filter.pl bug.log clean smudge delay" &&
|
|
|
|
test_config_global filter.bug.required true &&
|
|
|
|
|
|
|
|
rm -rf repo &&
|
|
|
|
mkdir repo &&
|
|
|
|
(
|
|
|
|
cd repo &&
|
|
|
|
git init &&
|
|
|
|
echo "*.a filter=bug" >.gitattributes &&
|
|
|
|
cp "$TEST_ROOT/test.o" invalid-delay.a &&
|
2018-07-02 02:23:55 +02:00
|
|
|
cp "$TEST_ROOT/test.o" unfiltered &&
|
2017-06-30 22:41:28 +02:00
|
|
|
git add . &&
|
|
|
|
git commit -m "test commit"
|
|
|
|
) &&
|
|
|
|
|
|
|
|
rm -rf repo-cloned &&
|
|
|
|
test_must_fail git clone repo repo-cloned 2>git-stderr.log &&
|
|
|
|
grep "error: external filter .* signaled that .unfiltered. is now available although it has not been delayed earlier" git-stderr.log
|
|
|
|
'
|
|
|
|
|
2007-04-22 04:09:02 +02:00
|
|
|
test_done
|