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