2007-04-22 10:09:02 +08:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='blob conversion via gitattributes'
|
|
|
|
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
2010-01-02 06:14:06 +08:00
|
|
|
cat <<EOF >rot13.sh
|
|
|
|
#!$SHELL_PATH
|
2008-03-12 01:40:45 +08:00
|
|
|
tr \
|
|
|
|
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' \
|
|
|
|
'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM'
|
2007-04-21 18:14:13 +08:00
|
|
|
EOF
|
|
|
|
chmod +x rot13.sh
|
|
|
|
|
2007-04-22 10:09:02 +08:00
|
|
|
test_expect_success setup '
|
2007-04-21 18:14:13 +08:00
|
|
|
git config filter.rot13.smudge ./rot13.sh &&
|
|
|
|
git config filter.rot13.clean ./rot13.sh &&
|
|
|
|
|
2007-04-22 10:09:02 +08:00
|
|
|
{
|
2007-04-21 18:14:13 +08:00
|
|
|
echo "*.t filter=rot13"
|
2007-04-22 10:09:02 +08: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 21:37:25 +08:00
|
|
|
echo '\''$Id$'\''
|
2007-04-22 10:09:02 +08: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 &&
|
|
|
|
git checkout -- test test.t test.i
|
|
|
|
'
|
|
|
|
|
2007-05-14 21:37:25 +08:00
|
|
|
script='s/^\$Id: \([0-9a-f]*\) \$/\1/p'
|
2007-04-22 10:09:02 +08:00
|
|
|
|
|
|
|
test_expect_success check '
|
|
|
|
|
|
|
|
cmp test.o test &&
|
|
|
|
cmp test.o test.t &&
|
|
|
|
|
|
|
|
# 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-20 03:48:04 +08:00
|
|
|
test "z$id" = "z$embedded" &&
|
|
|
|
|
|
|
|
git cat-file blob :test.t > test.r &&
|
|
|
|
|
|
|
|
./rot13.sh < test.o > test.t &&
|
|
|
|
cmp test.r test.t
|
2007-04-22 10:09:02 +08:00
|
|
|
'
|
|
|
|
|
2007-05-27 18:52:11 +08: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 20:46:37 +08:00
|
|
|
echo "\$Id: Foreign Commit With Spaces \$"
|
2011-05-25 09:02:48 +08:00
|
|
|
} >expanded-keywords.0 &&
|
2007-05-27 18:52:11 +08:00
|
|
|
|
2011-05-25 09:02:48 +08: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-22 05:25:06 +08:00
|
|
|
git commit -m "File with keywords expanded" &&
|
|
|
|
id=$(git rev-parse --verify :expanded-keywords) &&
|
|
|
|
|
2007-05-27 18:52:11 +08:00
|
|
|
{
|
|
|
|
echo "File with expanded keywords"
|
2011-05-22 05:25:06 +08:00
|
|
|
echo "\$Id: $id \$"
|
|
|
|
echo "\$Id: $id \$"
|
|
|
|
echo "\$Id: $id \$"
|
|
|
|
echo "\$Id: $id \$"
|
|
|
|
echo "\$Id: $id \$"
|
|
|
|
echo "\$Id: $id \$"
|
2007-05-27 18:52:11 +08:00
|
|
|
echo "\$Id: NoTerminatingSymbol"
|
2010-04-06 20:46:38 +08:00
|
|
|
echo "\$Id: Foreign Commit With Spaces \$"
|
2011-05-25 09:02:48 +08:00
|
|
|
} >expected-output.0 &&
|
|
|
|
{
|
|
|
|
cat expected-output.0 &&
|
2011-05-22 05:25:06 +08:00
|
|
|
printf "\$Id: NoTerminatingSymbolAtEOF"
|
2011-05-25 09:02:48 +08: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 18:52:11 +08:00
|
|
|
|
2011-05-25 09:02:48 +08:00
|
|
|
rm -f expanded-keywords expanded-keywords-crlf &&
|
2007-05-27 18:52:11 +08:00
|
|
|
|
|
|
|
git checkout -- expanded-keywords &&
|
2011-05-25 09:02:48 +08:00
|
|
|
test_cmp expanded-keywords expected-output &&
|
|
|
|
|
|
|
|
git checkout -- expanded-keywords-crlf &&
|
|
|
|
test_cmp expanded-keywords-crlf expected-output-crlf
|
2007-05-27 18:52:11 +08:00
|
|
|
'
|
|
|
|
|
2010-12-22 22:40:13 +08: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 07:18:47 +08:00
|
|
|
cat >/dev/null
|
2010-12-22 22:40:13 +08: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
|
|
|
|
git config filter.argc.smudge "sh ./argc.sh %f" &&
|
|
|
|
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
|
|
|
|
git config filter.argc.smudge "sh ./argc.sh %f --my-extra-arg" &&
|
|
|
|
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" &&
|
|
|
|
:
|
|
|
|
'
|
|
|
|
|
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 09:19:03 +08:00
|
|
|
test_expect_success 'required filter success' '
|
|
|
|
git config filter.required.smudge cat &&
|
|
|
|
git config filter.required.clean cat &&
|
|
|
|
git config filter.required.required true &&
|
|
|
|
|
|
|
|
echo "*.r filter=required" >.gitattributes &&
|
|
|
|
|
|
|
|
echo test >test.r &&
|
|
|
|
git add test.r &&
|
|
|
|
rm -f test.r &&
|
|
|
|
git checkout -- test.r
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'required filter smudge failure' '
|
|
|
|
git config filter.failsmudge.smudge false &&
|
|
|
|
git config filter.failsmudge.clean cat &&
|
|
|
|
git config filter.failsmudge.required true &&
|
|
|
|
|
|
|
|
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' '
|
|
|
|
git config filter.failclean.smudge cat &&
|
|
|
|
git config filter.failclean.clean false &&
|
|
|
|
git config filter.failclean.required true &&
|
|
|
|
|
|
|
|
echo "*.fc filter=failclean" >.gitattributes &&
|
|
|
|
|
|
|
|
echo test >test.fc &&
|
|
|
|
test_must_fail git add test.fc
|
|
|
|
'
|
|
|
|
|
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 14:43:54 +08:00
|
|
|
test -n "$GIT_TEST_LONG" && test_set_prereq EXPENSIVE
|
|
|
|
|
|
|
|
test_expect_success EXPENSIVE 'filter large file' '
|
|
|
|
git config filter.largefile.smudge cat &&
|
|
|
|
git config filter.largefile.clean cat &&
|
|
|
|
for i in $(test_seq 1 2048); do printf "%1048576d" 1; done >2GB &&
|
|
|
|
echo "2GB filter=largefile" >.gitattributes &&
|
|
|
|
git add 2GB 2>err &&
|
|
|
|
! test -s err &&
|
|
|
|
rm -f 2GB &&
|
|
|
|
git checkout -- 2GB 2>err &&
|
|
|
|
! test -s err
|
|
|
|
'
|
|
|
|
|
2007-04-22 10:09:02 +08:00
|
|
|
test_done
|