3 test_description
='git p4 filetype tests'
7 test_expect_success
'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' '
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 &&
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 &&
39 test_cmp f-unix-as-crlf f-unix
43 test_expect_success
'p4 client newlines, win' '
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 &&
52 # LineEnd: win; should be no change after sync
53 cp f-win f-win-orig &&
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 &&
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 &&
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
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
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' '
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 &&
128 test_expect_success
'utf-16 file create' '
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
155 test_expect_success
'utf-16 file test' '
156 test_when_finished cleanup_git &&
157 git p4 clone --dest="$git" //depot@all &&
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' '
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" &&
190 cat >k_smush.py
<<-\EOF &&
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
196 sys.stdout.write(re.sub(r'(?i)\$(Id|Header):[^$]*\$', r'$\1$', sys.stdin.read()))
200 test_expect_success 'keyword file test' '
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 &&
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
216 test_cmp "$cli/k-utf16-k" k-utf16-k &&
217 test_cmp "$cli/k-utf16-ko" k-utf16-ko
222 cat >gendouble.py <<-\EOF
226 s = struct.pack(">LL18s",
227 0x00051607, # AppleDouble
228 0x00020000, # version 2
235 test_expect_success 'ignore apple' '
236 test_when_finished rm -f gendouble.py &&
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
245 test_when_finished cleanup_git &&
246 git p4 clone --dest="$git" //depot@all &&
253 test_expect_success 'kill p4d' '