##// END OF EJS Templates
tests: unify test-win32text
Matt Mackall -
r12494:f18fd371 default
parent child Browse files
Show More
This diff has been collapsed as it changes many lines, (560 lines changed) Show them Hide them
@@ -1,144 +1,436 b''
1 #!/bin/sh
2
3 hg init t
4 cd t
5
6 cat > unix2dos.py <<EOF
7 import sys
8
9 for path in sys.argv[1:]:
10 data = file(path, 'rb').read()
11 data = data.replace('\n', '\r\n')
12 file(path, 'wb').write(data)
13 EOF
14
1
15 cat > print.py <<EOF
2 $ hg init t
16 import sys
3 $ cd t
17 print(sys.stdin.read().replace('\n', '<LF>').replace('\r', '<CR>').replace('\0', '<NUL>'))
4 $ cat > unix2dos.py <<EOF
18 EOF
5 > import sys
6 >
7 > for path in sys.argv[1:]:
8 > data = file(path, 'rb').read()
9 > data = data.replace('\n', '\r\n')
10 > file(path, 'wb').write(data)
11 > EOF
12 $ cat > print.py <<EOF
13 > import sys
14 > print(sys.stdin.read().replace('\n', '<LF>').replace('\r', '<CR>').replace('\0', '<NUL>'))
15 > EOF
16 $ echo '[hooks]' >> .hg/hgrc
17 $ echo 'pretxncommit.crlf = python:hgext.win32text.forbidcrlf' >> .hg/hgrc
18 $ echo 'pretxnchangegroup.crlf = python:hgext.win32text.forbidcrlf' >> .hg/hgrc
19 $ cat .hg/hgrc
20 [hooks]
21 pretxncommit.crlf = python:hgext.win32text.forbidcrlf
22 pretxnchangegroup.crlf = python:hgext.win32text.forbidcrlf
23 $ echo
24
25 $ echo hello > f
26 $ hg add f
19
27
20 echo '[hooks]' >> .hg/hgrc
28 commit should succeed
21 echo 'pretxncommit.crlf = python:hgext.win32text.forbidcrlf' >> .hg/hgrc
29
22 echo 'pretxnchangegroup.crlf = python:hgext.win32text.forbidcrlf' >> .hg/hgrc
30 $ hg ci -m 1
23 cat .hg/hgrc
31 $ echo
24 echo
32
33 $ hg clone . ../zoz
34 updating to branch default
35 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
36 $ cp .hg/hgrc ../zoz/.hg
37 $ python unix2dos.py f
38
39 commit should fail
25
40
26 echo hello > f
41 $ hg ci -m 2.1
27 hg add f
42 Attempt to commit or push text file(s) using CRLF line endings
28 echo commit should succeed
43 in f583ea08d42a: f
29 hg ci -m 1
44 transaction abort!
30 echo
45 rollback completed
46 abort: pretxncommit.crlf hook failed
47 [255]
48 $ echo
49
50 $ mv .hg/hgrc .hg/hgrc.bak
31
51
32 hg clone . ../zoz
52 commits should succeed
33 cp .hg/hgrc ../zoz/.hg
34
53
35 python unix2dos.py f
54 $ hg ci -m 2
36 echo commit should fail
55 $ hg cp f g
37 hg ci -m 2.1
56 $ hg ci -m 2.2
38 echo
57 $ echo
58
39
59
40 mv .hg/hgrc .hg/hgrc.bak
60 push should fail
41 echo commits should succeed
42 hg ci -m 2
43 hg cp f g
44 hg ci -m 2.2
45 echo
46
47 echo push should fail
48 hg push ../zoz
49 echo
50
61
51 mv .hg/hgrc.bak .hg/hgrc
62 $ hg push ../zoz
52 echo hello > f
63 pushing to ../zoz
53 hg rm g
64 searching for changes
54 echo commit should succeed
65 adding changesets
55 hg ci -m 2.3
66 adding manifests
56 echo
67 adding file changes
68 added 2 changesets with 2 changes to 2 files
69 Attempt to commit or push text file(s) using CRLF line endings
70 in bc2d09796734: g
71 in b1aa5cde7ff4: f
72
73 To prevent this mistake in your local repository,
74 add to Mercurial.ini or .hg/hgrc:
75
76 [hooks]
77 pretxncommit.crlf = python:hgext.win32text.forbidcrlf
78
79 and also consider adding:
80
81 [extensions]
82 win32text =
83 [encode]
84 ** = cleverencode:
85 [decode]
86 ** = cleverdecode:
87 transaction abort!
88 rollback completed
89 abort: pretxnchangegroup.crlf hook failed
90 [255]
91 $ echo
92
93 $ mv .hg/hgrc.bak .hg/hgrc
94 $ echo hello > f
95 $ hg rm g
57
96
58 echo push should succeed
97 commit should succeed
59 hg push ../zoz
98
60 echo
99 $ hg ci -m 2.3
100 $ echo
101
102
103 push should succeed
61
104
62 echo and now for something completely different
105 $ hg push ../zoz
63 mkdir d
106 pushing to ../zoz
64 echo hello > d/f2
107 searching for changes
65 python unix2dos.py d/f2
108 adding changesets
66 hg add d/f2
109 adding manifests
67 hg ci -m 3
110 adding file changes
68 hg revert -a
111 added 3 changesets with 3 changes to 2 files
69 rm d/f2
112 $ echo
70 echo
113
114
115 and now for something completely different
71
116
72 hg rem f
117 $ mkdir d
73 hg ci -m 4
118 $ echo hello > d/f2
74 echo
119 $ python unix2dos.py d/f2
75
120 $ hg add d/f2
76 python -c 'file("bin", "wb").write("hello\x00\x0D\x0A")'
121 $ hg ci -m 3
77 hg add bin
122 Attempt to commit or push text file(s) using CRLF line endings
78 hg ci -m 5
123 in 053ba1a3035a: d/f2
79 hg log -v
124 transaction abort!
80 echo
125 rollback completed
81
126 abort: pretxncommit.crlf hook failed
82 hg clone . dupe
127 [255]
83 echo
128 $ hg revert -a
84 for x in a b c d; do echo content > dupe/$x; done
129 forgetting d/f2
85 hg -R dupe add
130 $ rm d/f2
86 python unix2dos.py dupe/b dupe/c dupe/d
131 $ echo
87 hg -R dupe ci -m a dupe/a
132
88 hg -R dupe ci -m b/c dupe/[bc]
133 $ hg rem f
89 hg -R dupe ci -m d dupe/d
134 $ hg ci -m 4
90 hg -R dupe log -v
135 $ echo
91 echo
136
92
137 $ python -c 'file("bin", "wb").write("hello\x00\x0D\x0A")'
93 hg pull dupe
138 $ hg add bin
94 echo
139 $ hg ci -m 5
95
140 $ hg log -v
96 hg log -v
141 changeset: 5:f0b1c8d75fce
97 echo
142 tag: tip
98
143 user: test
99 rm .hg/hgrc
144 date: Thu Jan 01 00:00:00 1970 +0000
100 (echo some; echo text) > f3
145 files: bin
101 python -c 'file("f4.bat", "wb").write("rem empty\x0D\x0A")'
146 description:
102 hg add f3 f4.bat
147 5
103 hg ci -m 6
148
104
149
105 python print.py < bin
150 changeset: 4:77796dbcd4ad
106 python print.py < f3
151 user: test
107 python print.py < f4.bat
152 date: Thu Jan 01 00:00:00 1970 +0000
108 echo
153 files: f
109
154 description:
110 echo '[extensions]' >> .hg/hgrc
155 4
111 echo 'win32text = ' >> .hg/hgrc
156
112 echo '[decode]' >> .hg/hgrc
157
113 echo '** = cleverdecode:' >> .hg/hgrc
158 changeset: 3:7c1b5430b350
114 echo '[encode]' >> .hg/hgrc
159 user: test
115 echo '** = cleverencode:' >> .hg/hgrc
160 date: Thu Jan 01 00:00:00 1970 +0000
116 cat .hg/hgrc
161 files: f g
117 echo
162 description:
118
163 2.3
119 rm f3 f4.bat bin
164
120 hg co -C 2>&1 | python -c 'import sys, os; sys.stdout.write(sys.stdin.read().replace(os.getcwd(), "...."))'
165
121 python print.py < bin
166 changeset: 2:bc2d09796734
122 python print.py < f3
167 user: test
123 python print.py < f4.bat
168 date: Thu Jan 01 00:00:00 1970 +0000
124 echo
169 files: g
125
170 description:
126 python -c 'file("f5.sh", "wb").write("# empty\x0D\x0A")'
171 2.2
127 hg add f5.sh
172
128 hg ci -m 7
173
129 python print.py < f5.sh
174 changeset: 1:b1aa5cde7ff4
130 hg cat f5.sh | python print.py
175 user: test
131
176 date: Thu Jan 01 00:00:00 1970 +0000
132 echo '% just linefeed' > linefeed
177 files: f
133 hg ci -qAm 8 linefeed
178 description:
134 python print.py < linefeed
179 2
135 hg cat linefeed | python print.py
180
136 hg st -q
181
137 hg revert -a linefeed
182 changeset: 0:fcf06d5c4e1d
138 python print.py < linefeed
183 user: test
139 hg st -q
184 date: Thu Jan 01 00:00:00 1970 +0000
140 echo modified >> linefeed
185 files: f
141 hg st -q
186 description:
142 hg revert -a
187 1
143 hg st -q
188
144 python print.py < linefeed
189
190 $ echo
191
192 $ hg clone . dupe
193 updating to branch default
194 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
195 $ echo
196
197 $ for x in a b c d; do echo content > dupe/$x; done
198 $ hg -R dupe add
199 adding dupe/a
200 adding dupe/b
201 adding dupe/c
202 adding dupe/d
203 $ python unix2dos.py dupe/b dupe/c dupe/d
204 $ hg -R dupe ci -m a dupe/a
205 $ hg -R dupe ci -m b/c dupe/[bc]
206 $ hg -R dupe ci -m d dupe/d
207 $ hg -R dupe log -v
208 changeset: 8:67ac5962ab43
209 tag: tip
210 user: test
211 date: Thu Jan 01 00:00:00 1970 +0000
212 files: d
213 description:
214 d
215
216
217 changeset: 7:68c127d1834e
218 user: test
219 date: Thu Jan 01 00:00:00 1970 +0000
220 files: b c
221 description:
222 b/c
223
224
225 changeset: 6:adbf8bf7f31d
226 user: test
227 date: Thu Jan 01 00:00:00 1970 +0000
228 files: a
229 description:
230 a
231
232
233 changeset: 5:f0b1c8d75fce
234 user: test
235 date: Thu Jan 01 00:00:00 1970 +0000
236 files: bin
237 description:
238 5
239
240
241 changeset: 4:77796dbcd4ad
242 user: test
243 date: Thu Jan 01 00:00:00 1970 +0000
244 files: f
245 description:
246 4
247
248
249 changeset: 3:7c1b5430b350
250 user: test
251 date: Thu Jan 01 00:00:00 1970 +0000
252 files: f g
253 description:
254 2.3
255
256
257 changeset: 2:bc2d09796734
258 user: test
259 date: Thu Jan 01 00:00:00 1970 +0000
260 files: g
261 description:
262 2.2
263
264
265 changeset: 1:b1aa5cde7ff4
266 user: test
267 date: Thu Jan 01 00:00:00 1970 +0000
268 files: f
269 description:
270 2
271
272
273 changeset: 0:fcf06d5c4e1d
274 user: test
275 date: Thu Jan 01 00:00:00 1970 +0000
276 files: f
277 description:
278 1
279
280
281 $ echo
282
283 $ hg pull dupe
284 pulling from dupe
285 searching for changes
286 adding changesets
287 adding manifests
288 adding file changes
289 added 3 changesets with 4 changes to 4 files
290 Attempt to commit or push text file(s) using CRLF line endings
291 in 67ac5962ab43: d
292 in 68c127d1834e: b
293 in 68c127d1834e: c
294
295 To prevent this mistake in your local repository,
296 add to Mercurial.ini or .hg/hgrc:
297
298 [hooks]
299 pretxncommit.crlf = python:hgext.win32text.forbidcrlf
300
301 and also consider adding:
302
303 [extensions]
304 win32text =
305 [encode]
306 ** = cleverencode:
307 [decode]
308 ** = cleverdecode:
309 transaction abort!
310 rollback completed
311 abort: pretxnchangegroup.crlf hook failed
312 [255]
313 $ echo
314
315 $ hg log -v
316 changeset: 5:f0b1c8d75fce
317 tag: tip
318 user: test
319 date: Thu Jan 01 00:00:00 1970 +0000
320 files: bin
321 description:
322 5
323
324
325 changeset: 4:77796dbcd4ad
326 user: test
327 date: Thu Jan 01 00:00:00 1970 +0000
328 files: f
329 description:
330 4
331
332
333 changeset: 3:7c1b5430b350
334 user: test
335 date: Thu Jan 01 00:00:00 1970 +0000
336 files: f g
337 description:
338 2.3
339
340
341 changeset: 2:bc2d09796734
342 user: test
343 date: Thu Jan 01 00:00:00 1970 +0000
344 files: g
345 description:
346 2.2
347
348
349 changeset: 1:b1aa5cde7ff4
350 user: test
351 date: Thu Jan 01 00:00:00 1970 +0000
352 files: f
353 description:
354 2
355
356
357 changeset: 0:fcf06d5c4e1d
358 user: test
359 date: Thu Jan 01 00:00:00 1970 +0000
360 files: f
361 description:
362 1
363
364
365 $ echo
366
367 $ rm .hg/hgrc
368 $ (echo some; echo text) > f3
369 $ python -c 'file("f4.bat", "wb").write("rem empty\x0D\x0A")'
370 $ hg add f3 f4.bat
371 $ hg ci -m 6
372 $ python print.py < bin
373 hello<NUL><CR><LF>
374 $ python print.py < f3
375 some<LF>text<LF>
376 $ python print.py < f4.bat
377 rem empty<CR><LF>
378 $ echo
379
380 $ echo '[extensions]' >> .hg/hgrc
381 $ echo 'win32text = ' >> .hg/hgrc
382 $ echo '[decode]' >> .hg/hgrc
383 $ echo '** = cleverdecode:' >> .hg/hgrc
384 $ echo '[encode]' >> .hg/hgrc
385 $ echo '** = cleverencode:' >> .hg/hgrc
386 $ cat .hg/hgrc
387 [extensions]
388 win32text =
389 [decode]
390 ** = cleverdecode:
391 [encode]
392 ** = cleverencode:
393 $ echo
394
395 $ rm f3 f4.bat bin
396 $ hg co -C 2>&1 | python -c 'import sys, os; sys.stdout.write(sys.stdin.read().replace(os.getcwd(), "...."))'
397 WARNING: f4.bat already has CRLF line endings
398 and does not need EOL conversion by the win32text plugin.
399 Before your next commit, please reconsider your encode/decode settings in
400 Mercurial.ini or ..../.hg/hgrc.
401 3 files updated, 0 files merged, 0 files removed, 0 files unresolved
402 $ python print.py < bin
403 hello<NUL><CR><LF>
404 $ python print.py < f3
405 some<CR><LF>text<CR><LF>
406 $ python print.py < f4.bat
407 rem empty<CR><LF>
408 $ echo
409
410 $ python -c 'file("f5.sh", "wb").write("# empty\x0D\x0A")'
411 $ hg add f5.sh
412 $ hg ci -m 7
413 $ python print.py < f5.sh
414 # empty<CR><LF>
415 $ hg cat f5.sh | python print.py
416 # empty<LF>
417 $ echo '% just linefeed' > linefeed
418 $ hg ci -qAm 8 linefeed
419 $ python print.py < linefeed
420 % just linefeed<LF>
421 $ hg cat linefeed | python print.py
422 % just linefeed<LF>
423 $ hg st -q
424 $ hg revert -a linefeed
425 no changes needed to linefeed
426 $ python print.py < linefeed
427 % just linefeed<LF>
428 $ hg st -q
429 $ echo modified >> linefeed
430 $ hg st -q
431 M linefeed
432 $ hg revert -a
433 reverting linefeed
434 $ hg st -q
435 $ python print.py < linefeed
436 % just linefeed<CR><LF>
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now