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', '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'), | |
291 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), | 289 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), |
292 ((['git', | 290 ((['git', |
293 'config', 'branch.working.rietveldissue'],), '12345'), | 291 'config', 'branch.working.rietveldissue'],), '12345'), |
294 ((['git', | 292 ((['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'],), ''), | |
556 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), | 553 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
557 ((['git', 'config', 'branch.master.rietveldissue'],), ''), | 554 ((['git', 'config', 'branch.master.rietveldissue'],), ''), |
558 ((['git', 'config', 'branch.master.gerritissue'],), ''), | 555 ((['git', 'config', 'branch.master.gerritissue'],), ''), |
| 556 ((['git', 'config', 'rietveld.autoupdate'],), ''), |
559 ((['git', 'config', 'gerrit.host'],), 'True'), | 557 ((['git', 'config', 'gerrit.host'],), 'True'), |
560 ((['git', 'config', 'branch.master.merge'],), 'master'), | 558 ((['git', 'config', 'branch.master.merge'],), 'master'), |
561 ((['git', 'config', 'branch.master.remote'],), 'origin'), | 559 ((['git', 'config', 'branch.master.remote'],), 'origin'), |
562 ((['get_or_create_merge_base', 'master', 'master'],), | 560 ((['get_or_create_merge_base', 'master', 'master'],), |
563 'fake_ancestor_sha'), | 561 'fake_ancestor_sha'), |
564 ] + cls._git_sanity_checks('fake_ancestor_sha', 'master') + [ | 562 ] + cls._git_sanity_checks('fake_ancestor_sha', 'master') + [ |
565 ((['git', 'rev-parse', '--show-cdup'],), ''), | 563 ((['git', 'rev-parse', '--show-cdup'],), ''), |
566 ((['git', 'rev-parse', 'HEAD'],), '12345'), | 564 ((['git', 'rev-parse', 'HEAD'],), '12345'), |
567 ((['git', | 565 ((['git', |
568 'diff', '--name-status', '--no-renames', '-r', | 566 'diff', '--name-status', '--no-renames', '-r', |
569 'fake_ancestor_sha...', '.'],), | 567 'fake_ancestor_sha...', '.'],), |
570 'M\t.gitignore\n'), | 568 'M\t.gitignore\n'), |
571 ((['git', 'config', 'branch.master.gerritpatchset'],), ''), | 569 ((['git', 'config', 'branch.master.gerritpatchset'],), ''), |
572 ((['git', | 570 ((['git', |
573 'log', '--pretty=format:%s%n%n%b', 'fake_ancestor_sha...'],), | 571 'log', '--pretty=format:%s%n%n%b', 'fake_ancestor_sha...'],), |
574 'foo'), | 572 'foo'), |
575 ((['git', 'config', 'user.email'],), 'me@example.com'), | 573 ((['git', 'config', 'user.email'],), 'me@example.com'), |
576 ((['git', | 574 ((['git', |
577 'diff', '--no-ext-diff', '--stat', '--find-copies-harder', | 575 'diff', '--no-ext-diff', '--stat', '--find-copies-harder', |
578 '-l100000', '-C50', 'fake_ancestor_sha', 'HEAD'],), | 576 '-l100000', '-C50', 'fake_ancestor_sha', 'HEAD'],), |
579 '+dat'), | 577 '+dat'), |
580 ] | 578 ] |
581 | 579 |
582 @classmethod | 580 @classmethod |
583 def _gerrit_upload_calls(cls, description, reviewers, squash, | 581 def _gerrit_upload_calls(cls, description, reviewers, squash, |
584 expected_upstream_ref='origin/refs/heads/master', | 582 expected_upstream_ref='origin/refs/heads/master', |
585 post_amend_description=None): | 583 post_amend_description=None): |
586 if post_amend_description is None: | 584 if post_amend_description is None: |
587 post_amend_description = description | 585 post_amend_description = description |
588 calls = [ | 586 calls = [ |
589 ((['git', 'config', '--bool', 'gerrit.squash-uploads'],), 'false'), | 587 ((['git', 'config', '--bool', 'gerrit.squash-uploads'],), 'false'), |
590 ((['git', 'log', '--pretty=format:%s\n\n%b', | 588 ((['git', 'log', '--pretty=format:%s\n\n%b', |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
923 self.calls += [ | 921 self.calls += [ |
924 ((['git', 'apply', '--index', '-p0', '--3way'],), '', | 922 ((['git', 'apply', '--index', '-p0', '--3way'],), '', |
925 subprocess2.CalledProcessError(1, '', '', '', '')), | 923 subprocess2.CalledProcessError(1, '', '', '', '')), |
926 ] | 924 ] |
927 self.assertNotEqual(git_cl.main(['patch', '123456']), 0) | 925 self.assertNotEqual(git_cl.main(['patch', '123456']), 0) |
928 | 926 |
929 if __name__ == '__main__': | 927 if __name__ == '__main__': |
930 git_cl.logging.basicConfig( | 928 git_cl.logging.basicConfig( |
931 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) | 929 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) |
932 unittest.main() | 930 unittest.main() |
OLD | NEW |