Mercurial > hg > hg-fastimport
comparison hgext3rd/fastimport/vendor/python_fastimport/tests/test_filter_processor.py @ 86:28704a2a7461 vendor/python-fastimport
Import python-fastimport-0.9.8
| author | Roy Marples <roy@marples.name> |
|---|---|
| date | Tue, 19 Jan 2021 22:56:34 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 85:1f5544a8870b | 86:28704a2a7461 |
|---|---|
| 1 # Copyright (C) 2009 Canonical Ltd | |
| 2 # | |
| 3 # This program is free software; you can redistribute it and/or modify | |
| 4 # it under the terms of the GNU General Public License as published by | |
| 5 # the Free Software Foundation; either version 2 of the License, or | |
| 6 # (at your option) any later version. | |
| 7 # | |
| 8 # This program is distributed in the hope that it will be useful, | |
| 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 11 # GNU General Public License for more details. | |
| 12 # | |
| 13 # You should have received a copy of the GNU General Public License | |
| 14 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| 15 | |
| 16 """Test FilterProcessor""" | |
| 17 from io import BytesIO | |
| 18 | |
| 19 from unittest import TestCase | |
| 20 | |
| 21 from fastimport import ( | |
| 22 parser, | |
| 23 ) | |
| 24 | |
| 25 from fastimport.processors import ( | |
| 26 filter_processor, | |
| 27 ) | |
| 28 | |
| 29 | |
| 30 # A sample input stream containing all (top level) import commands | |
| 31 _SAMPLE_ALL = \ | |
| 32 b"""blob | |
| 33 mark :1 | |
| 34 data 4 | |
| 35 foo | |
| 36 commit refs/heads/master | |
| 37 mark :2 | |
| 38 committer Joe <joe@example.com> 1234567890 +1000 | |
| 39 data 14 | |
| 40 Initial import | |
| 41 M 644 :1 COPYING | |
| 42 checkpoint | |
| 43 progress first import done | |
| 44 reset refs/remote/origin/master | |
| 45 from :2 | |
| 46 tag v0.1 | |
| 47 from :2 | |
| 48 tagger Joe <joe@example.com> 1234567890 +1000 | |
| 49 data 12 | |
| 50 release v0.1 | |
| 51 """ | |
| 52 | |
| 53 | |
| 54 # A sample input stream creating the following tree: | |
| 55 # | |
| 56 # NEWS | |
| 57 # doc/README.txt | |
| 58 # doc/index.txt | |
| 59 _SAMPLE_WITH_DIR = \ | |
| 60 b"""blob | |
| 61 mark :1 | |
| 62 data 9 | |
| 63 Welcome! | |
| 64 commit refs/heads/master | |
| 65 mark :100 | |
| 66 committer a <b@c> 1234798653 +0000 | |
| 67 data 4 | |
| 68 test | |
| 69 M 644 :1 doc/README.txt | |
| 70 blob | |
| 71 mark :2 | |
| 72 data 17 | |
| 73 Life | |
| 74 is | |
| 75 good ... | |
| 76 commit refs/heads/master | |
| 77 mark :101 | |
| 78 committer a <b@c> 1234798653 +0000 | |
| 79 data 8 | |
| 80 test | |
| 81 ing | |
| 82 from :100 | |
| 83 M 644 :2 NEWS | |
| 84 blob | |
| 85 mark :3 | |
| 86 data 19 | |
| 87 Welcome! | |
| 88 my friend | |
| 89 blob | |
| 90 mark :4 | |
| 91 data 11 | |
| 92 == Docs == | |
| 93 commit refs/heads/master | |
| 94 mark :102 | |
| 95 committer d <b@c> 1234798653 +0000 | |
| 96 data 8 | |
| 97 test | |
| 98 ing | |
| 99 from :101 | |
| 100 M 644 :3 doc/README.txt | |
| 101 M 644 :4 doc/index.txt | |
| 102 """ | |
| 103 | |
| 104 class TestCaseWithFiltering(TestCase): | |
| 105 | |
| 106 def assertFiltering(self, input_stream, params, expected): | |
| 107 outf = BytesIO() | |
| 108 proc = filter_processor.FilterProcessor( | |
| 109 params=params) | |
| 110 proc.outf = outf | |
| 111 s = BytesIO(input_stream) | |
| 112 p = parser.ImportParser(s) | |
| 113 proc.process(p.iter_commands) | |
| 114 out = outf.getvalue() | |
| 115 self.assertEqual(expected, out) | |
| 116 | |
| 117 class TestNoFiltering(TestCaseWithFiltering): | |
| 118 | |
| 119 def test_params_not_given(self): | |
| 120 self.assertFiltering(_SAMPLE_ALL, None, _SAMPLE_ALL) | |
| 121 | |
| 122 def test_params_are_none(self): | |
| 123 params = {b'include_paths': None, b'exclude_paths': None} | |
| 124 self.assertFiltering(_SAMPLE_ALL, params, _SAMPLE_ALL) | |
| 125 | |
| 126 | |
| 127 class TestIncludePaths(TestCaseWithFiltering): | |
| 128 | |
| 129 def test_file_in_root(self): | |
| 130 # Things to note: | |
| 131 # * only referenced blobs are retained | |
| 132 # * from clause is dropped from the first command | |
| 133 params = {b'include_paths': [b'NEWS']} | |
| 134 self.assertFiltering(_SAMPLE_WITH_DIR, params, \ | |
| 135 b"""blob | |
| 136 mark :2 | |
| 137 data 17 | |
| 138 Life | |
| 139 is | |
| 140 good ... | |
| 141 commit refs/heads/master | |
| 142 mark :101 | |
| 143 committer a <b@c> 1234798653 +0000 | |
| 144 data 8 | |
| 145 test | |
| 146 ing | |
| 147 M 644 :2 NEWS | |
| 148 """) | |
| 149 | |
| 150 def test_file_in_subdir(self): | |
| 151 # Additional things to note: | |
| 152 # * new root: path is now index.txt, not doc/index.txt | |
| 153 # * other files changed in matching commits are excluded | |
| 154 params = {b'include_paths': [b'doc/index.txt']} | |
| 155 self.assertFiltering(_SAMPLE_WITH_DIR, params, \ | |
| 156 b"""blob | |
| 157 mark :4 | |
| 158 data 11 | |
| 159 == Docs == | |
| 160 commit refs/heads/master | |
| 161 mark :102 | |
| 162 committer d <b@c> 1234798653 +0000 | |
| 163 data 8 | |
| 164 test | |
| 165 ing | |
| 166 M 644 :4 index.txt | |
| 167 """) | |
| 168 | |
| 169 def test_file_with_changes(self): | |
| 170 # Additional things to note: | |
| 171 # * from updated to reference parents in the output | |
| 172 params = {b'include_paths': [b'doc/README.txt']} | |
| 173 self.assertFiltering(_SAMPLE_WITH_DIR, params, \ | |
| 174 b"""blob | |
| 175 mark :1 | |
| 176 data 9 | |
| 177 Welcome! | |
| 178 commit refs/heads/master | |
| 179 mark :100 | |
| 180 committer a <b@c> 1234798653 +0000 | |
| 181 data 4 | |
| 182 test | |
| 183 M 644 :1 README.txt | |
| 184 blob | |
| 185 mark :3 | |
| 186 data 19 | |
| 187 Welcome! | |
| 188 my friend | |
| 189 commit refs/heads/master | |
| 190 mark :102 | |
| 191 committer d <b@c> 1234798653 +0000 | |
| 192 data 8 | |
| 193 test | |
| 194 ing | |
| 195 from :100 | |
| 196 M 644 :3 README.txt | |
| 197 """) | |
| 198 | |
| 199 def test_subdir(self): | |
| 200 params = {b'include_paths': [b'doc/']} | |
| 201 self.assertFiltering(_SAMPLE_WITH_DIR, params, \ | |
| 202 b"""blob | |
| 203 mark :1 | |
| 204 data 9 | |
| 205 Welcome! | |
| 206 commit refs/heads/master | |
| 207 mark :100 | |
| 208 committer a <b@c> 1234798653 +0000 | |
| 209 data 4 | |
| 210 test | |
| 211 M 644 :1 README.txt | |
| 212 blob | |
| 213 mark :3 | |
| 214 data 19 | |
| 215 Welcome! | |
| 216 my friend | |
| 217 blob | |
| 218 mark :4 | |
| 219 data 11 | |
| 220 == Docs == | |
| 221 commit refs/heads/master | |
| 222 mark :102 | |
| 223 committer d <b@c> 1234798653 +0000 | |
| 224 data 8 | |
| 225 test | |
| 226 ing | |
| 227 from :100 | |
| 228 M 644 :3 README.txt | |
| 229 M 644 :4 index.txt | |
| 230 """) | |
| 231 | |
| 232 def test_multiple_files_in_subdir(self): | |
| 233 # The new root should be the subdrectory | |
| 234 params = {b'include_paths': [b'doc/README.txt', b'doc/index.txt']} | |
| 235 self.assertFiltering(_SAMPLE_WITH_DIR, params, \ | |
| 236 b"""blob | |
| 237 mark :1 | |
| 238 data 9 | |
| 239 Welcome! | |
| 240 commit refs/heads/master | |
| 241 mark :100 | |
| 242 committer a <b@c> 1234798653 +0000 | |
| 243 data 4 | |
| 244 test | |
| 245 M 644 :1 README.txt | |
| 246 blob | |
| 247 mark :3 | |
| 248 data 19 | |
| 249 Welcome! | |
| 250 my friend | |
| 251 blob | |
| 252 mark :4 | |
| 253 data 11 | |
| 254 == Docs == | |
| 255 commit refs/heads/master | |
| 256 mark :102 | |
| 257 committer d <b@c> 1234798653 +0000 | |
| 258 data 8 | |
| 259 test | |
| 260 ing | |
| 261 from :100 | |
| 262 M 644 :3 README.txt | |
| 263 M 644 :4 index.txt | |
| 264 """) | |
| 265 | |
| 266 | |
| 267 class TestExcludePaths(TestCaseWithFiltering): | |
| 268 | |
| 269 def test_file_in_root(self): | |
| 270 params = {b'exclude_paths': [b'NEWS']} | |
| 271 self.assertFiltering(_SAMPLE_WITH_DIR, params, \ | |
| 272 b"""blob | |
| 273 mark :1 | |
| 274 data 9 | |
| 275 Welcome! | |
| 276 commit refs/heads/master | |
| 277 mark :100 | |
| 278 committer a <b@c> 1234798653 +0000 | |
| 279 data 4 | |
| 280 test | |
| 281 M 644 :1 doc/README.txt | |
| 282 blob | |
| 283 mark :3 | |
| 284 data 19 | |
| 285 Welcome! | |
| 286 my friend | |
| 287 blob | |
| 288 mark :4 | |
| 289 data 11 | |
| 290 == Docs == | |
| 291 commit refs/heads/master | |
| 292 mark :102 | |
| 293 committer d <b@c> 1234798653 +0000 | |
| 294 data 8 | |
| 295 test | |
| 296 ing | |
| 297 from :100 | |
| 298 M 644 :3 doc/README.txt | |
| 299 M 644 :4 doc/index.txt | |
| 300 """) | |
| 301 | |
| 302 def test_file_in_subdir(self): | |
| 303 params = {b'exclude_paths': [b'doc/README.txt']} | |
| 304 self.assertFiltering(_SAMPLE_WITH_DIR, params, \ | |
| 305 b"""blob | |
| 306 mark :2 | |
| 307 data 17 | |
| 308 Life | |
| 309 is | |
| 310 good ... | |
| 311 commit refs/heads/master | |
| 312 mark :101 | |
| 313 committer a <b@c> 1234798653 +0000 | |
| 314 data 8 | |
| 315 test | |
| 316 ing | |
| 317 M 644 :2 NEWS | |
| 318 blob | |
| 319 mark :4 | |
| 320 data 11 | |
| 321 == Docs == | |
| 322 commit refs/heads/master | |
| 323 mark :102 | |
| 324 committer d <b@c> 1234798653 +0000 | |
| 325 data 8 | |
| 326 test | |
| 327 ing | |
| 328 from :101 | |
| 329 M 644 :4 doc/index.txt | |
| 330 """) | |
| 331 | |
| 332 def test_subdir(self): | |
| 333 params = {b'exclude_paths': [b'doc/']} | |
| 334 self.assertFiltering(_SAMPLE_WITH_DIR, params, \ | |
| 335 b"""blob | |
| 336 mark :2 | |
| 337 data 17 | |
| 338 Life | |
| 339 is | |
| 340 good ... | |
| 341 commit refs/heads/master | |
| 342 mark :101 | |
| 343 committer a <b@c> 1234798653 +0000 | |
| 344 data 8 | |
| 345 test | |
| 346 ing | |
| 347 M 644 :2 NEWS | |
| 348 """) | |
| 349 | |
| 350 def test_multple_files(self): | |
| 351 params = {b'exclude_paths': [b'doc/index.txt', b'NEWS']} | |
| 352 self.assertFiltering(_SAMPLE_WITH_DIR, params, \ | |
| 353 b"""blob | |
| 354 mark :1 | |
| 355 data 9 | |
| 356 Welcome! | |
| 357 commit refs/heads/master | |
| 358 mark :100 | |
| 359 committer a <b@c> 1234798653 +0000 | |
| 360 data 4 | |
| 361 test | |
| 362 M 644 :1 doc/README.txt | |
| 363 blob | |
| 364 mark :3 | |
| 365 data 19 | |
| 366 Welcome! | |
| 367 my friend | |
| 368 commit refs/heads/master | |
| 369 mark :102 | |
| 370 committer d <b@c> 1234798653 +0000 | |
| 371 data 8 | |
| 372 test | |
| 373 ing | |
| 374 from :100 | |
| 375 M 644 :3 doc/README.txt | |
| 376 """) | |
| 377 | |
| 378 | |
| 379 class TestIncludeAndExcludePaths(TestCaseWithFiltering): | |
| 380 | |
| 381 def test_included_dir_and_excluded_file(self): | |
| 382 params = {b'include_paths': [b'doc/'], b'exclude_paths': [b'doc/index.txt']} | |
| 383 self.assertFiltering(_SAMPLE_WITH_DIR, params, \ | |
| 384 b"""blob | |
| 385 mark :1 | |
| 386 data 9 | |
| 387 Welcome! | |
| 388 commit refs/heads/master | |
| 389 mark :100 | |
| 390 committer a <b@c> 1234798653 +0000 | |
| 391 data 4 | |
| 392 test | |
| 393 M 644 :1 README.txt | |
| 394 blob | |
| 395 mark :3 | |
| 396 data 19 | |
| 397 Welcome! | |
| 398 my friend | |
| 399 commit refs/heads/master | |
| 400 mark :102 | |
| 401 committer d <b@c> 1234798653 +0000 | |
| 402 data 8 | |
| 403 test | |
| 404 ing | |
| 405 from :100 | |
| 406 M 644 :3 README.txt | |
| 407 """) | |
| 408 | |
| 409 | |
| 410 # A sample input stream creating the following tree: | |
| 411 # | |
| 412 # NEWS | |
| 413 # doc/README.txt | |
| 414 # doc/index.txt | |
| 415 # | |
| 416 # It then renames doc/README.txt => doc/README | |
| 417 _SAMPLE_WITH_RENAME_INSIDE = _SAMPLE_WITH_DIR + \ | |
| 418 b"""commit refs/heads/master | |
| 419 mark :103 | |
| 420 committer d <b@c> 1234798653 +0000 | |
| 421 data 10 | |
| 422 move intro | |
| 423 from :102 | |
| 424 R doc/README.txt doc/README | |
| 425 """ | |
| 426 | |
| 427 # A sample input stream creating the following tree: | |
| 428 # | |
| 429 # NEWS | |
| 430 # doc/README.txt | |
| 431 # doc/index.txt | |
| 432 # | |
| 433 # It then renames doc/README.txt => README | |
| 434 _SAMPLE_WITH_RENAME_TO_OUTSIDE = _SAMPLE_WITH_DIR + \ | |
| 435 b"""commit refs/heads/master | |
| 436 mark :103 | |
| 437 committer d <b@c> 1234798653 +0000 | |
| 438 data 10 | |
| 439 move intro | |
| 440 from :102 | |
| 441 R doc/README.txt README | |
| 442 """ | |
| 443 | |
| 444 # A sample input stream creating the following tree: | |
| 445 # | |
| 446 # NEWS | |
| 447 # doc/README.txt | |
| 448 # doc/index.txt | |
| 449 # | |
| 450 # It then renames NEWS => doc/NEWS | |
| 451 _SAMPLE_WITH_RENAME_TO_INSIDE = _SAMPLE_WITH_DIR + \ | |
| 452 b"""commit refs/heads/master | |
| 453 mark :103 | |
| 454 committer d <b@c> 1234798653 +0000 | |
| 455 data 10 | |
| 456 move intro | |
| 457 from :102 | |
| 458 R NEWS doc/NEWS | |
| 459 """ | |
| 460 | |
| 461 class TestIncludePathsWithRenames(TestCaseWithFiltering): | |
| 462 | |
| 463 def test_rename_all_inside(self): | |
| 464 # These rename commands ought to be kept but adjusted for the new root | |
| 465 params = {b'include_paths': [b'doc/']} | |
| 466 self.assertFiltering(_SAMPLE_WITH_RENAME_INSIDE, params, \ | |
| 467 b"""blob | |
| 468 mark :1 | |
| 469 data 9 | |
| 470 Welcome! | |
| 471 commit refs/heads/master | |
| 472 mark :100 | |
| 473 committer a <b@c> 1234798653 +0000 | |
| 474 data 4 | |
| 475 test | |
| 476 M 644 :1 README.txt | |
| 477 blob | |
| 478 mark :3 | |
| 479 data 19 | |
| 480 Welcome! | |
| 481 my friend | |
| 482 blob | |
| 483 mark :4 | |
| 484 data 11 | |
| 485 == Docs == | |
| 486 commit refs/heads/master | |
| 487 mark :102 | |
| 488 committer d <b@c> 1234798653 +0000 | |
| 489 data 8 | |
| 490 test | |
| 491 ing | |
| 492 from :100 | |
| 493 M 644 :3 README.txt | |
| 494 M 644 :4 index.txt | |
| 495 commit refs/heads/master | |
| 496 mark :103 | |
| 497 committer d <b@c> 1234798653 +0000 | |
| 498 data 10 | |
| 499 move intro | |
| 500 from :102 | |
| 501 R README.txt README | |
| 502 """) | |
| 503 | |
| 504 def test_rename_to_outside(self): | |
| 505 # These rename commands become deletes | |
| 506 params = {b'include_paths': [b'doc/']} | |
| 507 self.assertFiltering(_SAMPLE_WITH_RENAME_TO_OUTSIDE, params, \ | |
| 508 b"""blob | |
| 509 mark :1 | |
| 510 data 9 | |
| 511 Welcome! | |
| 512 commit refs/heads/master | |
| 513 mark :100 | |
| 514 committer a <b@c> 1234798653 +0000 | |
| 515 data 4 | |
| 516 test | |
| 517 M 644 :1 README.txt | |
| 518 blob | |
| 519 mark :3 | |
| 520 data 19 | |
| 521 Welcome! | |
| 522 my friend | |
| 523 blob | |
| 524 mark :4 | |
| 525 data 11 | |
| 526 == Docs == | |
| 527 commit refs/heads/master | |
| 528 mark :102 | |
| 529 committer d <b@c> 1234798653 +0000 | |
| 530 data 8 | |
| 531 test | |
| 532 ing | |
| 533 from :100 | |
| 534 M 644 :3 README.txt | |
| 535 M 644 :4 index.txt | |
| 536 commit refs/heads/master | |
| 537 mark :103 | |
| 538 committer d <b@c> 1234798653 +0000 | |
| 539 data 10 | |
| 540 move intro | |
| 541 from :102 | |
| 542 D README.txt | |
| 543 """) | |
| 544 | |
| 545 def test_rename_to_inside(self): | |
| 546 # This ought to create a new file but doesn't yet | |
| 547 params = {b'include_paths': [b'doc/']} | |
| 548 self.assertFiltering(_SAMPLE_WITH_RENAME_TO_INSIDE, params, \ | |
| 549 b"""blob | |
| 550 mark :1 | |
| 551 data 9 | |
| 552 Welcome! | |
| 553 commit refs/heads/master | |
| 554 mark :100 | |
| 555 committer a <b@c> 1234798653 +0000 | |
| 556 data 4 | |
| 557 test | |
| 558 M 644 :1 README.txt | |
| 559 blob | |
| 560 mark :3 | |
| 561 data 19 | |
| 562 Welcome! | |
| 563 my friend | |
| 564 blob | |
| 565 mark :4 | |
| 566 data 11 | |
| 567 == Docs == | |
| 568 commit refs/heads/master | |
| 569 mark :102 | |
| 570 committer d <b@c> 1234798653 +0000 | |
| 571 data 8 | |
| 572 test | |
| 573 ing | |
| 574 from :100 | |
| 575 M 644 :3 README.txt | |
| 576 M 644 :4 index.txt | |
| 577 """) | |
| 578 | |
| 579 | |
| 580 # A sample input stream creating the following tree: | |
| 581 # | |
| 582 # NEWS | |
| 583 # doc/README.txt | |
| 584 # doc/index.txt | |
| 585 # | |
| 586 # It then copies doc/README.txt => doc/README | |
| 587 _SAMPLE_WITH_COPY_INSIDE = _SAMPLE_WITH_DIR + \ | |
| 588 b"""commit refs/heads/master | |
| 589 mark :103 | |
| 590 committer d <b@c> 1234798653 +0000 | |
| 591 data 10 | |
| 592 move intro | |
| 593 from :102 | |
| 594 C doc/README.txt doc/README | |
| 595 """ | |
| 596 | |
| 597 # A sample input stream creating the following tree: | |
| 598 # | |
| 599 # NEWS | |
| 600 # doc/README.txt | |
| 601 # doc/index.txt | |
| 602 # | |
| 603 # It then copies doc/README.txt => README | |
| 604 _SAMPLE_WITH_COPY_TO_OUTSIDE = _SAMPLE_WITH_DIR + \ | |
| 605 b"""commit refs/heads/master | |
| 606 mark :103 | |
| 607 committer d <b@c> 1234798653 +0000 | |
| 608 data 10 | |
| 609 move intro | |
| 610 from :102 | |
| 611 C doc/README.txt README | |
| 612 """ | |
| 613 | |
| 614 # A sample input stream creating the following tree: | |
| 615 # | |
| 616 # NEWS | |
| 617 # doc/README.txt | |
| 618 # doc/index.txt | |
| 619 # | |
| 620 # It then copies NEWS => doc/NEWS | |
| 621 _SAMPLE_WITH_COPY_TO_INSIDE = _SAMPLE_WITH_DIR + \ | |
| 622 b"""commit refs/heads/master | |
| 623 mark :103 | |
| 624 committer d <b@c> 1234798653 +0000 | |
| 625 data 10 | |
| 626 move intro | |
| 627 from :102 | |
| 628 C NEWS doc/NEWS | |
| 629 """ | |
| 630 | |
| 631 | |
| 632 class TestIncludePathsWithCopies(TestCaseWithFiltering): | |
| 633 | |
| 634 def test_copy_all_inside(self): | |
| 635 # These copy commands ought to be kept but adjusted for the new root | |
| 636 params = {b'include_paths': [b'doc/']} | |
| 637 self.assertFiltering(_SAMPLE_WITH_COPY_INSIDE, params, \ | |
| 638 b"""blob | |
| 639 mark :1 | |
| 640 data 9 | |
| 641 Welcome! | |
| 642 commit refs/heads/master | |
| 643 mark :100 | |
| 644 committer a <b@c> 1234798653 +0000 | |
| 645 data 4 | |
| 646 test | |
| 647 M 644 :1 README.txt | |
| 648 blob | |
| 649 mark :3 | |
| 650 data 19 | |
| 651 Welcome! | |
| 652 my friend | |
| 653 blob | |
| 654 mark :4 | |
| 655 data 11 | |
| 656 == Docs == | |
| 657 commit refs/heads/master | |
| 658 mark :102 | |
| 659 committer d <b@c> 1234798653 +0000 | |
| 660 data 8 | |
| 661 test | |
| 662 ing | |
| 663 from :100 | |
| 664 M 644 :3 README.txt | |
| 665 M 644 :4 index.txt | |
| 666 commit refs/heads/master | |
| 667 mark :103 | |
| 668 committer d <b@c> 1234798653 +0000 | |
| 669 data 10 | |
| 670 move intro | |
| 671 from :102 | |
| 672 C README.txt README | |
| 673 """) | |
| 674 | |
| 675 def test_copy_to_outside(self): | |
| 676 # This can be ignored | |
| 677 params = {b'include_paths': [b'doc/']} | |
| 678 self.assertFiltering(_SAMPLE_WITH_COPY_TO_OUTSIDE, params, \ | |
| 679 b"""blob | |
| 680 mark :1 | |
| 681 data 9 | |
| 682 Welcome! | |
| 683 commit refs/heads/master | |
| 684 mark :100 | |
| 685 committer a <b@c> 1234798653 +0000 | |
| 686 data 4 | |
| 687 test | |
| 688 M 644 :1 README.txt | |
| 689 blob | |
| 690 mark :3 | |
| 691 data 19 | |
| 692 Welcome! | |
| 693 my friend | |
| 694 blob | |
| 695 mark :4 | |
| 696 data 11 | |
| 697 == Docs == | |
| 698 commit refs/heads/master | |
| 699 mark :102 | |
| 700 committer d <b@c> 1234798653 +0000 | |
| 701 data 8 | |
| 702 test | |
| 703 ing | |
| 704 from :100 | |
| 705 M 644 :3 README.txt | |
| 706 M 644 :4 index.txt | |
| 707 """) | |
| 708 | |
| 709 def test_copy_to_inside(self): | |
| 710 # This ought to create a new file but doesn't yet | |
| 711 params = {b'include_paths': [b'doc/']} | |
| 712 self.assertFiltering(_SAMPLE_WITH_COPY_TO_INSIDE, params, \ | |
| 713 b"""blob | |
| 714 mark :1 | |
| 715 data 9 | |
| 716 Welcome! | |
| 717 commit refs/heads/master | |
| 718 mark :100 | |
| 719 committer a <b@c> 1234798653 +0000 | |
| 720 data 4 | |
| 721 test | |
| 722 M 644 :1 README.txt | |
| 723 blob | |
| 724 mark :3 | |
| 725 data 19 | |
| 726 Welcome! | |
| 727 my friend | |
| 728 blob | |
| 729 mark :4 | |
| 730 data 11 | |
| 731 == Docs == | |
| 732 commit refs/heads/master | |
| 733 mark :102 | |
| 734 committer d <b@c> 1234798653 +0000 | |
| 735 data 8 | |
| 736 test | |
| 737 ing | |
| 738 from :100 | |
| 739 M 644 :3 README.txt | |
| 740 M 644 :4 index.txt | |
| 741 """) | |
| 742 | |
| 743 | |
| 744 # A sample input stream with deleteall's creating the following tree: | |
| 745 # | |
| 746 # NEWS | |
| 747 # doc/README.txt | |
| 748 # doc/index.txt | |
| 749 _SAMPLE_WITH_DELETEALL = \ | |
| 750 b"""blob | |
| 751 mark :1 | |
| 752 data 9 | |
| 753 Welcome! | |
| 754 commit refs/heads/master | |
| 755 mark :100 | |
| 756 committer a <b@c> 1234798653 +0000 | |
| 757 data 4 | |
| 758 test | |
| 759 deleteall | |
| 760 M 644 :1 doc/README.txt | |
| 761 blob | |
| 762 mark :3 | |
| 763 data 19 | |
| 764 Welcome! | |
| 765 my friend | |
| 766 blob | |
| 767 mark :4 | |
| 768 data 11 | |
| 769 == Docs == | |
| 770 commit refs/heads/master | |
| 771 mark :102 | |
| 772 committer d <b@c> 1234798653 +0000 | |
| 773 data 8 | |
| 774 test | |
| 775 ing | |
| 776 from :100 | |
| 777 deleteall | |
| 778 M 644 :3 doc/README.txt | |
| 779 M 644 :4 doc/index.txt | |
| 780 """ | |
| 781 | |
| 782 | |
| 783 class TestIncludePathsWithDeleteAll(TestCaseWithFiltering): | |
| 784 | |
| 785 def test_deleteall(self): | |
| 786 params = {b'include_paths': [b'doc/index.txt']} | |
| 787 self.assertFiltering(_SAMPLE_WITH_DELETEALL, params, \ | |
| 788 b"""blob | |
| 789 mark :4 | |
| 790 data 11 | |
| 791 == Docs == | |
| 792 commit refs/heads/master | |
| 793 mark :102 | |
| 794 committer d <b@c> 1234798653 +0000 | |
| 795 data 8 | |
| 796 test | |
| 797 ing | |
| 798 from :100 | |
| 799 deleteall | |
| 800 M 644 :4 index.txt | |
| 801 """) | |
| 802 | |
| 803 | |
| 804 _SAMPLE_WITH_TAGS = _SAMPLE_WITH_DIR + \ | |
| 805 b"""tag v0.1 | |
| 806 from :100 | |
| 807 tagger d <b@c> 1234798653 +0000 | |
| 808 data 12 | |
| 809 release v0.1 | |
| 810 tag v0.2 | |
| 811 from :102 | |
| 812 tagger d <b@c> 1234798653 +0000 | |
| 813 data 12 | |
| 814 release v0.2 | |
| 815 """ | |
| 816 | |
| 817 class TestIncludePathsWithTags(TestCaseWithFiltering): | |
| 818 | |
| 819 def test_tag_retention(self): | |
| 820 # If a tag references a commit with a parent we kept, | |
| 821 # keep the tag but adjust 'from' accordingly. | |
| 822 # Otherwise, delete the tag command. | |
| 823 params = {b'include_paths': [b'NEWS']} | |
| 824 self.assertFiltering(_SAMPLE_WITH_TAGS, params, \ | |
| 825 b"""blob | |
| 826 mark :2 | |
| 827 data 17 | |
| 828 Life | |
| 829 is | |
| 830 good ... | |
| 831 commit refs/heads/master | |
| 832 mark :101 | |
| 833 committer a <b@c> 1234798653 +0000 | |
| 834 data 8 | |
| 835 test | |
| 836 ing | |
| 837 M 644 :2 NEWS | |
| 838 tag v0.2 | |
| 839 from :101 | |
| 840 tagger d <b@c> 1234798653 +0000 | |
| 841 data 12 | |
| 842 release v0.2 | |
| 843 """) | |
| 844 | |
| 845 | |
| 846 _SAMPLE_WITH_RESETS = _SAMPLE_WITH_DIR + \ | |
| 847 b"""reset refs/heads/foo | |
| 848 reset refs/heads/bar | |
| 849 from :102 | |
| 850 """ | |
| 851 | |
| 852 class TestIncludePathsWithResets(TestCaseWithFiltering): | |
| 853 | |
| 854 def test_reset_retention(self): | |
| 855 # Resets init'ing a branch (without a from) are passed through. | |
| 856 # If a reset references a commit with a parent we kept, | |
| 857 # keep the reset but adjust 'from' accordingly. | |
| 858 params = {b'include_paths': [b'NEWS']} | |
| 859 self.assertFiltering(_SAMPLE_WITH_RESETS, params, \ | |
| 860 b"""blob | |
| 861 mark :2 | |
| 862 data 17 | |
| 863 Life | |
| 864 is | |
| 865 good ... | |
| 866 commit refs/heads/master | |
| 867 mark :101 | |
| 868 committer a <b@c> 1234798653 +0000 | |
| 869 data 8 | |
| 870 test | |
| 871 ing | |
| 872 M 644 :2 NEWS | |
| 873 reset refs/heads/foo | |
| 874 reset refs/heads/bar | |
| 875 from :101 | |
| 876 """) | |
| 877 | |
| 878 | |
| 879 # A sample input stream containing empty commit | |
| 880 _SAMPLE_EMPTY_COMMIT = \ | |
| 881 b"""blob | |
| 882 mark :1 | |
| 883 data 4 | |
| 884 foo | |
| 885 commit refs/heads/master | |
| 886 mark :2 | |
| 887 committer Joe <joe@example.com> 1234567890 +1000 | |
| 888 data 14 | |
| 889 Initial import | |
| 890 M 644 :1 COPYING | |
| 891 commit refs/heads/master | |
| 892 mark :3 | |
| 893 committer Joe <joe@example.com> 1234567890 +1000 | |
| 894 data 12 | |
| 895 empty commit | |
| 896 """ | |
| 897 | |
| 898 # A sample input stream containing unresolved from and merge references | |
| 899 _SAMPLE_FROM_MERGE_COMMIT = \ | |
| 900 b"""blob | |
| 901 mark :1 | |
| 902 data 4 | |
| 903 foo | |
| 904 commit refs/heads/master | |
| 905 mark :3 | |
| 906 committer Joe <joe@example.com> 1234567890 +1000 | |
| 907 data 6 | |
| 908 import | |
| 909 M 644 :1 COPYING | |
| 910 blob | |
| 911 mark :2 | |
| 912 data 4 | |
| 913 bar | |
| 914 commit refs/heads/master | |
| 915 mark :4 | |
| 916 committer Joe <joe@example.com> 1234567890 +1000 | |
| 917 data 19 | |
| 918 unknown from commit | |
| 919 from :999 | |
| 920 M 644 :2 data/DATA | |
| 921 blob | |
| 922 mark :99 | |
| 923 data 4 | |
| 924 bar | |
| 925 commit refs/heads/master | |
| 926 mark :5 | |
| 927 committer Joe <joe@example.com> 1234567890 +1000 | |
| 928 data 12 | |
| 929 merge commit | |
| 930 from :3 | |
| 931 merge :4 | |
| 932 merge :1001 | |
| 933 M 644 :99 data/DATA2 | |
| 934 """ | |
| 935 | |
| 936 class TestSquashEmptyCommitsFlag(TestCaseWithFiltering): | |
| 937 | |
| 938 def test_squash_empty_commit(self): | |
| 939 params = {b'include_paths': None, b'exclude_paths': None} | |
| 940 self.assertFiltering(_SAMPLE_EMPTY_COMMIT, params, \ | |
| 941 b"""blob | |
| 942 mark :1 | |
| 943 data 4 | |
| 944 foo | |
| 945 commit refs/heads/master | |
| 946 mark :2 | |
| 947 committer Joe <joe@example.com> 1234567890 +1000 | |
| 948 data 14 | |
| 949 Initial import | |
| 950 M 644 :1 COPYING | |
| 951 """) | |
| 952 | |
| 953 def test_keep_empty_commit(self): | |
| 954 params = {b'include_paths': None, b'exclude_paths': None, b'squash_empty_commits': False} | |
| 955 self.assertFiltering(_SAMPLE_EMPTY_COMMIT, params, _SAMPLE_EMPTY_COMMIT) | |
| 956 | |
| 957 def test_squash_unresolved_references(self): | |
| 958 params = {b'include_paths': None, b'exclude_paths': None} | |
| 959 self.assertFiltering(_SAMPLE_FROM_MERGE_COMMIT, params, \ | |
| 960 b"""blob | |
| 961 mark :1 | |
| 962 data 4 | |
| 963 foo | |
| 964 commit refs/heads/master | |
| 965 mark :3 | |
| 966 committer Joe <joe@example.com> 1234567890 +1000 | |
| 967 data 6 | |
| 968 import | |
| 969 M 644 :1 COPYING | |
| 970 blob | |
| 971 mark :2 | |
| 972 data 4 | |
| 973 bar | |
| 974 commit refs/heads/master | |
| 975 mark :4 | |
| 976 committer Joe <joe@example.com> 1234567890 +1000 | |
| 977 data 19 | |
| 978 unknown from commit | |
| 979 from :999 | |
| 980 M 644 :2 data/DATA | |
| 981 blob | |
| 982 mark :99 | |
| 983 data 4 | |
| 984 bar | |
| 985 commit refs/heads/master | |
| 986 mark :5 | |
| 987 committer Joe <joe@example.com> 1234567890 +1000 | |
| 988 data 12 | |
| 989 merge commit | |
| 990 from :3 | |
| 991 merge :4 | |
| 992 merge :1001 | |
| 993 M 644 :99 data/DATA2 | |
| 994 """) | |
| 995 | |
| 996 def test_keep_unresolved_from_and_merge(self): | |
| 997 params = {b'include_paths': None, b'exclude_paths': None, b'squash_empty_commits': False} | |
| 998 self.assertFiltering(_SAMPLE_FROM_MERGE_COMMIT, params, _SAMPLE_FROM_MERGE_COMMIT) | |
| 999 | |
| 1000 def test_with_excludes(self): | |
| 1001 params = {b'include_paths': None, | |
| 1002 b'exclude_paths': [b'data/DATA'], | |
| 1003 b'squash_empty_commits': False} | |
| 1004 self.assertFiltering(_SAMPLE_FROM_MERGE_COMMIT, params, \ | |
| 1005 b"""blob | |
| 1006 mark :1 | |
| 1007 data 4 | |
| 1008 foo | |
| 1009 commit refs/heads/master | |
| 1010 mark :3 | |
| 1011 committer Joe <joe@example.com> 1234567890 +1000 | |
| 1012 data 6 | |
| 1013 import | |
| 1014 M 644 :1 COPYING | |
| 1015 commit refs/heads/master | |
| 1016 mark :4 | |
| 1017 committer Joe <joe@example.com> 1234567890 +1000 | |
| 1018 data 19 | |
| 1019 unknown from commit | |
| 1020 from :999 | |
| 1021 blob | |
| 1022 mark :99 | |
| 1023 data 4 | |
| 1024 bar | |
| 1025 commit refs/heads/master | |
| 1026 mark :5 | |
| 1027 committer Joe <joe@example.com> 1234567890 +1000 | |
| 1028 data 12 | |
| 1029 merge commit | |
| 1030 from :3 | |
| 1031 merge :4 | |
| 1032 merge :1001 | |
| 1033 M 644 :99 data/DATA2 | |
| 1034 """) | |
| 1035 | |
| 1036 def test_with_file_includes(self): | |
| 1037 params = {b'include_paths': [b'COPYING', b'data/DATA2'], | |
| 1038 b'exclude_paths': None, | |
| 1039 b'squash_empty_commits': False} | |
| 1040 self.assertFiltering(_SAMPLE_FROM_MERGE_COMMIT, params, \ | |
| 1041 b"""blob | |
| 1042 mark :1 | |
| 1043 data 4 | |
| 1044 foo | |
| 1045 commit refs/heads/master | |
| 1046 mark :3 | |
| 1047 committer Joe <joe@example.com> 1234567890 +1000 | |
| 1048 data 6 | |
| 1049 import | |
| 1050 M 644 :1 COPYING | |
| 1051 commit refs/heads/master | |
| 1052 mark :4 | |
| 1053 committer Joe <joe@example.com> 1234567890 +1000 | |
| 1054 data 19 | |
| 1055 unknown from commit | |
| 1056 from :999 | |
| 1057 blob | |
| 1058 mark :99 | |
| 1059 data 4 | |
| 1060 bar | |
| 1061 commit refs/heads/master | |
| 1062 mark :5 | |
| 1063 committer Joe <joe@example.com> 1234567890 +1000 | |
| 1064 data 12 | |
| 1065 merge commit | |
| 1066 from :3 | |
| 1067 merge :4 | |
| 1068 merge :1001 | |
| 1069 M 644 :99 data/DATA2 | |
| 1070 """ | |
| 1071 ) | |
| 1072 | |
| 1073 def test_with_directory_includes(self): | |
| 1074 params = {b'include_paths': [b'data/'], | |
| 1075 b'exclude_paths': None, | |
| 1076 b'squash_empty_commits': False} | |
| 1077 self.assertFiltering(_SAMPLE_FROM_MERGE_COMMIT, params, \ | |
| 1078 b"""commit refs/heads/master | |
| 1079 mark :3 | |
| 1080 committer Joe <joe@example.com> 1234567890 +1000 | |
| 1081 data 6 | |
| 1082 import | |
| 1083 blob | |
| 1084 mark :2 | |
| 1085 data 4 | |
| 1086 bar | |
| 1087 commit refs/heads/master | |
| 1088 mark :4 | |
| 1089 committer Joe <joe@example.com> 1234567890 +1000 | |
| 1090 data 19 | |
| 1091 unknown from commit | |
| 1092 from :999 | |
| 1093 M 644 :2 DATA | |
| 1094 blob | |
| 1095 mark :99 | |
| 1096 data 4 | |
| 1097 bar | |
| 1098 commit refs/heads/master | |
| 1099 mark :5 | |
| 1100 committer Joe <joe@example.com> 1234567890 +1000 | |
| 1101 data 12 | |
| 1102 merge commit | |
| 1103 from :3 | |
| 1104 merge :4 | |
| 1105 merge :1001 | |
| 1106 M 644 :99 DATA2 | |
| 1107 """) |
