| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2013 The Chromium Authors. All rights reserved. | 2 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Unit tests for git_common.py""" | 6 """Unit tests for git_common.py""" |
| 7 | 7 |
| 8 import binascii | 8 import binascii |
| 9 import collections | 9 import collections |
| 10 import os | 10 import os |
| (...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 ]) | 554 ]) |
| 555 | 555 |
| 556 self.assertEqual(bottomup, [ | 556 self.assertEqual(bottomup, [ |
| 557 ('branch_L', 'branch_K'), | 557 ('branch_L', 'branch_K'), |
| 558 ('branch_Z', 'root_X'), | 558 ('branch_Z', 'root_X'), |
| 559 ('branch_K', 'branch_G'), | 559 ('branch_K', 'branch_G'), |
| 560 ('branch_G', 'root_A'), | 560 ('branch_G', 'root_A'), |
| 561 ('root_A', 'root_X'), | 561 ('root_A', 'root_X'), |
| 562 ]) | 562 ]) |
| 563 | 563 |
| 564 def testIsGitTreeDirty(self): |
| 565 self.assertEquals(False, self.repo.run(self.gc.is_dirty_git_tree, 'foo')) |
| 566 self.repo.open('test.file', 'w').write('test data') |
| 567 self.repo.git('add', 'test.file') |
| 568 self.assertEquals(True, self.repo.run(self.gc.is_dirty_git_tree, 'foo')) |
| 569 |
| 564 def testSquashBranch(self): | 570 def testSquashBranch(self): |
| 565 self.repo.git('checkout', 'branch_K') | 571 self.repo.git('checkout', 'branch_K') |
| 566 | 572 |
| 567 self.repo.run(self.gc.squash_current_branch, 'cool message') | 573 self.assertEquals(True, self.repo.run(self.gc.squash_current_branch, |
| 574 'cool message')) |
| 568 | 575 |
| 569 lines = ['cool message', ''] | 576 lines = ['cool message', ''] |
| 570 for l in 'HIJK': | 577 for l in 'HIJK': |
| 571 lines.extend((self.repo[l], l, '')) | 578 lines.extend((self.repo[l], l, '')) |
| 572 lines.pop() | 579 lines.pop() |
| 573 msg = '\n'.join(lines) | 580 msg = '\n'.join(lines) |
| 574 | 581 |
| 575 self.assertEquals(self.repo.run(self.gc.run, 'log', '-n1', '--format=%B'), | 582 self.assertEquals(self.repo.run(self.gc.run, 'log', '-n1', '--format=%B'), |
| 576 msg) | 583 msg) |
| 577 | 584 |
| 578 self.assertEquals( | 585 self.assertEquals( |
| 579 self.repo.git('cat-file', 'blob', 'branch_K:file').stdout, | 586 self.repo.git('cat-file', 'blob', 'branch_K:file').stdout, |
| 580 'K' | 587 'K' |
| 581 ) | 588 ) |
| 582 | 589 |
| 590 def testSquashBranchEmpty(self): |
| 591 self.repo.git('checkout', 'branch_K') |
| 592 self.repo.git('checkout', 'branch_G', '.') |
| 593 self.repo.git('commit', '-m', 'revert all changes no branch') |
| 594 # Should return False since the quash would result in an empty commit |
| 595 stdout = self.repo.capture_stdio(self.gc.squash_current_branch)[0] |
| 596 self.assertEquals(stdout, 'Nothing to commit; squashed branch is empty\n') |
| 597 |
| 583 def testRebase(self): | 598 def testRebase(self): |
| 584 self.assertSchema(""" | 599 self.assertSchema(""" |
| 585 A B C D E F G | 600 A B C D E F G |
| 586 B H I J K | 601 B H I J K |
| 587 J L | 602 J L |
| 588 | 603 |
| 589 X Y Z | 604 X Y Z |
| 590 | 605 |
| 591 CAT DOG | 606 CAT DOG |
| 592 """) | 607 """) |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 | 720 |
| 706 self.assertEquals(self.repo.git('status', '--porcelain').stdout, STATUS_1) | 721 self.assertEquals(self.repo.git('status', '--porcelain').stdout, STATUS_1) |
| 707 | 722 |
| 708 self.repo.run(inner) | 723 self.repo.run(inner) |
| 709 | 724 |
| 710 | 725 |
| 711 if __name__ == '__main__': | 726 if __name__ == '__main__': |
| 712 sys.exit(coverage_utils.covered_main( | 727 sys.exit(coverage_utils.covered_main( |
| 713 os.path.join(DEPOT_TOOLS_ROOT, 'git_common.py') | 728 os.path.join(DEPOT_TOOLS_ROOT, 'git_common.py') |
| 714 )) | 729 )) |
| OLD | NEW |