##// 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, (534 lines changed) Show them Hide them
@@ -1,144 +1,436 b''
1 #!/bin/sh
2
1
3 hg init t
2 $ hg init t
4 cd t
3 $ cd t
4 $ cat > unix2dos.py <<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
5
24
6 cat > unix2dos.py <<EOF
25 $ echo hello > f
7 import sys
26 $ hg add f
27
28 commit should succeed
29
30 $ hg ci -m 1
31 $ echo
8
32
9 for path in sys.argv[1:]:
33 $ hg clone . ../zoz
10 data = file(path, 'rb').read()
34 updating to branch default
11 data = data.replace('\n', '\r\n')
35 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
12 file(path, 'wb').write(data)
36 $ cp .hg/hgrc ../zoz/.hg
13 EOF
37 $ python unix2dos.py f
38
39 commit should fail
40
41 $ hg ci -m 2.1
42 Attempt to commit or push text file(s) using CRLF line endings
43 in f583ea08d42a: f
44 transaction abort!
45 rollback completed
46 abort: pretxncommit.crlf hook failed
47 [255]
48 $ echo
49
50 $ mv .hg/hgrc .hg/hgrc.bak
14
51
15 cat > print.py <<EOF
52 commits should succeed
16 import sys
53
17 print(sys.stdin.read().replace('\n', '<LF>').replace('\r', '<CR>').replace('\0', '<NUL>'))
54 $ hg ci -m 2
18 EOF
55 $ hg cp f g
56 $ hg ci -m 2.2
57 $ echo
58
59
60 push should fail
61
62 $ hg push ../zoz
63 pushing to ../zoz
64 searching for changes
65 adding changesets
66 adding manifests
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:
19
75
20 echo '[hooks]' >> .hg/hgrc
76 [hooks]
21 echo 'pretxncommit.crlf = python:hgext.win32text.forbidcrlf' >> .hg/hgrc
77 pretxncommit.crlf = python:hgext.win32text.forbidcrlf
22 echo 'pretxnchangegroup.crlf = python:hgext.win32text.forbidcrlf' >> .hg/hgrc
78
23 cat .hg/hgrc
79 and also consider adding:
24 echo
25
80
26 echo hello > f
81 [extensions]
27 hg add f
82 win32text =
28 echo commit should succeed
83 [encode]
29 hg ci -m 1
84 ** = cleverencode:
30 echo
85 [decode]
86 ** = cleverdecode:
87 transaction abort!
88 rollback completed
89 abort: pretxnchangegroup.crlf hook failed
90 [255]
91 $ echo
31
92
32 hg clone . ../zoz
93 $ mv .hg/hgrc.bak .hg/hgrc
33 cp .hg/hgrc ../zoz/.hg
94 $ echo hello > f
95 $ hg rm g
96
97 commit should succeed
98
99 $ hg ci -m 2.3
100 $ echo
101
102
103 push should succeed
34
104
35 python unix2dos.py f
105 $ hg push ../zoz
36 echo commit should fail
106 pushing to ../zoz
37 hg ci -m 2.1
107 searching for changes
38 echo
108 adding changesets
109 adding manifests
110 adding file changes
111 added 3 changesets with 3 changes to 2 files
112 $ echo
113
114
115 and now for something completely different
39
116
40 mv .hg/hgrc .hg/hgrc.bak
117 $ mkdir d
41 echo commits should succeed
118 $ echo hello > d/f2
42 hg ci -m 2
119 $ python unix2dos.py d/f2
43 hg cp f g
120 $ hg add d/f2
44 hg ci -m 2.2
121 $ hg ci -m 3
45 echo
122 Attempt to commit or push text file(s) using CRLF line endings
123 in 053ba1a3035a: d/f2
124 transaction abort!
125 rollback completed
126 abort: pretxncommit.crlf hook failed
127 [255]
128 $ hg revert -a
129 forgetting d/f2
130 $ rm d/f2
131 $ echo
132
133 $ hg rem f
134 $ hg ci -m 4
135 $ echo
46
136
47 echo push should fail
137 $ python -c 'file("bin", "wb").write("hello\x00\x0D\x0A")'
48 hg push ../zoz
138 $ hg add bin
49 echo
139 $ hg ci -m 5
140 $ hg log -v
141 changeset: 5:f0b1c8d75fce
142 tag: tip
143 user: test
144 date: Thu Jan 01 00:00:00 1970 +0000
145 files: bin
146 description:
147 5
148
149
150 changeset: 4:77796dbcd4ad
151 user: test
152 date: Thu Jan 01 00:00:00 1970 +0000
153 files: f
154 description:
155 4
156
50
157
51 mv .hg/hgrc.bak .hg/hgrc
158 changeset: 3:7c1b5430b350
52 echo hello > f
159 user: test
53 hg rm g
160 date: Thu Jan 01 00:00:00 1970 +0000
54 echo commit should succeed
161 files: f g
55 hg ci -m 2.3
162 description:
56 echo
163 2.3
164
165
166 changeset: 2:bc2d09796734
167 user: test
168 date: Thu Jan 01 00:00:00 1970 +0000
169 files: g
170 description:
171 2.2
172
173
174 changeset: 1:b1aa5cde7ff4
175 user: test
176 date: Thu Jan 01 00:00:00 1970 +0000
177 files: f
178 description:
179 2
180
57
181
58 echo push should succeed
182 changeset: 0:fcf06d5c4e1d
59 hg push ../zoz
183 user: test
60 echo
184 date: Thu Jan 01 00:00:00 1970 +0000
185 files: f
186 description:
187 1
188
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
61
196
62 echo and now for something completely different
197 $ for x in a b c d; do echo content > dupe/$x; done
63 mkdir d
198 $ hg -R dupe add
64 echo hello > d/f2
199 adding dupe/a
65 python unix2dos.py d/f2
200 adding dupe/b
66 hg add d/f2
201 adding dupe/c
67 hg ci -m 3
202 adding dupe/d
68 hg revert -a
203 $ python unix2dos.py dupe/b dupe/c dupe/d
69 rm d/f2
204 $ hg -R dupe ci -m a dupe/a
70 echo
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
71
216
72 hg rem f
217 changeset: 7:68c127d1834e
73 hg ci -m 4
218 user: test
74 echo
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
75
240
76 python -c 'file("bin", "wb").write("hello\x00\x0D\x0A")'
241 changeset: 4:77796dbcd4ad
77 hg add bin
242 user: test
78 hg ci -m 5
243 date: Thu Jan 01 00:00:00 1970 +0000
79 hg log -v
244 files: f
80 echo
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
81
264
82 hg clone . dupe
265 changeset: 1:b1aa5cde7ff4
83 echo
266 user: test
84 for x in a b c d; do echo content > dupe/$x; done
267 date: Thu Jan 01 00:00:00 1970 +0000
85 hg -R dupe add
268 files: f
86 python unix2dos.py dupe/b dupe/c dupe/d
269 description:
87 hg -R dupe ci -m a dupe/a
270 2
88 hg -R dupe ci -m b/c dupe/[bc]
271
89 hg -R dupe ci -m d dupe/d
272
90 hg -R dupe log -v
273 changeset: 0:fcf06d5c4e1d
91 echo
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
92
294
93 hg pull dupe
295 To prevent this mistake in your local repository,
94 echo
296 add to Mercurial.ini or .hg/hgrc:
95
297
96 hg log -v
298 [hooks]
97 echo
299 pretxncommit.crlf = python:hgext.win32text.forbidcrlf
300
301 and also consider adding:
98
302
99 rm .hg/hgrc
303 [extensions]
100 (echo some; echo text) > f3
304 win32text =
101 python -c 'file("f4.bat", "wb").write("rem empty\x0D\x0A")'
305 [encode]
102 hg add f3 f4.bat
306 ** = cleverencode:
103 hg ci -m 6
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
104
324
105 python print.py < bin
325 changeset: 4:77796dbcd4ad
106 python print.py < f3
326 user: test
107 python print.py < f4.bat
327 date: Thu Jan 01 00:00:00 1970 +0000
108 echo
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
109
348
110 echo '[extensions]' >> .hg/hgrc
349 changeset: 1:b1aa5cde7ff4
111 echo 'win32text = ' >> .hg/hgrc
350 user: test
112 echo '[decode]' >> .hg/hgrc
351 date: Thu Jan 01 00:00:00 1970 +0000
113 echo '** = cleverdecode:' >> .hg/hgrc
352 files: f
114 echo '[encode]' >> .hg/hgrc
353 description:
115 echo '** = cleverencode:' >> .hg/hgrc
354 2
116 cat .hg/hgrc
355
117 echo
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
118
379
119 rm f3 f4.bat bin
380 $ echo '[extensions]' >> .hg/hgrc
120 hg co -C 2>&1 | python -c 'import sys, os; sys.stdout.write(sys.stdin.read().replace(os.getcwd(), "...."))'
381 $ echo 'win32text = ' >> .hg/hgrc
121 python print.py < bin
382 $ echo '[decode]' >> .hg/hgrc
122 python print.py < f3
383 $ echo '** = cleverdecode:' >> .hg/hgrc
123 python print.py < f4.bat
384 $ echo '[encode]' >> .hg/hgrc
124 echo
385 $ echo '** = cleverencode:' >> .hg/hgrc
125
386 $ cat .hg/hgrc
126 python -c 'file("f5.sh", "wb").write("# empty\x0D\x0A")'
387 [extensions]
127 hg add f5.sh
388 win32text =
128 hg ci -m 7
389 [decode]
129 python print.py < f5.sh
390 ** = cleverdecode:
130 hg cat f5.sh | python print.py
391 [encode]
392 ** = cleverencode:
393 $ echo
131
394
132 echo '% just linefeed' > linefeed
395 $ rm f3 f4.bat bin
133 hg ci -qAm 8 linefeed
396 $ hg co -C 2>&1 | python -c 'import sys, os; sys.stdout.write(sys.stdin.read().replace(os.getcwd(), "...."))'
134 python print.py < linefeed
397 WARNING: f4.bat already has CRLF line endings
135 hg cat linefeed | python print.py
398 and does not need EOL conversion by the win32text plugin.
136 hg st -q
399 Before your next commit, please reconsider your encode/decode settings in
137 hg revert -a linefeed
400 Mercurial.ini or ..../.hg/hgrc.
138 python print.py < linefeed
401 3 files updated, 0 files merged, 0 files removed, 0 files unresolved
139 hg st -q
402 $ python print.py < bin
140 echo modified >> linefeed
403 hello<NUL><CR><LF>
141 hg st -q
404 $ python print.py < f3
142 hg revert -a
405 some<CR><LF>text<CR><LF>
143 hg st -q
406 $ python print.py < f4.bat
144 python print.py < linefeed
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