Show More
@@ -1,442 +1,443 | |||
|
1 | 1 | Test EOL extension |
|
2 | 2 | |
|
3 | 3 | $ cat > $HGRCPATH <<EOF |
|
4 | 4 | > [diff] |
|
5 | 5 | > git = True |
|
6 | 6 | > EOF |
|
7 | 7 | |
|
8 | 8 | Set up helpers |
|
9 | 9 | |
|
10 | 10 | $ cat > switch-eol.py <<EOF |
|
11 | 11 | > import sys |
|
12 | 12 | > try: |
|
13 | 13 | > import os, msvcrt |
|
14 | 14 | > msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY) |
|
15 | 15 | > msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) |
|
16 | 16 | > except ImportError: |
|
17 | 17 | > pass |
|
18 | 18 | > (old, new) = sys.argv[1] == 'LF' and ('\n', '\r\n') or ('\r\n', '\n') |
|
19 | 19 | > print "%% switching encoding from %r to %r" % (old, new) |
|
20 | 20 | > for path in sys.argv[2:]: |
|
21 | 21 | > data = file(path, 'rb').read() |
|
22 | 22 | > data = data.replace(old, new) |
|
23 | 23 | > file(path, 'wb').write(data) |
|
24 | 24 | > EOF |
|
25 | 25 | |
|
26 | 26 | $ seteol () { |
|
27 | 27 | > if [ $1 = "LF" ]; then |
|
28 | 28 | > EOL='\n' |
|
29 | 29 | > else |
|
30 | 30 | > EOL='\r\n' |
|
31 | 31 | > fi |
|
32 | 32 | > } |
|
33 | 33 | |
|
34 | 34 | $ makerepo () { |
|
35 | 35 | > seteol $1 |
|
36 | 36 | > echo "% setup $1 repository" |
|
37 | 37 | > hg init repo |
|
38 | 38 | > cd repo |
|
39 | 39 | > cat > .hgeol <<EOF |
|
40 | 40 | > [repository] |
|
41 | 41 | > native = $1 |
|
42 | 42 | > [patterns] |
|
43 | 43 | > mixed.txt = BIN |
|
44 | 44 | > **.txt = native |
|
45 | 45 | > EOF |
|
46 | 46 | > printf "first${EOL}second${EOL}third${EOL}" > a.txt |
|
47 | 47 | > hg commit --addremove -m 'checkin' |
|
48 | 48 | > echo |
|
49 | 49 | > cd .. |
|
50 | 50 | > } |
|
51 | 51 | |
|
52 | 52 | $ dotest () { |
|
53 | 53 | > seteol $1 |
|
54 | 54 | > echo "% hg clone repo repo-$1" |
|
55 | 55 | > hg clone --noupdate repo repo-$1 |
|
56 | 56 | > cd repo-$1 |
|
57 | 57 | > cat > .hg/hgrc <<EOF |
|
58 | 58 | > [extensions] |
|
59 | 59 | > eol = |
|
60 | 60 | > [eol] |
|
61 | 61 | > native = $1 |
|
62 | 62 | > EOF |
|
63 | 63 | > hg update |
|
64 | 64 | > echo '% a.txt' |
|
65 | 65 | > cat a.txt |
|
66 | 66 | > echo '% hg cat a.txt' |
|
67 | 67 | > hg cat a.txt |
|
68 | 68 | > printf "fourth${EOL}" >> a.txt |
|
69 | 69 | > echo '% a.txt' |
|
70 | 70 | > cat a.txt |
|
71 | 71 | > hg diff |
|
72 | 72 | > python ../switch-eol.py $1 a.txt |
|
73 | 73 | > echo '% hg diff only reports a single changed line:' |
|
74 | 74 | > hg diff |
|
75 | 75 | > echo "% reverting back to $1 format" |
|
76 | 76 | > hg revert a.txt |
|
77 | 77 | > cat a.txt |
|
78 | 78 | > printf "first\r\nsecond\n" > mixed.txt |
|
79 | 79 | > hg add mixed.txt |
|
80 | 80 | > echo "% hg commit of inconsistent .txt file marked as binary (should work)" |
|
81 | 81 | > hg commit -m 'binary file' |
|
82 | 82 | > echo "% hg commit of inconsistent .txt file marked as native (should fail)" |
|
83 | 83 | > printf "first\nsecond\r\nthird\nfourth\r\n" > a.txt |
|
84 | 84 | > hg commit -m 'inconsistent file' |
|
85 | 85 | > echo "% hg commit --config eol.only-consistent=False (should work)" |
|
86 | 86 | > hg commit --config eol.only-consistent=False -m 'inconsistent file' |
|
87 | 87 | > echo "% hg commit of binary .txt file marked as native (binary files always okay)" |
|
88 | 88 | > printf "first${EOL}\0${EOL}third${EOL}" > a.txt |
|
89 | 89 | > hg commit -m 'binary file' |
|
90 | 90 | > cd .. |
|
91 | 91 | > rm -r repo-$1 |
|
92 | 92 | > } |
|
93 | 93 | |
|
94 | 94 | $ makemixedrepo () { |
|
95 | 95 | > echo |
|
96 | 96 | > echo "# setup $1 repository" |
|
97 | 97 | > hg init mixed |
|
98 | 98 | > cd mixed |
|
99 | 99 | > printf "foo\r\nbar\r\nbaz\r\n" > win.txt |
|
100 | 100 | > printf "foo\nbar\nbaz\n" > unix.txt |
|
101 | 101 | > #printf "foo\r\nbar\nbaz\r\n" > mixed.txt |
|
102 | 102 | > hg commit --addremove -m 'created mixed files' |
|
103 | 103 | > echo "# setting repository-native EOLs to $1" |
|
104 | 104 | > cat > .hgeol <<EOF |
|
105 | 105 | > [repository] |
|
106 | 106 | > native = $1 |
|
107 | 107 | > [patterns] |
|
108 | 108 | > **.txt = native |
|
109 | 109 | > EOF |
|
110 | 110 | > hg commit --addremove -m 'added .hgeol' |
|
111 | 111 | > cd .. |
|
112 | 112 | > } |
|
113 | 113 | |
|
114 | 114 | $ testmixed () { |
|
115 | 115 | > echo |
|
116 | 116 | > echo "% hg clone mixed mixed-$1" |
|
117 | 117 | > hg clone mixed mixed-$1 |
|
118 | 118 | > cd mixed-$1 |
|
119 | 119 | > echo '% hg status (eol extension not yet activated)' |
|
120 | 120 | > hg status |
|
121 | 121 | > cat > .hg/hgrc <<EOF |
|
122 | 122 | > [extensions] |
|
123 | 123 | > eol = |
|
124 | 124 | > [eol] |
|
125 | 125 | > native = $1 |
|
126 | 126 | > EOF |
|
127 | 127 | > echo '% hg status (eol activated)' |
|
128 | 128 | > hg status |
|
129 | 129 | > echo '% hg commit' |
|
130 | 130 | > hg commit -m 'synchronized EOLs' |
|
131 | 131 | > echo '% hg status' |
|
132 | 132 | > hg status |
|
133 | 133 | > cd .. |
|
134 | 134 | > rm -r mixed-$1 |
|
135 | 135 | > } |
|
136 | 136 | |
|
137 | 137 | Basic tests |
|
138 | 138 | |
|
139 | 139 | $ makerepo LF |
|
140 | 140 | % setup LF repository |
|
141 | 141 | adding .hgeol |
|
142 | 142 | adding a.txt |
|
143 | 143 | |
|
144 | 144 | $ dotest LF |
|
145 | 145 | % hg clone repo repo-LF |
|
146 | 146 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
147 | 147 | % a.txt |
|
148 | 148 | first |
|
149 | 149 | second |
|
150 | 150 | third |
|
151 | 151 | % hg cat a.txt |
|
152 | 152 | first |
|
153 | 153 | second |
|
154 | 154 | third |
|
155 | 155 | % a.txt |
|
156 | 156 | first |
|
157 | 157 | second |
|
158 | 158 | third |
|
159 | 159 | fourth |
|
160 | 160 | diff --git a/a.txt b/a.txt |
|
161 | 161 | --- a/a.txt |
|
162 | 162 | +++ b/a.txt |
|
163 | 163 | @@ -1,3 +1,4 @@ |
|
164 | 164 | first |
|
165 | 165 | second |
|
166 | 166 | third |
|
167 | 167 | +fourth |
|
168 | 168 | % switching encoding from '\n' to '\r\n' |
|
169 | 169 | % hg diff only reports a single changed line: |
|
170 | 170 | diff --git a/a.txt b/a.txt |
|
171 | 171 | --- a/a.txt |
|
172 | 172 | +++ b/a.txt |
|
173 | 173 | @@ -1,3 +1,4 @@ |
|
174 | 174 | first |
|
175 | 175 | second |
|
176 | 176 | third |
|
177 | 177 | +fourth |
|
178 | 178 | % reverting back to LF format |
|
179 | 179 | first |
|
180 | 180 | second |
|
181 | 181 | third |
|
182 | 182 | % hg commit of inconsistent .txt file marked as binary (should work) |
|
183 | 183 | % hg commit of inconsistent .txt file marked as native (should fail) |
|
184 | 184 | abort: inconsistent newline style in a.txt |
|
185 | 185 | |
|
186 | 186 | % hg commit --config eol.only-consistent=False (should work) |
|
187 | 187 | % hg commit of binary .txt file marked as native (binary files always okay) |
|
188 | 188 | $ dotest CRLF |
|
189 | 189 | % hg clone repo repo-CRLF |
|
190 | 190 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
191 | 191 | % a.txt |
|
192 | 192 | first\r (esc) |
|
193 | 193 | second\r (esc) |
|
194 | 194 | third\r (esc) |
|
195 | 195 | % hg cat a.txt |
|
196 | 196 | first |
|
197 | 197 | second |
|
198 | 198 | third |
|
199 | 199 | % a.txt |
|
200 | 200 | first\r (esc) |
|
201 | 201 | second\r (esc) |
|
202 | 202 | third\r (esc) |
|
203 | 203 | fourth\r (esc) |
|
204 | 204 | diff --git a/a.txt b/a.txt |
|
205 | 205 | --- a/a.txt |
|
206 | 206 | +++ b/a.txt |
|
207 | 207 | @@ -1,3 +1,4 @@ |
|
208 | 208 | first |
|
209 | 209 | second |
|
210 | 210 | third |
|
211 | 211 | +fourth |
|
212 | 212 | % switching encoding from '\r\n' to '\n' |
|
213 | 213 | % hg diff only reports a single changed line: |
|
214 | 214 | diff --git a/a.txt b/a.txt |
|
215 | 215 | --- a/a.txt |
|
216 | 216 | +++ b/a.txt |
|
217 | 217 | @@ -1,3 +1,4 @@ |
|
218 | 218 | first |
|
219 | 219 | second |
|
220 | 220 | third |
|
221 | 221 | +fourth |
|
222 | 222 | % reverting back to CRLF format |
|
223 | 223 | first\r (esc) |
|
224 | 224 | second\r (esc) |
|
225 | 225 | third\r (esc) |
|
226 | 226 | % hg commit of inconsistent .txt file marked as binary (should work) |
|
227 | 227 | % hg commit of inconsistent .txt file marked as native (should fail) |
|
228 | 228 | abort: inconsistent newline style in a.txt |
|
229 | 229 | |
|
230 | 230 | % hg commit --config eol.only-consistent=False (should work) |
|
231 | 231 | % hg commit of binary .txt file marked as native (binary files always okay) |
|
232 | 232 | $ rm -r repo |
|
233 | 233 | $ makerepo CRLF |
|
234 | 234 | % setup CRLF repository |
|
235 | 235 | adding .hgeol |
|
236 | 236 | adding a.txt |
|
237 | 237 | |
|
238 | 238 | $ dotest LF |
|
239 | 239 | % hg clone repo repo-LF |
|
240 | 240 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
241 | 241 | % a.txt |
|
242 | 242 | first |
|
243 | 243 | second |
|
244 | 244 | third |
|
245 | 245 | % hg cat a.txt |
|
246 | 246 | first\r (esc) |
|
247 | 247 | second\r (esc) |
|
248 | 248 | third\r (esc) |
|
249 | 249 | % a.txt |
|
250 | 250 | first |
|
251 | 251 | second |
|
252 | 252 | third |
|
253 | 253 | fourth |
|
254 | 254 | diff --git a/a.txt b/a.txt |
|
255 | 255 | --- a/a.txt |
|
256 | 256 | +++ b/a.txt |
|
257 | 257 | @@ -1,3 +1,4 @@ |
|
258 | 258 | first\r (esc) |
|
259 | 259 | second\r (esc) |
|
260 | 260 | third\r (esc) |
|
261 | 261 | +fourth\r (esc) |
|
262 | 262 | % switching encoding from '\n' to '\r\n' |
|
263 | 263 | % hg diff only reports a single changed line: |
|
264 | 264 | diff --git a/a.txt b/a.txt |
|
265 | 265 | --- a/a.txt |
|
266 | 266 | +++ b/a.txt |
|
267 | 267 | @@ -1,3 +1,4 @@ |
|
268 | 268 | first\r (esc) |
|
269 | 269 | second\r (esc) |
|
270 | 270 | third\r (esc) |
|
271 | 271 | +fourth\r (esc) |
|
272 | 272 | % reverting back to LF format |
|
273 | 273 | first |
|
274 | 274 | second |
|
275 | 275 | third |
|
276 | 276 | % hg commit of inconsistent .txt file marked as binary (should work) |
|
277 | 277 | % hg commit of inconsistent .txt file marked as native (should fail) |
|
278 | 278 | abort: inconsistent newline style in a.txt |
|
279 | 279 | |
|
280 | 280 | % hg commit --config eol.only-consistent=False (should work) |
|
281 | 281 | % hg commit of binary .txt file marked as native (binary files always okay) |
|
282 | 282 | $ dotest CRLF |
|
283 | 283 | % hg clone repo repo-CRLF |
|
284 | 284 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
285 | 285 | % a.txt |
|
286 | 286 | first\r (esc) |
|
287 | 287 | second\r (esc) |
|
288 | 288 | third\r (esc) |
|
289 | 289 | % hg cat a.txt |
|
290 | 290 | first\r (esc) |
|
291 | 291 | second\r (esc) |
|
292 | 292 | third\r (esc) |
|
293 | 293 | % a.txt |
|
294 | 294 | first\r (esc) |
|
295 | 295 | second\r (esc) |
|
296 | 296 | third\r (esc) |
|
297 | 297 | fourth\r (esc) |
|
298 | 298 | diff --git a/a.txt b/a.txt |
|
299 | 299 | --- a/a.txt |
|
300 | 300 | +++ b/a.txt |
|
301 | 301 | @@ -1,3 +1,4 @@ |
|
302 | 302 | first\r (esc) |
|
303 | 303 | second\r (esc) |
|
304 | 304 | third\r (esc) |
|
305 | 305 | +fourth\r (esc) |
|
306 | 306 | % switching encoding from '\r\n' to '\n' |
|
307 | 307 | % hg diff only reports a single changed line: |
|
308 | 308 | diff --git a/a.txt b/a.txt |
|
309 | 309 | --- a/a.txt |
|
310 | 310 | +++ b/a.txt |
|
311 | 311 | @@ -1,3 +1,4 @@ |
|
312 | 312 | first\r (esc) |
|
313 | 313 | second\r (esc) |
|
314 | 314 | third\r (esc) |
|
315 | 315 | +fourth\r (esc) |
|
316 | 316 | % reverting back to CRLF format |
|
317 | 317 | first\r (esc) |
|
318 | 318 | second\r (esc) |
|
319 | 319 | third\r (esc) |
|
320 | 320 | % hg commit of inconsistent .txt file marked as binary (should work) |
|
321 | 321 | % hg commit of inconsistent .txt file marked as native (should fail) |
|
322 | 322 | abort: inconsistent newline style in a.txt |
|
323 | 323 | |
|
324 | 324 | % hg commit --config eol.only-consistent=False (should work) |
|
325 | 325 | % hg commit of binary .txt file marked as native (binary files always okay) |
|
326 | 326 | $ rm -r repo |
|
327 | 327 | |
|
328 | 328 | Mixed tests |
|
329 | 329 | |
|
330 | 330 | $ makemixedrepo LF |
|
331 | 331 | |
|
332 | 332 | # setup LF repository |
|
333 | 333 | adding unix.txt |
|
334 | 334 | adding win.txt |
|
335 | 335 | # setting repository-native EOLs to LF |
|
336 | 336 | adding .hgeol |
|
337 | 337 | $ testmixed LF |
|
338 | 338 | |
|
339 | 339 | % hg clone mixed mixed-LF |
|
340 | 340 | updating to branch default |
|
341 | 341 | 3 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
342 | 342 | % hg status (eol extension not yet activated) |
|
343 | 343 | % hg status (eol activated) |
|
344 | 344 | M win.txt |
|
345 | 345 | % hg commit |
|
346 | 346 | % hg status |
|
347 | 347 | $ testmixed CRLF |
|
348 | 348 | |
|
349 | 349 | % hg clone mixed mixed-CRLF |
|
350 | 350 | updating to branch default |
|
351 | 351 | 3 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
352 | 352 | % hg status (eol extension not yet activated) |
|
353 | 353 | % hg status (eol activated) |
|
354 | 354 | M win.txt |
|
355 | 355 | % hg commit |
|
356 | 356 | % hg status |
|
357 | 357 | $ rm -r mixed |
|
358 | 358 | $ makemixedrepo CRLF |
|
359 | 359 | |
|
360 | 360 | # setup CRLF repository |
|
361 | 361 | adding unix.txt |
|
362 | 362 | adding win.txt |
|
363 | 363 | # setting repository-native EOLs to CRLF |
|
364 | 364 | adding .hgeol |
|
365 | 365 | $ testmixed LF |
|
366 | 366 | |
|
367 | 367 | % hg clone mixed mixed-LF |
|
368 | 368 | updating to branch default |
|
369 | 369 | 3 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
370 | 370 | % hg status (eol extension not yet activated) |
|
371 | 371 | % hg status (eol activated) |
|
372 | 372 | M unix.txt |
|
373 | 373 | % hg commit |
|
374 | 374 | % hg status |
|
375 | 375 | $ testmixed CRLF |
|
376 | 376 | |
|
377 | 377 | % hg clone mixed mixed-CRLF |
|
378 | 378 | updating to branch default |
|
379 | 379 | 3 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
380 | 380 | % hg status (eol extension not yet activated) |
|
381 | 381 | % hg status (eol activated) |
|
382 | 382 | M unix.txt |
|
383 | 383 | % hg commit |
|
384 | 384 | % hg status |
|
385 | 385 | $ rm -r mixed |
|
386 | 386 | |
|
387 | 387 | Test issue2569 -- eol extension takes write lock on reading: |
|
388 | 388 | |
|
389 | 389 | $ echo '[extensions]' >> $HGRCPATH |
|
390 | 390 | $ echo 'eol =' >> $HGRCPATH |
|
391 | 391 | $ hg init repo |
|
392 | 392 | $ cd repo |
|
393 | 393 | $ touch .hgeol |
|
394 | 394 | $ hg status |
|
395 | 395 | ? .hgeol |
|
396 | 396 | $ chmod -R -w .hg |
|
397 | 397 | $ sleep 1 |
|
398 | 398 | $ touch .hgeol |
|
399 | 399 | $ hg status --traceback |
|
400 | 400 | ? .hgeol |
|
401 | $ chmod -R u+w .hg | |
|
401 | 402 | $ cd .. |
|
402 | 403 | |
|
403 | 404 | Test cleverencode: and cleverdecode: aliases for win32text extension |
|
404 | 405 | |
|
405 | 406 | $ echo '[encode]' >> $HGRCPATH |
|
406 | 407 | $ echo '**.txt = cleverencode:' >> $HGRCPATH |
|
407 | 408 | $ echo '[decode]' >> $HGRCPATH |
|
408 | 409 | $ echo '**.txt = cleverdecode:' >> $HGRCPATH |
|
409 | 410 | |
|
410 | 411 | $ hg init win32compat |
|
411 | 412 | $ cd win32compat |
|
412 | 413 | $ printf "foo\r\nbar\r\nbaz\r\n" > win.txt |
|
413 | 414 | $ printf "foo\nbar\nbaz\n" > unix.txt |
|
414 | 415 | $ hg add |
|
415 | 416 | adding unix.txt |
|
416 | 417 | adding win.txt |
|
417 | 418 | $ hg commit -m checkin |
|
418 | 419 | |
|
419 | 420 | Check that both files have LF line-endings in the repository: |
|
420 | 421 | |
|
421 | 422 | $ hg cat win.txt |
|
422 | 423 | foo |
|
423 | 424 | bar |
|
424 | 425 | baz |
|
425 | 426 | $ hg cat unix.txt |
|
426 | 427 | foo |
|
427 | 428 | bar |
|
428 | 429 | baz |
|
429 | 430 | |
|
430 | 431 | Test handling of a broken .hgeol file: |
|
431 | 432 | |
|
432 | 433 | $ touch .hgeol |
|
433 | 434 | $ hg add .hgeol |
|
434 | 435 | $ hg commit -m 'clean version' |
|
435 | 436 | $ echo "bad" > .hgeol |
|
436 | 437 | $ hg status |
|
437 | 438 | warning: ignoring .hgeol file due to parse error at .hgeol:1: bad |
|
438 | 439 | M .hgeol |
|
439 | 440 | $ hg revert .hgeol |
|
440 | 441 | warning: ignoring .hgeol file due to parse error at .hgeol:1: bad |
|
441 | 442 | $ hg status |
|
442 | 443 | ? .hgeol.orig |
General Comments 0
You need to be logged in to leave comments.
Login now