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