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