]>
Commit | Line | Data |
---|---|---|
3fed15f5 JH |
1 | #!/bin/sh |
2 | ||
3 | test_description='blob conversion via gitattributes' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
fa7151a6 JS |
7 | cat <<EOF >rot13.sh |
8 | #!$SHELL_PATH | |
7339eb08 JK |
9 | tr \ |
10 | 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' \ | |
11 | 'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM' | |
aa4ed402 JH |
12 | EOF |
13 | chmod +x rot13.sh | |
14 | ||
3fed15f5 | 15 | test_expect_success setup ' |
aa4ed402 JH |
16 | git config filter.rot13.smudge ./rot13.sh && |
17 | git config filter.rot13.clean ./rot13.sh && | |
18 | ||
3fed15f5 | 19 | { |
aa4ed402 | 20 | echo "*.t filter=rot13" |
3fed15f5 JH |
21 | 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 | |
af9b54bb | 27 | echo '\''$Id$'\'' |
3fed15f5 JH |
28 | } >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 | ||
af9b54bb | 37 | script='s/^\$Id: \([0-9a-f]*\) \$/\1/p' |
3fed15f5 JH |
38 | |
39 | test_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) && | |
a0ae35ae JS |
48 | 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 | |
3fed15f5 JH |
54 | ' |
55 | ||
dfab71cb AP |
56 | # 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 | |
58 | test_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" | |
a9f3049f HG |
68 | echo "\$Id: Foreign Commit With Spaces \$" |
69 | echo "\$Id: NoTerminatingSymbolAtEOF" | |
dfab71cb AP |
70 | } > expanded-keywords && |
71 | ||
72 | { | |
73 | echo "File with expanded keywords" | |
a9f3049f HG |
74 | echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$" |
75 | echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$" | |
76 | echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$" | |
77 | echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$" | |
78 | echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$" | |
79 | echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$" | |
dfab71cb | 80 | echo "\$Id: NoTerminatingSymbol" |
07814d90 | 81 | echo "\$Id: Foreign Commit With Spaces \$" |
a9f3049f | 82 | echo "\$Id: NoTerminatingSymbolAtEOF" |
dfab71cb AP |
83 | } > expected-output && |
84 | ||
85 | git add expanded-keywords && | |
86 | git commit -m "File with keywords expanded" && | |
87 | ||
88 | echo "expanded-keywords ident" >> .gitattributes && | |
89 | ||
90 | rm -f expanded-keywords && | |
91 | git checkout -- expanded-keywords && | |
92 | cat expanded-keywords && | |
93 | cmp expanded-keywords expected-output | |
94 | ' | |
95 | ||
a2b665de PW |
96 | # The use of %f in a filter definition is expanded to the path to |
97 | # the filename being smudged or cleaned. It must be shell escaped. | |
98 | # First, set up some interesting file names and pet them in | |
99 | # .gitattributes. | |
100 | test_expect_success 'filter shell-escaped filenames' ' | |
101 | cat >argc.sh <<-EOF && | |
102 | #!$SHELL_PATH | |
4290f690 | 103 | cat >/dev/null |
a2b665de PW |
104 | echo argc: \$# "\$@" |
105 | EOF | |
106 | normal=name-no-magic && | |
107 | special="name with '\''sq'\'' and \$x" && | |
108 | echo some test text >"$normal" && | |
109 | echo some test text >"$special" && | |
110 | git add "$normal" "$special" && | |
111 | git commit -q -m "add files" && | |
112 | echo "name* filter=argc" >.gitattributes && | |
113 | ||
114 | # delete the files and check them out again, using a smudge filter | |
115 | # that will count the args and echo the command-line back to us | |
116 | git config filter.argc.smudge "sh ./argc.sh %f" && | |
117 | rm "$normal" "$special" && | |
118 | git checkout -- "$normal" "$special" && | |
119 | ||
120 | # make sure argc.sh counted the right number of args | |
121 | echo "argc: 1 $normal" >expect && | |
122 | test_cmp expect "$normal" && | |
123 | echo "argc: 1 $special" >expect && | |
124 | test_cmp expect "$special" && | |
125 | ||
126 | # do the same thing, but with more args in the filter expression | |
127 | git config filter.argc.smudge "sh ./argc.sh %f --my-extra-arg" && | |
128 | rm "$normal" "$special" && | |
129 | git checkout -- "$normal" "$special" && | |
130 | ||
131 | # make sure argc.sh counted the right number of args | |
132 | echo "argc: 2 $normal --my-extra-arg" >expect && | |
133 | test_cmp expect "$normal" && | |
134 | echo "argc: 2 $special --my-extra-arg" >expect && | |
135 | test_cmp expect "$special" && | |
136 | : | |
137 | ' | |
138 | ||
3fed15f5 | 139 | test_done |