| 1 |
Test EOL extension |
| 2 |
|
| 3 |
$ cat >> $HGRCPATH <<EOF |
| 4 |
> [diff] |
| 5 |
> git = True |
| 6 |
> EOF |
| 7 |
|
| 8 |
Set up helpers |
| 9 |
|
| 10 |
$ cat > switch-eol.py <<'EOF' |
| 11 |
> import os |
| 12 |
> import sys |
| 13 |
> try: |
| 14 |
> import msvcrt |
| 15 |
> msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY) |
| 16 |
> msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) |
| 17 |
> except ImportError: |
| 18 |
> pass |
| 19 |
> eolmap = {b'\n': '\\n', b'\r\n': '\\r\\n'} |
| 20 |
> (old, new) = sys.argv[1] == 'LF' and (b'\n', b'\r\n') or (b'\r\n', b'\n') |
| 21 |
> print("%% switching encoding from '%s' to '%s'" |
| 22 |
> % (eolmap[old], eolmap[new])) |
| 23 |
> for path in sys.argv[2:]: |
| 24 |
> data = open(path, 'rb').read() |
| 25 |
> data = data.replace(old, new) |
| 26 |
> open(path, 'wb').write(data) |
| 27 |
> EOF |
| 28 |
|
| 29 |
$ seteol () { |
| 30 |
> if [ $1 = "LF" ]; then |
| 31 |
> EOL='\n' |
| 32 |
> else |
| 33 |
> EOL='\r\n' |
| 34 |
> fi |
| 35 |
> } |
| 36 |
|
| 37 |
$ makerepo () { |
| 38 |
> seteol $1 |
| 39 |
> echo "% setup $1 repository" |
| 40 |
> hg init repo |
| 41 |
> cd repo |
| 42 |
> cat > .hgeol <<EOF |
| 43 |
> [repository] |
| 44 |
> native = $1 |
| 45 |
> [patterns] |
| 46 |
> mixed.txt = BIN |
| 47 |
> **.txt = native |
| 48 |
> EOF |
| 49 |
> printf "first${EOL}second${EOL}third${EOL}" > a.txt |
| 50 |
> hg commit --addremove -m 'checkin' |
| 51 |
> echo |
| 52 |
> cd .. |
| 53 |
> } |
| 54 |
|
| 55 |
$ dotest () { |
| 56 |
> seteol $1 |
| 57 |
> echo "% hg clone repo repo-$1" |
| 58 |
> hg clone --noupdate repo repo-$1 |
| 59 |
> cd repo-$1 |
| 60 |
> cat > .hg/hgrc <<EOF |
| 61 |
> [extensions] |
| 62 |
> eol = |
| 63 |
> [eol] |
| 64 |
> native = $1 |
| 65 |
> EOF |
| 66 |
> hg update |
| 67 |
> echo '% a.txt' |
| 68 |
> cat a.txt |
| 69 |
> echo '% hg cat a.txt' |
| 70 |
> hg cat a.txt |
| 71 |
> printf "fourth${EOL}" >> a.txt |
| 72 |
> echo '% a.txt' |
| 73 |
> cat a.txt |
| 74 |
> hg diff |
| 75 |
> "$PYTHON" ../switch-eol.py $1 a.txt |
| 76 |
> echo '% hg diff only reports a single changed line:' |
| 77 |
> hg diff |
| 78 |
> echo "% reverting back to $1 format" |
| 79 |
> hg revert a.txt |
| 80 |
> cat a.txt |
| 81 |
> printf "first\r\nsecond\n" > mixed.txt |
| 82 |
> hg add mixed.txt |
| 83 |
> echo "% hg commit of inconsistent .txt file marked as binary (should work)" |
| 84 |
> hg commit -m 'binary file' |
| 85 |
> echo "% hg commit of inconsistent .txt file marked as native (should fail)" |
| 86 |
> printf "first\nsecond\r\nthird\nfourth\r\n" > a.txt |
| 87 |
> hg commit -m 'inconsistent file' |
| 88 |
> echo "% hg commit --config eol.only-consistent=False (should work)" |
| 89 |
> hg commit --config eol.only-consistent=False -m 'inconsistent file' |
| 90 |
> echo "% hg commit of binary .txt file marked as native (binary files always okay)" |
| 91 |
> printf "first${EOL}\0${EOL}third${EOL}" > a.txt |
| 92 |
> hg commit -m 'binary file' |
| 93 |
> cd .. |
| 94 |
> rm -r repo-$1 |
| 95 |
> } |
| 96 |
|
| 97 |
$ makemixedrepo () { |
| 98 |
> echo |
| 99 |
> echo "# setup $1 repository" |
| 100 |
> hg init mixed |
| 101 |
> cd mixed |
| 102 |
> printf "foo\r\nbar\r\nbaz\r\n" > win.txt |
| 103 |
> printf "foo\nbar\nbaz\n" > unix.txt |
| 104 |
> #printf "foo\r\nbar\nbaz\r\n" > mixed.txt |
| 105 |
> hg commit --addremove -m 'created mixed files' |
| 106 |
> echo "# setting repository-native EOLs to $1" |
| 107 |
> cat > .hgeol <<EOF |
| 108 |
> [repository] |
| 109 |
> native = $1 |
| 110 |
> [patterns] |
| 111 |
> **.txt = native |
| 112 |
> EOF |
| 113 |
> hg commit --addremove -m 'added .hgeol' |
| 114 |
> cd .. |
| 115 |
> } |
| 116 |
|
| 117 |
$ testmixed () { |
| 118 |
> echo |
| 119 |
> echo "% hg clone mixed mixed-$1" |
| 120 |
> hg clone mixed mixed-$1 |
| 121 |
> cd mixed-$1 |
| 122 |
> echo '% hg status (eol extension not yet activated)' |
| 123 |
> hg status |
| 124 |
> cat > .hg/hgrc <<EOF |
| 125 |
> [extensions] |
| 126 |
> eol = |
| 127 |
> [eol] |
| 128 |
> native = $1 |
| 129 |
> EOF |
| 130 |
> echo '% hg status (eol activated)' |
| 131 |
> hg status |
| 132 |
> echo '% hg commit' |
| 133 |
> hg commit -m 'synchronized EOLs' |
| 134 |
> echo '% hg status' |
| 135 |
> hg status |
| 136 |
> cd .. |
| 137 |
> rm -r mixed-$1 |
| 138 |
> } |
| 139 |
|
| 140 |
Basic tests |
| 141 |
|
| 142 |
$ makerepo LF |
| 143 |
% setup LF repository |
| 144 |
adding .hgeol |
| 145 |
adding a.txt |
| 146 |
|
| 147 |
$ dotest LF |
| 148 |
% hg clone repo repo-LF |
| 149 |
2 files updated, 0 files merged, 0 files removed, 0 files unresolved |
| 150 |
% a.txt |
| 151 |
first |
| 152 |
second |
| 153 |
third |
| 154 |
% hg cat a.txt |
| 155 |
first |
| 156 |
second |
| 157 |
third |
| 158 |
% a.txt |
| 159 |
first |
| 160 |
second |
| 161 |
third |
| 162 |
fourth |
| 163 |
diff --git a/a.txt b/a.txt |
| 164 |
--- a/a.txt |
| 165 |
+++ b/a.txt |
| 166 |
@@ -1,3 +1,4 @@ |
| 167 |
first |
| 168 |
second |
| 169 |
third |
| 170 |
+fourth |
| 171 |
% switching encoding from '\n' to '\r\n' |
| 172 |
% hg diff only reports a single changed line: |
| 173 |
diff --git a/a.txt b/a.txt |
| 174 |
--- a/a.txt |
| 175 |
+++ b/a.txt |
| 176 |
@@ -1,3 +1,4 @@ |
| 177 |
first |
| 178 |
second |
| 179 |
third |
| 180 |
+fourth |
| 181 |
% reverting back to LF format |
| 182 |
first |
| 183 |
second |
| 184 |
third |
| 185 |
% hg commit of inconsistent .txt file marked as binary (should work) |
| 186 |
% hg commit of inconsistent .txt file marked as native (should fail) |
| 187 |
abort: inconsistent newline style in a.txt |
| 188 |
|
| 189 |
% hg commit --config eol.only-consistent=False (should work) |
| 190 |
% hg commit of binary .txt file marked as native (binary files always okay) |
| 191 |
$ dotest CRLF |
| 192 |
% hg clone repo repo-CRLF |
| 193 |
2 files updated, 0 files merged, 0 files removed, 0 files unresolved |
| 194 |
% a.txt |
| 195 |
first\r (esc) |
| 196 |
second\r (esc) |
| 197 |
third\r (esc) |
| 198 |
% hg cat a.txt |
| 199 |
first |
| 200 |
second |
| 201 |
third |
| 202 |
% a.txt |
| 203 |
first\r (esc) |
| 204 |
second\r (esc) |
| 205 |
third\r (esc) |
| 206 |
fourth\r (esc) |
| 207 |
diff --git a/a.txt b/a.txt |
| 208 |
--- a/a.txt |
| 209 |
+++ b/a.txt |
| 210 |
@@ -1,3 +1,4 @@ |
| 211 |
first |
| 212 |
second |
| 213 |
third |
| 214 |
+fourth |
| 215 |
% switching encoding from '\r\n' to '\n' |
| 216 |
% hg diff only reports a single changed line: |
| 217 |
diff --git a/a.txt b/a.txt |
| 218 |
--- a/a.txt |
| 219 |
+++ b/a.txt |
| 220 |
@@ -1,3 +1,4 @@ |
| 221 |
first |
| 222 |
second |
| 223 |
third |
| 224 |
+fourth |
| 225 |
% reverting back to CRLF format |
| 226 |
first\r (esc) |
| 227 |
second\r (esc) |
| 228 |
third\r (esc) |
| 229 |
% hg commit of inconsistent .txt file marked as binary (should work) |
| 230 |
% hg commit of inconsistent .txt file marked as native (should fail) |
| 231 |
abort: inconsistent newline style in a.txt |
| 232 |
|
| 233 |
% hg commit --config eol.only-consistent=False (should work) |
| 234 |
% hg commit of binary .txt file marked as native (binary files always okay) |
| 235 |
$ rm -r repo |
| 236 |
$ makerepo CRLF |
| 237 |
% setup CRLF repository |
| 238 |
adding .hgeol |
| 239 |
adding a.txt |
| 240 |
|
| 241 |
$ dotest LF |
| 242 |
% hg clone repo repo-LF |
| 243 |
2 files updated, 0 files merged, 0 files removed, 0 files unresolved |
| 244 |
% a.txt |
| 245 |
first |
| 246 |
second |
| 247 |
third |
| 248 |
% hg cat a.txt |
| 249 |
first\r (esc) |
| 250 |
second\r (esc) |
| 251 |
third\r (esc) |
| 252 |
% a.txt |
| 253 |
first |
| 254 |
second |
| 255 |
third |
| 256 |
fourth |
| 257 |
diff --git a/a.txt b/a.txt |
| 258 |
--- a/a.txt |
| 259 |
+++ b/a.txt |
| 260 |
@@ -1,3 +1,4 @@ |
| 261 |
first\r (esc) |
| 262 |
second\r (esc) |
| 263 |
third\r (esc) |
| 264 |
+fourth\r (esc) |
| 265 |
% switching encoding from '\n' to '\r\n' |
| 266 |
% hg diff only reports a single changed line: |
| 267 |
diff --git a/a.txt b/a.txt |
| 268 |
--- a/a.txt |
| 269 |
+++ b/a.txt |
| 270 |
@@ -1,3 +1,4 @@ |
| 271 |
first\r (esc) |
| 272 |
second\r (esc) |
| 273 |
third\r (esc) |
| 274 |
+fourth\r (esc) |
| 275 |
% reverting back to LF format |
| 276 |
first |
| 277 |
second |
| 278 |
third |
| 279 |
% hg commit of inconsistent .txt file marked as binary (should work) |
| 280 |
% hg commit of inconsistent .txt file marked as native (should fail) |
| 281 |
abort: inconsistent newline style in a.txt |
| 282 |
|
| 283 |
% hg commit --config eol.only-consistent=False (should work) |
| 284 |
% hg commit of binary .txt file marked as native (binary files always okay) |
| 285 |
$ dotest CRLF |
| 286 |
% hg clone repo repo-CRLF |
| 287 |
2 files updated, 0 files merged, 0 files removed, 0 files unresolved |
| 288 |
% a.txt |
| 289 |
first\r (esc) |
| 290 |
second\r (esc) |
| 291 |
third\r (esc) |
| 292 |
% hg cat a.txt |
| 293 |
first\r (esc) |
| 294 |
second\r (esc) |
| 295 |
third\r (esc) |
| 296 |
% a.txt |
| 297 |
first\r (esc) |
| 298 |
second\r (esc) |
| 299 |
third\r (esc) |
| 300 |
fourth\r (esc) |
| 301 |
diff --git a/a.txt b/a.txt |
| 302 |
--- a/a.txt |
| 303 |
+++ b/a.txt |
| 304 |
@@ -1,3 +1,4 @@ |
| 305 |
first\r (esc) |
| 306 |
second\r (esc) |
| 307 |
third\r (esc) |
| 308 |
+fourth\r (esc) |
| 309 |
% switching encoding from '\r\n' to '\n' |
| 310 |
% hg diff only reports a single changed line: |
| 311 |
diff --git a/a.txt b/a.txt |
| 312 |
--- a/a.txt |
| 313 |
+++ b/a.txt |
| 314 |
@@ -1,3 +1,4 @@ |
| 315 |
first\r (esc) |
| 316 |
second\r (esc) |
| 317 |
third\r (esc) |
| 318 |
+fourth\r (esc) |
| 319 |
% reverting back to CRLF format |
| 320 |
first\r (esc) |
| 321 |
second\r (esc) |
| 322 |
third\r (esc) |
| 323 |
% hg commit of inconsistent .txt file marked as binary (should work) |
| 324 |
% hg commit of inconsistent .txt file marked as native (should fail) |
| 325 |
abort: inconsistent newline style in a.txt |
| 326 |
|
| 327 |
% hg commit --config eol.only-consistent=False (should work) |
| 328 |
% hg commit of binary .txt file marked as native (binary files always okay) |
| 329 |
$ rm -r repo |
| 330 |
|
| 331 |
Mixed tests |
| 332 |
|
| 333 |
$ makemixedrepo LF |
| 334 |
|
| 335 |
# setup LF repository |
| 336 |
adding unix.txt |
| 337 |
adding win.txt |
| 338 |
# setting repository-native EOLs to LF |
| 339 |
adding .hgeol |
| 340 |
$ testmixed LF |
| 341 |
|
| 342 |
% hg clone mixed mixed-LF |
| 343 |
updating to branch default |
| 344 |
3 files updated, 0 files merged, 0 files removed, 0 files unresolved |
| 345 |
% hg status (eol extension not yet activated) |
| 346 |
% hg status (eol activated) |
| 347 |
M win.txt |
| 348 |
% hg commit |
| 349 |
% hg status |
| 350 |
$ testmixed CRLF |
| 351 |
|
| 352 |
% hg clone mixed mixed-CRLF |
| 353 |
updating to branch default |
| 354 |
3 files updated, 0 files merged, 0 files removed, 0 files unresolved |
| 355 |
% hg status (eol extension not yet activated) |
| 356 |
% hg status (eol activated) |
| 357 |
M win.txt |
| 358 |
% hg commit |
| 359 |
% hg status |
| 360 |
$ rm -r mixed |
| 361 |
$ makemixedrepo CRLF |
| 362 |
|
| 363 |
# setup CRLF repository |
| 364 |
adding unix.txt |
| 365 |
adding win.txt |
| 366 |
# setting repository-native EOLs to CRLF |
| 367 |
adding .hgeol |
| 368 |
$ testmixed LF |
| 369 |
|
| 370 |
% hg clone mixed mixed-LF |
| 371 |
updating to branch default |
| 372 |
3 files updated, 0 files merged, 0 files removed, 0 files unresolved |
| 373 |
% hg status (eol extension not yet activated) |
| 374 |
% hg status (eol activated) |
| 375 |
M unix.txt |
| 376 |
% hg commit |
| 377 |
% hg status |
| 378 |
$ testmixed CRLF |
| 379 |
|
| 380 |
% hg clone mixed mixed-CRLF |
| 381 |
updating to branch default |
| 382 |
3 files updated, 0 files merged, 0 files removed, 0 files unresolved |
| 383 |
% hg status (eol extension not yet activated) |
| 384 |
% hg status (eol activated) |
| 385 |
M unix.txt |
| 386 |
% hg commit |
| 387 |
% hg status |
| 388 |
$ rm -r mixed |
| 389 |
|
| 390 |
$ echo '[extensions]' >> $HGRCPATH |
| 391 |
$ echo 'eol =' >> $HGRCPATH |
| 392 |
|
| 393 |
#if unix-permissions |
| 394 |
|
| 395 |
Test issue2569 -- eol extension takes write lock on reading: |
| 396 |
|
| 397 |
$ hg init repo |
| 398 |
$ cd repo |
| 399 |
$ touch .hgeol |
| 400 |
$ hg status |
| 401 |
? .hgeol |
| 402 |
$ chmod -R -w .hg |
| 403 |
$ sleep 1 |
| 404 |
$ touch .hgeol |
| 405 |
$ hg status --traceback |
| 406 |
? .hgeol |
| 407 |
$ chmod -R u+w .hg |
| 408 |
$ cd .. |
| 409 |
|
| 410 |
#endif |
| 411 |
|
| 412 |
Test cleverencode: and cleverdecode: aliases for win32text extension |
| 413 |
|
| 414 |
$ cat <<EOF >> $HGRCPATH |
| 415 |
> [encode] |
| 416 |
> **.txt = cleverencode: |
| 417 |
> [decode] |
| 418 |
> **.txt = cleverdecode: |
| 419 |
> EOF |
| 420 |
|
| 421 |
$ hg init win32compat |
| 422 |
$ cd win32compat |
| 423 |
$ printf "foo\r\nbar\r\nbaz\r\n" > win.txt |
| 424 |
$ printf "foo\nbar\nbaz\n" > unix.txt |
| 425 |
$ hg add |
| 426 |
adding unix.txt |
| 427 |
adding win.txt |
| 428 |
$ hg commit -m checkin |
| 429 |
|
| 430 |
Check that both files have LF line-endings in the repository: |
| 431 |
|
| 432 |
$ hg cat win.txt |
| 433 |
foo |
| 434 |
bar |
| 435 |
baz |
| 436 |
$ hg cat unix.txt |
| 437 |
foo |
| 438 |
bar |
| 439 |
baz |
| 440 |
|
| 441 |
Test handling of a broken .hgeol file: |
| 442 |
|
| 443 |
$ touch .hgeol |
| 444 |
$ hg add .hgeol |
| 445 |
$ hg commit -m 'clean version' |
| 446 |
$ echo "bad" > .hgeol |
| 447 |
$ hg status |
| 448 |
warning: ignoring .hgeol file due to parse error at .hgeol:1: bad |
| 449 |
M .hgeol |
| 450 |
$ hg revert .hgeol |
| 451 |
warning: ignoring .hgeol file due to parse error at .hgeol:1: bad |
| 452 |
$ hg status |
| 453 |
? .hgeol.orig |
| 454 |
|
| 455 |
Test eol.only-consistent can be specified in .hgeol |
| 456 |
|
| 457 |
$ cd $TESTTMP |
| 458 |
$ hg init only-consistent |
| 459 |
$ cd only-consistent |
| 460 |
$ printf "first\nsecond\r\n" > a.txt |
| 461 |
$ hg add a.txt |
| 462 |
$ cat > .hgeol << EOF |
| 463 |
> [eol] |
| 464 |
> only-consistent = True |
| 465 |
> EOF |
| 466 |
$ hg commit -m 'inconsistent' |
| 467 |
abort: inconsistent newline style in a.txt |
| 468 |
|
| 469 |
[255] |
| 470 |
$ cat > .hgeol << EOF |
| 471 |
> [eol] |
| 472 |
> only-consistent = False |
| 473 |
> EOF |
| 474 |
$ hg commit -m 'consistent' |
| 475 |
|
| 476 |
$ hg init subrepo |
| 477 |
$ hg -R subrepo pull -qu . |
| 478 |
$ echo "subrepo = subrepo" > .hgsub |
| 479 |
$ hg ci -Am "add subrepo" |
| 480 |
adding .hgeol |
| 481 |
adding .hgsub |
| 482 |
$ hg archive -S ../archive |
| 483 |
$ find ../archive/* | sort |
| 484 |
../archive/a.txt |
| 485 |
../archive/subrepo |
| 486 |
../archive/subrepo/a.txt |
| 487 |
$ cat ../archive/a.txt ../archive/subrepo/a.txt |
| 488 |
first\r (esc) |
| 489 |
second\r (esc) |
| 490 |
first\r (esc) |
| 491 |
second\r (esc) |
| 492 |
|
| 493 |
Test trailing newline |
| 494 |
|
| 495 |
$ cat >> $HGRCPATH <<EOF |
| 496 |
> [extensions] |
| 497 |
> eol= |
| 498 |
> EOF |
| 499 |
|
| 500 |
setup repository |
| 501 |
|
| 502 |
$ cd $TESTTMP |
| 503 |
$ hg init trailing |
| 504 |
$ cd trailing |
| 505 |
$ cat > .hgeol <<EOF |
| 506 |
> [patterns] |
| 507 |
> **.txt = native |
| 508 |
> [eol] |
| 509 |
> fix-trailing-newline = False |
| 510 |
> EOF |
| 511 |
|
| 512 |
add text without trailing newline |
| 513 |
|
| 514 |
$ printf "first\nsecond" > a.txt |
| 515 |
$ hg commit --addremove -m 'checking in' |
| 516 |
adding .hgeol |
| 517 |
adding a.txt |
| 518 |
$ rm a.txt |
| 519 |
$ hg update -C -q |
| 520 |
$ cat a.txt |
| 521 |
first |
| 522 |
second (no-eol) |
| 523 |
|
| 524 |
$ cat > .hgeol <<EOF |
| 525 |
> [patterns] |
| 526 |
> **.txt = native |
| 527 |
> [eol] |
| 528 |
> fix-trailing-newline = True |
| 529 |
> EOF |
| 530 |
$ printf "third\nfourth" > a.txt |
| 531 |
$ hg commit -m 'checking in with newline fix' |
| 532 |
$ rm a.txt |
| 533 |
$ hg update -C -q |
| 534 |
$ cat a.txt |
| 535 |
third |
| 536 |
fourth |
| 537 |
|
| 538 |
append a line without trailing newline |
| 539 |
|
| 540 |
$ printf "fifth" >> a.txt |
| 541 |
$ hg commit -m 'adding another line line' |
| 542 |
$ rm a.txt |
| 543 |
$ hg update -C -q |
| 544 |
$ cat a.txt |
| 545 |
third |
| 546 |
fourth |
| 547 |
fifth |
| 548 |
|
| 549 |
amend of changesets with renamed/deleted files expose new code paths |
| 550 |
|
| 551 |
$ hg mv a.txt b.txt |
| 552 |
$ hg ci --amend -q |
| 553 |
$ hg diff -c. |
| 554 |
diff --git a/a.txt b/b.txt |
| 555 |
rename from a.txt |
| 556 |
rename to b.txt |
| 557 |
--- a/a.txt |
| 558 |
+++ b/b.txt |
| 559 |
@@ -1,2 +1,3 @@ |
| 560 |
third |
| 561 |
fourth |
| 562 |
+fifth |
| 563 |
|
| 564 |
$ cd .. |