blob: f19e6510d04583866e39cbdea545a0d1323b7f76 [file] [log] [blame]
Junio C Hamano3fed15f2007-04-21 19:09:02 -07001#!/bin/sh
2
3test_description='blob conversion via gitattributes'
4
5. ./test-lib.sh
6
Johannes Sixtfa7151a2010-01-01 23:14:06 +01007cat <<EOF >rot13.sh
8#!$SHELL_PATH
Jeff King7339eb02008-03-11 13:40:45 -04009tr \
10 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' \
11 'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM'
Junio C Hamanoaa4ed402007-04-21 03:14:13 -070012EOF
13chmod +x rot13.sh
14
Junio C Hamano3fed15f2007-04-21 19:09:02 -070015test_expect_success setup '
Junio C Hamanoaa4ed402007-04-21 03:14:13 -070016 git config filter.rot13.smudge ./rot13.sh &&
17 git config filter.rot13.clean ./rot13.sh &&
18
Junio C Hamano3fed15f2007-04-21 19:09:02 -070019 {
Junio C Hamanoaa4ed402007-04-21 03:14:13 -070020 echo "*.t filter=rot13"
Junio C Hamano3fed15f2007-04-21 19:09:02 -070021 echo "*.i ident"
22 } >.gitattributes &&
23
24 {
25 echo a b c d e f g h i j k l m
26 echo n o p q r s t u v w x y z
Andy Parkinsaf9b54b2007-05-14 14:37:25 +010027 echo '\''$Id$'\''
Junio C Hamano3fed15f2007-04-21 19:09:02 -070028 } >test &&
29 cat test >test.t &&
30 cat test >test.o &&
31 cat test >test.i &&
32 git add test test.t test.i &&
33 rm -f test test.t test.i &&
34 git checkout -- test test.t test.i
35'
36
Andy Parkinsaf9b54b2007-05-14 14:37:25 +010037script='s/^\$Id: \([0-9a-f]*\) \$/\1/p'
Junio C Hamano3fed15f2007-04-21 19:09:02 -070038
39test_expect_success check '
40
41 cmp test.o test &&
42 cmp test.o test.t &&
43
44 # ident should be stripped in the repository
45 git diff --raw --exit-code :test :test.i &&
46 id=$(git rev-parse --verify :test) &&
47 embedded=$(sed -ne "$script" test.i) &&
Johannes Sixta0ae35a2007-10-19 21:48:04 +020048 test "z$id" = "z$embedded" &&
49
50 git cat-file blob :test.t > test.r &&
51
52 ./rot13.sh < test.o > test.t &&
53 cmp test.r test.t
Junio C Hamano3fed15f2007-04-21 19:09:02 -070054'
55
Andy Parkinsdfab71c2007-05-27 11:52:11 +010056# If an expanded ident ever gets into the repository, we want to make sure that
57# it is collapsed before being expanded again on checkout
58test_expect_success expanded_in_repo '
59 {
60 echo "File with expanded keywords"
61 echo "\$Id\$"
62 echo "\$Id:\$"
63 echo "\$Id: 0000000000000000000000000000000000000000 \$"
64 echo "\$Id: NoSpaceAtEnd\$"
65 echo "\$Id:NoSpaceAtFront \$"
66 echo "\$Id:NoSpaceAtEitherEnd\$"
67 echo "\$Id: NoTerminatingSymbol"
Henrik Grubbströma9f30492010-04-06 14:46:37 +020068 echo "\$Id: Foreign Commit With Spaces \$"
Junio C Hamano6b6cab32011-05-24 18:02:48 -070069 } >expanded-keywords.0 &&
Andy Parkinsdfab71c2007-05-27 11:52:11 +010070
Junio C Hamano6b6cab32011-05-24 18:02:48 -070071 {
72 cat expanded-keywords.0 &&
73 printf "\$Id: NoTerminatingSymbolAtEOF"
74 } >expanded-keywords &&
75 cat expanded-keywords >expanded-keywords-crlf &&
76 git add expanded-keywords expanded-keywords-crlf &&
Andy Parkinsdfab71c2007-05-27 11:52:11 +010077 git commit -m "File with keywords expanded" &&
René Scharfedd555d82011-05-21 23:25:06 +020078 id=$(git rev-parse --verify :expanded-keywords) &&
79
80 {
81 echo "File with expanded keywords"
82 echo "\$Id: $id \$"
83 echo "\$Id: $id \$"
84 echo "\$Id: $id \$"
85 echo "\$Id: $id \$"
86 echo "\$Id: $id \$"
87 echo "\$Id: $id \$"
88 echo "\$Id: NoTerminatingSymbol"
89 echo "\$Id: Foreign Commit With Spaces \$"
Junio C Hamano6b6cab32011-05-24 18:02:48 -070090 } >expected-output.0 &&
91 {
92 cat expected-output.0 &&
René Scharfedd555d82011-05-21 23:25:06 +020093 printf "\$Id: NoTerminatingSymbolAtEOF"
Junio C Hamano6b6cab32011-05-24 18:02:48 -070094 } >expected-output &&
95 {
96 append_cr <expected-output.0 &&
97 printf "\$Id: NoTerminatingSymbolAtEOF"
98 } >expected-output-crlf &&
99 {
100 echo "expanded-keywords ident"
101 echo "expanded-keywords-crlf ident text eol=crlf"
102 } >>.gitattributes &&
Andy Parkinsdfab71c2007-05-27 11:52:11 +0100103
Junio C Hamano6b6cab32011-05-24 18:02:48 -0700104 rm -f expanded-keywords expanded-keywords-crlf &&
Andy Parkinsdfab71c2007-05-27 11:52:11 +0100105
Andy Parkinsdfab71c2007-05-27 11:52:11 +0100106 git checkout -- expanded-keywords &&
Junio C Hamano6b6cab32011-05-24 18:02:48 -0700107 test_cmp expanded-keywords expected-output &&
108
109 git checkout -- expanded-keywords-crlf &&
110 test_cmp expanded-keywords-crlf expected-output-crlf
Andy Parkinsdfab71c2007-05-27 11:52:11 +0100111'
112
Pete Wyckoffa2b665d2010-12-22 06:40:13 -0800113# The use of %f in a filter definition is expanded to the path to
114# the filename being smudged or cleaned. It must be shell escaped.
115# First, set up some interesting file names and pet them in
116# .gitattributes.
117test_expect_success 'filter shell-escaped filenames' '
118 cat >argc.sh <<-EOF &&
119 #!$SHELL_PATH
Junio C Hamano4290f692010-12-22 15:18:47 -0800120 cat >/dev/null
Pete Wyckoffa2b665d2010-12-22 06:40:13 -0800121 echo argc: \$# "\$@"
122 EOF
123 normal=name-no-magic &&
124 special="name with '\''sq'\'' and \$x" &&
125 echo some test text >"$normal" &&
126 echo some test text >"$special" &&
127 git add "$normal" "$special" &&
128 git commit -q -m "add files" &&
129 echo "name* filter=argc" >.gitattributes &&
130
131 # delete the files and check them out again, using a smudge filter
132 # that will count the args and echo the command-line back to us
133 git config filter.argc.smudge "sh ./argc.sh %f" &&
134 rm "$normal" "$special" &&
135 git checkout -- "$normal" "$special" &&
136
137 # make sure argc.sh counted the right number of args
138 echo "argc: 1 $normal" >expect &&
139 test_cmp expect "$normal" &&
140 echo "argc: 1 $special" >expect &&
141 test_cmp expect "$special" &&
142
143 # do the same thing, but with more args in the filter expression
144 git config filter.argc.smudge "sh ./argc.sh %f --my-extra-arg" &&
145 rm "$normal" "$special" &&
146 git checkout -- "$normal" "$special" &&
147
148 # make sure argc.sh counted the right number of args
149 echo "argc: 2 $normal --my-extra-arg" >expect &&
150 test_cmp expect "$normal" &&
151 echo "argc: 2 $special --my-extra-arg" >expect &&
152 test_cmp expect "$special" &&
153 :
154'
155
Junio C Hamano3fed15f2007-04-21 19:09:02 -0700156test_done