| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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_cl.py.""" | 6 """Unit tests for git_cl.py.""" |
| 7 | 7 |
| 8 import os | 8 import os |
| 9 import StringIO | 9 import StringIO |
| 10 import stat | 10 import stat |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 'fake_ancestor_sha', 'HEAD'],), '+dat') | 160 'fake_ancestor_sha', 'HEAD'],), '+dat') |
| 161 else: | 161 else: |
| 162 stat_call = ((['git', 'diff', '--no-ext-diff', '--stat', | 162 stat_call = ((['git', 'diff', '--no-ext-diff', '--stat', |
| 163 '-M'+similarity, 'fake_ancestor_sha', 'HEAD'],), '+dat') | 163 '-M'+similarity, 'fake_ancestor_sha', 'HEAD'],), '+dat') |
| 164 | 164 |
| 165 return [ | 165 return [ |
| 166 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), | 166 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
| 167 similarity_call, | 167 similarity_call, |
| 168 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), | 168 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
| 169 find_copies_call, | 169 find_copies_call, |
| 170 ((['git', 'config', 'rietveld.autoupdate'],), ''), |
| 171 ((['git', 'config', 'rietveld.server'],), |
| 172 'codereview.example.com'), |
| 170 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), | 173 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
| 171 ((['git', 'config', 'branch.master.rietveldissue'],), ''), | 174 ((['git', 'config', 'branch.master.rietveldissue'],), ''), |
| 172 ((['git', 'config', 'branch.master.gerritissue'],), ''), | 175 ((['git', 'config', 'branch.master.gerritissue'],), ''), |
| 173 ((['git', 'config', 'rietveld.autoupdate'],), ''), | |
| 174 ((['git', 'config', 'gerrit.host'],), ''), | 176 ((['git', 'config', 'gerrit.host'],), ''), |
| 175 ((['git', 'config', 'rietveld.server'],), | |
| 176 'codereview.example.com'), | |
| 177 ((['git', 'config', 'branch.master.merge'],), 'master'), | 177 ((['git', 'config', 'branch.master.merge'],), 'master'), |
| 178 ((['git', 'config', 'branch.master.remote'],), 'origin'), | 178 ((['git', 'config', 'branch.master.remote'],), 'origin'), |
| 179 ((['get_or_create_merge_base', 'master', 'master'],), | 179 ((['get_or_create_merge_base', 'master', 'master'],), |
| 180 'fake_ancestor_sha'), | 180 'fake_ancestor_sha'), |
| 181 ] + cls._git_sanity_checks('fake_ancestor_sha', 'master') + [ | 181 ] + cls._git_sanity_checks('fake_ancestor_sha', 'master') + [ |
| 182 ((['git', 'rev-parse', '--show-cdup'],), ''), | 182 ((['git', 'rev-parse', '--show-cdup'],), ''), |
| 183 ((['git', 'rev-parse', 'HEAD'],), '12345'), | 183 ((['git', 'rev-parse', 'HEAD'],), '12345'), |
| 184 ((['git', 'diff', '--name-status', '--no-renames', '-r', | 184 ((['git', 'diff', '--name-status', '--no-renames', '-r', |
| 185 'fake_ancestor_sha...', '.'],), | 185 'fake_ancestor_sha...', '.'],), |
| 186 'M\t.gitignore\n'), | 186 'M\t.gitignore\n'), |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 ((('svn-remote.svn.url svn://svn.chromium.org/chrome\n' | 279 ((('svn-remote.svn.url svn://svn.chromium.org/chrome\n' |
| 280 'svn-remote.svn.fetch trunk/src:refs/remotes/origin/master'), | 280 'svn-remote.svn.fetch trunk/src:refs/remotes/origin/master'), |
| 281 None), | 281 None), |
| 282 0)), | 282 0)), |
| 283 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), | 283 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), |
| 284 ((['git', 'config', '--int', '--get', | 284 ((['git', 'config', '--int', '--get', |
| 285 'branch.working.git-cl-similarity'],), ''), | 285 'branch.working.git-cl-similarity'],), ''), |
| 286 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), | 286 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), |
| 287 ((['git', 'config', '--int', '--get', | 287 ((['git', 'config', '--int', '--get', |
| 288 'branch.working.git-find-copies'],), ''), | 288 'branch.working.git-find-copies'],), ''), |
| 289 ((['git', |
| 290 'config', 'rietveld.server'],), 'codereview.example.com'), |
| 289 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), | 291 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), |
| 290 ((['git', | 292 ((['git', |
| 291 'config', 'branch.working.rietveldissue'],), '12345'), | 293 'config', 'branch.working.rietveldissue'],), '12345'), |
| 292 ((['git', | 294 ((['git', |
| 293 'config', 'rietveld.server'],), 'codereview.example.com'), | |
| 294 ((['git', | |
| 295 'config', 'branch.working.merge'],), 'refs/heads/master'), | 295 'config', 'branch.working.merge'],), 'refs/heads/master'), |
| 296 ((['git', 'config', 'branch.working.remote'],), 'origin'), | 296 ((['git', 'config', 'branch.working.remote'],), 'origin'), |
| 297 ((['git', 'config', 'branch.working.merge'],), | 297 ((['git', 'config', 'branch.working.merge'],), |
| 298 'refs/heads/master'), | 298 'refs/heads/master'), |
| 299 ((['git', 'config', 'branch.working.remote'],), 'origin'), | 299 ((['git', 'config', 'branch.working.remote'],), 'origin'), |
| 300 ((['git', 'rev-list', '--merges', | 300 ((['git', 'rev-list', '--merges', |
| 301 '--grep=^SVN changes up to revision [0-9]*$', | 301 '--grep=^SVN changes up to revision [0-9]*$', |
| 302 'refs/remotes/origin/master^!'],), ''), | 302 'refs/remotes/origin/master^!'],), ''), |
| 303 ((['git', 'rev-list', '^refs/heads/working', | 303 ((['git', 'rev-list', '^refs/heads/working', |
| 304 'refs/remotes/origin/master'],), | 304 'refs/remotes/origin/master'],), |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 | 543 |
| 544 @classmethod | 544 @classmethod |
| 545 def _gerrit_base_calls(cls): | 545 def _gerrit_base_calls(cls): |
| 546 return [ | 546 return [ |
| 547 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), | 547 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
| 548 ((['git', 'config', '--int', '--get', | 548 ((['git', 'config', '--int', '--get', |
| 549 'branch.master.git-cl-similarity'],), ''), | 549 'branch.master.git-cl-similarity'],), ''), |
| 550 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), | 550 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
| 551 ((['git', 'config', '--int', '--get', | 551 ((['git', 'config', '--int', '--get', |
| 552 'branch.master.git-find-copies'],), ''), | 552 'branch.master.git-find-copies'],), ''), |
| 553 ((['git', 'config', 'rietveld.autoupdate'],), ''), |
| 554 ((['git', 'config', 'rietveld.server'],), ''), |
| 555 ((['git', 'config', 'rietveld.server'],), ''), |
| 553 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), | 556 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
| 554 ((['git', 'config', 'branch.master.rietveldissue'],), ''), | 557 ((['git', 'config', 'branch.master.rietveldissue'],), ''), |
| 555 ((['git', 'config', 'branch.master.gerritissue'],), ''), | 558 ((['git', 'config', 'branch.master.gerritissue'],), ''), |
| 556 ((['git', 'config', 'rietveld.autoupdate'],), ''), | |
| 557 ((['git', 'config', 'gerrit.host'],), 'True'), | 559 ((['git', 'config', 'gerrit.host'],), 'True'), |
| 558 ((['git', 'config', 'branch.master.merge'],), 'master'), | 560 ((['git', 'config', 'branch.master.merge'],), 'master'), |
| 559 ((['git', 'config', 'branch.master.remote'],), 'origin'), | 561 ((['git', 'config', 'branch.master.remote'],), 'origin'), |
| 560 ((['get_or_create_merge_base', 'master', 'master'],), | 562 ((['get_or_create_merge_base', 'master', 'master'],), |
| 561 'fake_ancestor_sha'), | 563 'fake_ancestor_sha'), |
| 562 ] + cls._git_sanity_checks('fake_ancestor_sha', 'master') + [ | 564 ] + cls._git_sanity_checks('fake_ancestor_sha', 'master') + [ |
| 563 ((['git', 'rev-parse', '--show-cdup'],), ''), | 565 ((['git', 'rev-parse', '--show-cdup'],), ''), |
| 564 ((['git', 'rev-parse', 'HEAD'],), '12345'), | 566 ((['git', 'rev-parse', 'HEAD'],), '12345'), |
| 565 ((['git', | 567 ((['git', |
| 566 'diff', '--name-status', '--no-renames', '-r', | 568 'diff', '--name-status', '--no-renames', '-r', |
| 567 'fake_ancestor_sha...', '.'],), | 569 'fake_ancestor_sha...', '.'],), |
| 568 'M\t.gitignore\n'), | 570 'M\t.gitignore\n'), |
| 569 ((['git', 'config', 'branch.master.gerritpatchset'],), ''), | 571 ((['git', 'config', 'branch.master.gerritpatchset'],), ''), |
| 570 ((['git', | 572 ((['git', |
| 571 'log', '--pretty=format:%s%n%n%b', 'fake_ancestor_sha...'],), | 573 'log', '--pretty=format:%s%n%n%b', 'fake_ancestor_sha...'],), |
| 572 'foo'), | 574 'foo'), |
| 573 ((['git', 'config', 'user.email'],), 'me@example.com'), | 575 ((['git', 'config', 'user.email'],), 'me@example.com'), |
| 574 ((['git', | 576 ((['git', |
| 575 'diff', '--no-ext-diff', '--stat', '--find-copies-harder', | 577 'diff', '--no-ext-diff', '--stat', '--find-copies-harder', |
| 576 '-l100000', '-C50', 'fake_ancestor_sha', 'HEAD'],), | 578 '-l100000', '-C50', 'fake_ancestor_sha', 'HEAD'],), |
| 577 '+dat'), | 579 '+dat'), |
| 578 ] | 580 ] |
| 579 | 581 |
| 580 @classmethod | 582 @classmethod |
| 581 def _gerrit_upload_calls(cls, description, reviewers, squash, | 583 def _gerrit_upload_calls(cls, description, reviewers, squash, |
| 582 expected_upstream_ref='origin/refs/heads/master', | 584 expected_upstream_ref='origin/refs/heads/master', |
| 583 post_amend_description=None): | 585 post_amend_description=None): |
| 584 if post_amend_description is None: | 586 if post_amend_description is None: |
| 585 post_amend_description = description | 587 post_amend_description = description |
| 586 calls = [ | 588 calls = [ |
| 587 ((['git', 'config', '--bool', 'gerrit.squash-uploads'],), 'false'), | 589 ((['git', 'config', '--bool', 'gerrit.squash-uploads'],), 'false'), |
| 588 ((['git', 'log', '--pretty=format:%s\n\n%b', | 590 ((['git', 'log', '--pretty=format:%s\n\n%b', |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 921 self.calls += [ | 923 self.calls += [ |
| 922 ((['git', 'apply', '--index', '-p0', '--3way'],), '', | 924 ((['git', 'apply', '--index', '-p0', '--3way'],), '', |
| 923 subprocess2.CalledProcessError(1, '', '', '', '')), | 925 subprocess2.CalledProcessError(1, '', '', '', '')), |
| 924 ] | 926 ] |
| 925 self.assertNotEqual(git_cl.main(['patch', '123456']), 0) | 927 self.assertNotEqual(git_cl.main(['patch', '123456']), 0) |
| 926 | 928 |
| 927 if __name__ == '__main__': | 929 if __name__ == '__main__': |
| 928 git_cl.logging.basicConfig( | 930 git_cl.logging.basicConfig( |
| 929 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) | 931 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) |
| 930 unittest.main() | 932 unittest.main() |
| OLD | NEW |