3 test_description
='git p4 filetype tests'
5 TEST_PASSES_SANITIZE_LEAK
=true
8 test_expect_success
'start p4d' '
13 # This series of tests checks newline handling Both p4 and
14 # git store newlines as \n, and have options to choose how
15 # newlines appear in checked-out files.
17 test_expect_success
'p4 client newlines, unix' '
20 p4 client -o | sed "/LineEnd/s/:.*/:unix/" | p4 client -i &&
21 printf "unix\ncrlf\n" >f-unix &&
22 printf "unix\r\ncrlf\r\n" >f-unix-as-crlf &&
23 p4 add -t text f-unix &&
24 p4 submit -d f-unix &&
26 # LineEnd: unix; should be no change after sync
27 cp f-unix f-unix-orig &&
29 test_cmp f-unix-orig f-unix &&
31 # make sure stored in repo as unix newlines
32 # use sed to eat python-appended newline
33 p4 -G print //depot/f-unix | marshal_dump data 2 |\
34 sed \$d >f-unix-p4-print &&
35 test_cmp f-unix-orig f-unix-p4-print &&
37 # switch to win, make sure lf -> crlf
38 p4 client -o | sed "/LineEnd/s/:.*/:win/" | p4 client -i &&
40 test_cmp f-unix-as-crlf f-unix
44 test_expect_success
'p4 client newlines, win' '
47 p4 client -o | sed "/LineEnd/s/:.*/:win/" | p4 client -i &&
48 printf "win\r\ncrlf\r\n" >f-win &&
49 printf "win\ncrlf\n" >f-win-as-lf &&
50 p4 add -t text f-win &&
53 # LineEnd: win; should be no change after sync
54 cp f-win f-win-orig &&
56 test_cmp f-win-orig f-win &&
58 # make sure stored in repo as unix newlines
59 # use sed to eat python-appened newline
60 p4 -G print //depot/f-win | marshal_dump data 2 |\
61 sed \$d >f-win-p4-print &&
62 test_cmp f-win-as-lf f-win-p4-print &&
64 # switch to unix, make sure lf -> crlf
65 p4 client -o | sed "/LineEnd/s/:.*/:unix/" | p4 client -i &&
67 test_cmp f-win-as-lf f-win
71 test_expect_success
'ensure blobs store only lf newlines' '
72 test_when_finished cleanup_git &&
76 git p4 sync //depot@all &&
78 # verify the files in .git are stored only with newlines
79 o=$(git ls-tree p4/master -- f-unix | cut -f1 | cut -d\ -f3) &&
80 git cat-file blob $o >f-unix-blob &&
81 test_cmp "$cli"/f-unix-orig f-unix-blob &&
83 o=$(git ls-tree p4/master -- f-win | cut -f1 | cut -d\ -f3) &&
84 git cat-file blob $o >f-win-blob &&
85 test_cmp "$cli"/f-win-as-lf f-win-blob &&
87 rm f-unix-blob f-win-blob
91 test_expect_success
'gitattributes setting eol=lf produces lf newlines' '
92 test_when_finished cleanup_git &&
94 # checkout the files and make sure core.eol works as planned
97 echo "* eol=lf" >.gitattributes &&
98 git p4 sync //depot@all &&
99 git checkout -b master p4/master &&
100 test_cmp "$cli"/f-unix-orig f-unix &&
101 test_cmp "$cli"/f-win-as-lf f-win
105 test_expect_success
'gitattributes setting eol=crlf produces crlf newlines' '
106 test_when_finished cleanup_git &&
108 # checkout the files and make sure core.eol works as planned
111 echo "* eol=crlf" >.gitattributes &&
112 git p4 sync //depot@all &&
113 git checkout -b master p4/master &&
114 test_cmp "$cli"/f-unix-as-crlf f-unix &&
115 test_cmp "$cli"/f-win-orig f-win
119 test_expect_success
'crlf cleanup' '
122 rm f-unix-orig f-unix-as-crlf &&
123 rm f-win-orig f-win-as-lf &&
124 p4 client -o | sed "/LineEnd/s/:.*/:unix/" | p4 client -i &&
129 test_expect_success
'utf-16 file create' '
133 # p4 saves this verbatim
134 printf "three\nline\ntext\n" >f-ascii &&
135 p4 add -t text f-ascii &&
137 # p4 adds \377\376 header
138 cp f-ascii f-ascii-as-utf16 &&
139 p4 add -t utf16 f-ascii-as-utf16 &&
141 # p4 saves this exactly as iconv produced it
142 printf "three\nline\ntext\n" | iconv -f ascii -t utf-16 >f-utf16 &&
143 p4 add -t utf16 f-utf16 &&
145 # this also is unchanged
146 cp f-utf16 f-utf16-as-text &&
147 p4 add -t text f-utf16-as-text &&
149 p4 submit -d "f files" &&
151 # force update of client files
156 test_expect_success
'utf-16 file test' '
157 test_when_finished cleanup_git &&
158 git p4 clone --dest="$git" //depot@all &&
162 test_cmp "$cli/f-ascii" f-ascii &&
163 test_cmp "$cli/f-ascii-as-utf16" f-ascii-as-utf16 &&
164 test_cmp "$cli/f-utf16" f-utf16 &&
165 test_cmp "$cli/f-utf16-as-text" f-utf16-as-text
169 test_expect_success
'keyword file create' '
173 printf "id\n\$Id\$\n\$Author\$\ntext\n" >k-text-k &&
174 p4 add -t text+k k-text-k &&
176 cp k-text-k k-text-ko &&
177 p4 add -t text+ko k-text-ko &&
179 iconv -f ascii -t utf-16 <k-text-k >k-utf16-k &&
180 p4 add -t utf16+k k-utf16-k &&
182 cp k-utf16-k k-utf16-ko &&
183 p4 add -t utf16+ko k-utf16-ko &&
185 p4 submit -d "k files" &&
191 cat >k_smush.py
<<-\EOF &&
193 sys.stdout.write(re.sub(r'(?i)\$(Id|Header|Author|Date|DateTime|Change|File|Revision):[^$]*\$', r'$\1$', sys.stdin.read()))
195 cat >ko_smush.py <<-\
EOF
197 sys.stdout.write(re.sub(r'(?i)\$(Id|Header):[^$]*\$', r'$\1$', sys.stdin.read()))
201 test_expect_success 'keyword file test' '
203 test_when_finished rm -f k_smush.py ko_smush.py &&
204 test_when_finished cleanup_git &&
205 git p4 clone --dest="$git" //depot@all &&
209 # text, ensure unexpanded
210 "$PYTHON_PATH" "$TRASH_DIRECTORY/k_smush.py" <"$cli/k-text-k" >cli-k-text-k-smush &&
211 test_cmp cli-k-text-k-smush k-text-k &&
212 "$PYTHON_PATH" "$TRASH_DIRECTORY/ko_smush.py" <"$cli/k-text-ko" >cli-k-text-ko-smush &&
213 test_cmp cli-k-text-ko-smush k-text-ko &&
215 # utf16, even though p4 expands keywords, git p4 does not
217 test_cmp "$cli/k-utf16-k" k-utf16-k &&
218 test_cmp "$cli/k-utf16-ko" k-utf16-ko
223 cat >gendouble.py <<-\EOF
227 s = struct.pack(b">LL18s",
228 0x00051607, # AppleDouble
229 0x00020000, # version 2
230 b"" # pad to 26 bytes
232 getattr(sys.stdout, 'buffer', sys.stdout).write(s)
236 test_expect_success 'ignore apple' '
237 test_when_finished rm -f gendouble.py &&
241 test-tool genrandom apple 1024 >double.png &&
242 "$PYTHON_PATH" "$TRASH_DIRECTORY/gendouble.py" >%double.png &&
243 p4 add -t apple double.png &&
244 p4 submit -d appledouble
246 test_when_finished cleanup_git &&
247 git p4 clone --dest="$git" //depot@all &&
254 test_expect_success SYMLINKS 'create p4 symlink' '
256 ln -s symlink-target symlink &&
258 p4 submit -d "add symlink"
261 test_expect_success SYMLINKS 'ensure p4 symlink parsed correctly' '
262 test_when_finished cleanup_git &&
263 git p4 clone --dest="$git" //depot@all &&
267 test $(test_readlink symlink) = symlink-target
271 test_expect_success SYMLINKS 'empty symlink target' '
273 # first create the file as a file
276 p4 add empty-symlink &&
277 p4 submit -d "add empty-symlink as a file"
280 # now change it to be a symlink to "target1"
282 p4 edit empty-symlink &&
283 p4 reopen -t symlink empty-symlink &&
285 ln -s target1 empty-symlink &&
286 p4 add empty-symlink &&
287 p4 submit -d "make empty-symlink point to target1"
290 # Hack the p4 depot to make the symlink point to nothing;
291 # this should not happen in reality, but shows up
292 # in p4 repos in the wild.
294 # The sed expression changes this:
304 # Note that newer Perforce versions started to store files
305 # compressed in directories. The case statement handles both
306 # old and new layout.
308 case "$(echo empty-symlink*)" in
310 sed "/@target1/{; s/target1/@/; n; d; }" \
311 empty-symlink,v >empty-symlink,v.tmp &&
312 mv empty-symlink,v.tmp empty-symlink,v;;
314 path="empty-symlink,d/$(ls empty-symlink,d/ | tail -n1)" &&
316 gzip </dev/null >"$path";;
318 BUG "unhandled p4d layout";;
322 # Make sure symlink really is empty. Asking
323 # p4 to sync here will make it generate errors.
325 p4 print -q //depot/empty-symlink#2 >out &&
326 test_must_be_empty out
328 test_when_finished cleanup_git &&
330 # make sure git p4 handles it without error
331 git p4 clone --dest="$git" //depot@all &&
333 # fix the symlink, make it point to "target2"
336 p4 open empty-symlink &&
338 ln -s target2 empty-symlink &&
339 p4 submit -d "make empty-symlink point to target2"
342 git p4 clone --dest="$git" //depot@all &&
345 test $(test_readlink empty-symlink) = target2
349 test_expect_success SYMLINKS 'utf-8 with and without BOM in text file' '
354 echo some tǣxt >utf8-nobom-test &&
356 # same utf8 content as before but with bom
357 echo some tǣxt | sed '\''s/^/\xef\xbb\xbf/'\'' >utf8-bom-test &&
360 dd bs=1 count=3 if=utf8-bom-test of=utf8-bom-empty-test &&
362 p4 add utf8-nobom-test utf8-bom-test utf8-bom-empty-test &&
363 p4 submit -d "add utf8 test files"
365 test_when_finished cleanup_git &&
367 git p4 clone --dest="$git" //depot@all &&
370 git checkout refs/remotes/p4/master &&
372 echo some tǣxt >utf8-nobom-check &&
373 test_cmp utf8-nobom-check utf8-nobom-test &&
375 echo some tǣxt | sed '\''s/^/\xef\xbb\xbf/'\'' >utf8-bom-check &&
376 test_cmp utf8-bom-check utf8-bom-test &&
378 dd bs=1 count=3 if=utf8-bom-check of=utf8-bom-empty-check &&
379 test_cmp utf8-bom-empty-check utf8-bom-empty-test