Merge branch 'fc/send-email-annotate'
[git/mjg.git] / t / t9802-git-p4-filetype.sh
blobeeefa6790454d83bfb4ce740f7b1843c6a71c79c
1 #!/bin/sh
3 test_description='git p4 filetype tests'
5 . ./lib-git-p4.sh
7 test_expect_success 'start p4d' '
8 start_p4d
12 # This series of tests checks newline handling Both p4 and
13 # git store newlines as \n, and have options to choose how
14 # newlines appear in checked-out files.
16 test_expect_success 'p4 client newlines, unix' '
18 cd "$cli" &&
19 p4 client -o | sed "/LineEnd/s/:.*/:unix/" | p4 client -i &&
20 printf "unix\ncrlf\n" >f-unix &&
21 printf "unix\r\ncrlf\r\n" >f-unix-as-crlf &&
22 p4 add -t text f-unix &&
23 p4 submit -d f-unix &&
25 # LineEnd: unix; should be no change after sync
26 cp f-unix f-unix-orig &&
27 p4 sync -f &&
28 test_cmp f-unix-orig f-unix &&
30 # make sure stored in repo as unix newlines
31 # use sed to eat python-appened newline
32 p4 -G print //depot/f-unix | marshal_dump data 2 |\
33 sed \$d >f-unix-p4-print &&
34 test_cmp f-unix-orig f-unix-p4-print &&
36 # switch to win, make sure lf -> crlf
37 p4 client -o | sed "/LineEnd/s/:.*/:win/" | p4 client -i &&
38 p4 sync -f &&
39 test_cmp f-unix-as-crlf f-unix
43 test_expect_success 'p4 client newlines, win' '
45 cd "$cli" &&
46 p4 client -o | sed "/LineEnd/s/:.*/:win/" | p4 client -i &&
47 printf "win\r\ncrlf\r\n" >f-win &&
48 printf "win\ncrlf\n" >f-win-as-lf &&
49 p4 add -t text f-win &&
50 p4 submit -d f-win &&
52 # LineEnd: win; should be no change after sync
53 cp f-win f-win-orig &&
54 p4 sync -f &&
55 test_cmp f-win-orig f-win &&
57 # make sure stored in repo as unix newlines
58 # use sed to eat python-appened newline
59 p4 -G print //depot/f-win | marshal_dump data 2 |\
60 sed \$d >f-win-p4-print &&
61 test_cmp f-win-as-lf f-win-p4-print &&
63 # switch to unix, make sure lf -> crlf
64 p4 client -o | sed "/LineEnd/s/:.*/:unix/" | p4 client -i &&
65 p4 sync -f &&
66 test_cmp f-win-as-lf f-win
70 test_expect_success 'ensure blobs store only lf newlines' '
71 test_when_finished cleanup_git &&
73 cd "$git" &&
74 git init &&
75 git p4 sync //depot@all &&
77 # verify the files in .git are stored only with newlines
78 o=$(git ls-tree p4/master -- f-unix | cut -f1 | cut -d\ -f3) &&
79 git cat-file blob $o >f-unix-blob &&
80 test_cmp "$cli"/f-unix-orig f-unix-blob &&
82 o=$(git ls-tree p4/master -- f-win | cut -f1 | cut -d\ -f3) &&
83 git cat-file blob $o >f-win-blob &&
84 test_cmp "$cli"/f-win-as-lf f-win-blob &&
86 rm f-unix-blob f-win-blob
90 test_expect_success 'gitattributes setting eol=lf produces lf newlines' '
91 test_when_finished cleanup_git &&
93 # checkout the files and make sure core.eol works as planned
94 cd "$git" &&
95 git init &&
96 echo "* eol=lf" >.gitattributes &&
97 git p4 sync //depot@all &&
98 git checkout master &&
99 test_cmp "$cli"/f-unix-orig f-unix &&
100 test_cmp "$cli"/f-win-as-lf f-win
104 test_expect_success 'gitattributes setting eol=crlf produces crlf newlines' '
105 test_when_finished cleanup_git &&
107 # checkout the files and make sure core.eol works as planned
108 cd "$git" &&
109 git init &&
110 echo "* eol=crlf" >.gitattributes &&
111 git p4 sync //depot@all &&
112 git checkout master &&
113 test_cmp "$cli"/f-unix-as-crlf f-unix &&
114 test_cmp "$cli"/f-win-orig f-win
118 test_expect_success 'crlf cleanup' '
120 cd "$cli" &&
121 rm f-unix-orig f-unix-as-crlf &&
122 rm f-win-orig f-win-as-lf &&
123 p4 client -o | sed "/LineEnd/s/:.*/:unix/" | p4 client -i &&
124 p4 sync -f
128 test_expect_success 'utf-16 file create' '
130 cd "$cli" &&
132 # p4 saves this verbatim
133 printf "three\nline\ntext\n" >f-ascii &&
134 p4 add -t text f-ascii &&
136 # p4 adds \377\376 header
137 cp f-ascii f-ascii-as-utf16 &&
138 p4 add -t utf16 f-ascii-as-utf16 &&
140 # p4 saves this exactly as iconv produced it
141 printf "three\nline\ntext\n" | iconv -f ascii -t utf-16 >f-utf16 &&
142 p4 add -t utf16 f-utf16 &&
144 # this also is unchanged
145 cp f-utf16 f-utf16-as-text &&
146 p4 add -t text f-utf16-as-text &&
148 p4 submit -d "f files" &&
150 # force update of client files
151 p4 sync -f
155 test_expect_success 'utf-16 file test' '
156 test_when_finished cleanup_git &&
157 git p4 clone --dest="$git" //depot@all &&
159 cd "$git" &&
161 test_cmp "$cli/f-ascii" f-ascii &&
162 test_cmp "$cli/f-ascii-as-utf16" f-ascii-as-utf16 &&
163 test_cmp "$cli/f-utf16" f-utf16 &&
164 test_cmp "$cli/f-utf16-as-text" f-utf16-as-text
168 test_expect_success 'keyword file create' '
170 cd "$cli" &&
172 printf "id\n\$Id\$\n\$Author\$\ntext\n" >k-text-k &&
173 p4 add -t text+k k-text-k &&
175 cp k-text-k k-text-ko &&
176 p4 add -t text+ko k-text-ko &&
178 cat k-text-k | iconv -f ascii -t utf-16 >k-utf16-k &&
179 p4 add -t utf16+k k-utf16-k &&
181 cp k-utf16-k k-utf16-ko &&
182 p4 add -t utf16+ko k-utf16-ko &&
184 p4 submit -d "k files" &&
185 p4 sync -f
189 build_smush() {
190 cat >k_smush.py <<-\EOF &&
191 import re, sys
192 sys.stdout.write(re.sub(r'(?i)\$(Id|Header|Author|Date|DateTime|Change|File|Revision):[^$]*\$', r'$\1$', sys.stdin.read()))
194 cat >ko_smush.py <<-\EOF
195 import re, sys
196 sys.stdout.write(re.sub(r'(?i)\$(Id|Header):[^$]*\$', r'$\1$', sys.stdin.read()))
200 test_expect_success 'keyword file test' '
201 build_smush &&
202 test_when_finished rm -f k_smush.py ko_smush.py &&
203 test_when_finished cleanup_git &&
204 git p4 clone --dest="$git" //depot@all &&
206 cd "$git" &&
208 # text, ensure unexpanded
209 "$PYTHON_PATH" "$TRASH_DIRECTORY/k_smush.py" <"$cli/k-text-k" >cli-k-text-k-smush &&
210 test_cmp cli-k-text-k-smush k-text-k &&
211 "$PYTHON_PATH" "$TRASH_DIRECTORY/ko_smush.py" <"$cli/k-text-ko" >cli-k-text-ko-smush &&
212 test_cmp cli-k-text-ko-smush k-text-ko &&
214 # utf16, even though p4 expands keywords, git p4 does not
215 # try to undo that
216 test_cmp "$cli/k-utf16-k" k-utf16-k &&
217 test_cmp "$cli/k-utf16-ko" k-utf16-ko
221 build_gendouble() {
222 cat >gendouble.py <<-\EOF
223 import sys
224 import struct
226 s = struct.pack(">LL18s",
227 0x00051607, # AppleDouble
228 0x00020000, # version 2
229 "" # pad to 26 bytes
231 sys.stdout.write(s)
235 test_expect_success 'ignore apple' '
236 test_when_finished rm -f gendouble.py &&
237 build_gendouble &&
239 cd "$cli" &&
240 test-genrandom apple 1024 >double.png &&
241 "$PYTHON_PATH" "$TRASH_DIRECTORY/gendouble.py" >%double.png &&
242 p4 add -t apple double.png &&
243 p4 submit -d appledouble
244 ) &&
245 test_when_finished cleanup_git &&
246 git p4 clone --dest="$git" //depot@all &&
248 cd "$git" &&
249 test ! -f double.png
253 test_expect_success 'kill p4d' '
254 kill_p4d
257 test_done