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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 private_call = [ | 197 private_call = [ |
198 ((['git', 'config', 'rietveld.private'],), '')] | 198 ((['git', 'config', 'rietveld.private'],), '')] |
199 | 199 |
200 return [ | 200 return [ |
201 ((['git', 'config', 'core.editor'],), ''), | 201 ((['git', 'config', 'core.editor'],), ''), |
202 ] + cc_call + private_call + [ | 202 ] + cc_call + private_call + [ |
203 ((['git', 'config', 'branch.master.base-url'],), ''), | 203 ((['git', 'config', 'branch.master.base-url'],), ''), |
204 ((['git', | 204 ((['git', |
205 'config', '--local', '--get-regexp', '^svn-remote\\.'],), | 205 'config', '--local', '--get-regexp', '^svn-remote\\.'],), |
206 (('', None), 0)), | 206 (('', None), 0)), |
207 ((['git', 'rev-parse', '--show-cdup'],), ''), | |
208 ((['git', 'svn', 'info'],), ''), | 207 ((['git', 'svn', 'info'],), ''), |
209 ((['git', | 208 ((['git', |
210 'config', 'branch.master.rietveldissue', '1'],), ''), | 209 'config', 'branch.master.rietveldissue', '1'],), ''), |
211 ((['git', 'config', 'branch.master.rietveldserver', | 210 ((['git', 'config', 'branch.master.rietveldserver', |
212 'https://codereview.example.com'],), ''), | 211 'https://codereview.example.com'],), ''), |
213 ((['git', | 212 ((['git', |
214 'config', 'branch.master.rietveldpatchset', '2'],), ''), | 213 'config', 'branch.master.rietveldpatchset', '2'],), ''), |
215 ((['git', 'rev-parse', 'HEAD'],), 'hash'), | 214 ((['git', 'rev-parse', 'HEAD'],), 'hash'), |
216 ((['git', 'symbolic-ref', 'HEAD'],), 'hash'), | 215 ((['git', 'symbolic-ref', 'HEAD'],), 'hash'), |
217 ((['git', | 216 ((['git', |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 'config', 'branch.working.rietveldissue'],), '12345'), | 311 'config', 'branch.working.rietveldissue'],), '12345'), |
313 ((['git', 'config', 'branch.working.rietveldserver'],), | 312 ((['git', 'config', 'branch.working.rietveldserver'],), |
314 'codereview.example.com'), | 313 'codereview.example.com'), |
315 ((['git', 'config', 'rietveld.tree-status-url'],), ''), | 314 ((['git', 'config', 'rietveld.tree-status-url'],), ''), |
316 (('GitClHooksBypassedCommit', | 315 (('GitClHooksBypassedCommit', |
317 'Issue https://codereview.example.com/12345 bypassed hook when ' | 316 'Issue https://codereview.example.com/12345 bypassed hook when ' |
318 'committing (tree status was "unset")'), None), | 317 'committing (tree status was "unset")'), None), |
319 ] | 318 ] |
320 | 319 |
321 @classmethod | 320 @classmethod |
322 def _dcommit_calls_3(cls): | 321 def _dcommit_calls_3(cls, is_first_call): |
323 return [ | 322 calls = [ |
324 ((['git', | 323 ((['git', |
325 'diff', '--no-ext-diff', '--stat', '--find-copies-harder', | 324 'diff', '--no-ext-diff', '--stat', '--find-copies-harder', |
326 '-l100000', '-C50', 'fake_ancestor_sha', | 325 '-l100000', '-C50', 'fake_ancestor_sha', |
327 'refs/heads/working'],), | 326 'refs/heads/working'],), |
328 (' PRESUBMIT.py | 2 +-\n' | 327 (' PRESUBMIT.py | 2 +-\n' |
329 ' 1 files changed, 1 insertions(+), 1 deletions(-)\n')), | 328 ' 1 files changed, 1 insertions(+), 1 deletions(-)\n')), |
330 (('About to commit; enter to confirm.',), None), | 329 (('About to commit; enter to confirm.',), None), |
331 ((['git', 'show-ref', '--quiet', '--verify', | 330 ((['git', 'show-ref', '--quiet', '--verify', |
332 'refs/heads/git-cl-commit'],), | 331 'refs/heads/git-cl-commit'],), |
333 (('', None), 0)), | 332 (('', None), 0)), |
334 ((['git', 'branch', '-D', 'git-cl-commit'],), ''), | 333 ((['git', 'branch', '-D', 'git-cl-commit'],), ''), |
335 ((['git', 'show-ref', '--quiet', '--verify', | 334 ((['git', 'show-ref', '--quiet', '--verify', |
336 'refs/heads/git-cl-cherry-pick'],), ''), | 335 'refs/heads/git-cl-cherry-pick'],), ''), |
337 ((['git', 'rev-parse', '--show-cdup'],), '\n'), | 336 ] |
| 337 if is_first_call: |
| 338 calls += [ |
| 339 ((['git', 'rev-parse', '--show-cdup'],), '\n'), |
| 340 ] |
| 341 calls += [ |
338 ((['git', 'checkout', '-q', '-b', 'git-cl-commit'],), ''), | 342 ((['git', 'checkout', '-q', '-b', 'git-cl-commit'],), ''), |
339 ((['git', 'reset', '--soft', 'fake_ancestor_sha'],), ''), | 343 ((['git', 'reset', '--soft', 'fake_ancestor_sha'],), ''), |
340 ((['git', 'commit', '-m', | 344 ((['git', 'commit', '-m', |
341 'Issue: 12345\n\nR=john@chromium.org\n\n' | 345 'Issue: 12345\n\nR=john@chromium.org\n\n' |
342 'Review URL: https://codereview.example.com/12345'],), | 346 'Review URL: https://codereview.example.com/12345'],), |
343 ''), | 347 ''), |
344 ((['git', | 348 ((['git', |
345 'svn', 'dcommit', '-C50', '--no-rebase', '--rmdir'],), | 349 'svn', 'dcommit', '-C50', '--no-rebase', '--rmdir'],), |
346 (('', None), 0)), | 350 (('', None), 0)), |
347 ((['git', 'checkout', '-q', 'working'],), ''), | 351 ((['git', 'checkout', '-q', 'working'],), ''), |
348 ((['git', 'branch', '-D', 'git-cl-commit'],), ''), | 352 ((['git', 'branch', '-D', 'git-cl-commit'],), ''), |
349 ] | 353 ] |
| 354 return calls |
350 | 355 |
351 @staticmethod | 356 @staticmethod |
352 def _cmd_line(description, args, similarity, find_copies, private): | 357 def _cmd_line(description, args, similarity, find_copies, private): |
353 """Returns the upload command line passed to upload.RealMain().""" | 358 """Returns the upload command line passed to upload.RealMain().""" |
354 return [ | 359 return [ |
355 'upload', '--assume_yes', '--server', | 360 'upload', '--assume_yes', '--server', |
356 'https://codereview.example.com', | 361 'https://codereview.example.com', |
357 '--message', description | 362 '--message', description |
358 ] + args + [ | 363 ] + args + [ |
359 '--cc', 'joe@example.com', | 364 '--cc', 'joe@example.com', |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 '--similarity.\n', | 507 '--similarity.\n', |
503 stdout.getvalue()) | 508 stdout.getvalue()) |
504 self.assertEqual( | 509 self.assertEqual( |
505 'Must specify reviewers to send email.\n', stderr.getvalue()) | 510 'Must specify reviewers to send email.\n', stderr.getvalue()) |
506 | 511 |
507 def test_dcommit(self): | 512 def test_dcommit(self): |
508 self.calls = ( | 513 self.calls = ( |
509 self._dcommit_calls_1() + | 514 self._dcommit_calls_1() + |
510 self._git_sanity_checks('fake_ancestor_sha', 'working') + | 515 self._git_sanity_checks('fake_ancestor_sha', 'working') + |
511 self._dcommit_calls_normal() + | 516 self._dcommit_calls_normal() + |
512 self._dcommit_calls_3()) | 517 self._dcommit_calls_3(False)) |
513 git_cl.main(['dcommit']) | 518 git_cl.main(['dcommit']) |
514 | 519 |
515 def test_dcommit_bypass_hooks(self): | 520 def test_dcommit_bypass_hooks(self): |
516 self.calls = ( | 521 self.calls = ( |
517 self._dcommit_calls_1() + | 522 self._dcommit_calls_1() + |
518 self._dcommit_calls_bypassed() + | 523 self._dcommit_calls_bypassed() + |
519 self._dcommit_calls_3()) | 524 self._dcommit_calls_3(True)) |
520 git_cl.main(['dcommit', '--bypass-hooks']) | 525 git_cl.main(['dcommit', '--bypass-hooks']) |
521 | 526 |
522 | 527 |
523 @classmethod | 528 @classmethod |
524 def _gerrit_base_calls(cls): | 529 def _gerrit_base_calls(cls): |
525 return [ | 530 return [ |
526 ((['git', 'config', 'rietveld.autoupdate'],), | 531 ((['git', 'config', 'rietveld.autoupdate'],), |
527 ''), | 532 ''), |
528 ((['git', | 533 ((['git', |
529 'config', 'rietveld.server'],), 'codereview.example.com'), | 534 'config', 'rietveld.server'],), 'codereview.example.com'), |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 obj = git_cl.ChangeDescription(orig) | 738 obj = git_cl.ChangeDescription(orig) |
734 obj.update_reviewers(reviewers) | 739 obj.update_reviewers(reviewers) |
735 actual.append(obj.description) | 740 actual.append(obj.description) |
736 self.assertEqual(expected, actual) | 741 self.assertEqual(expected, actual) |
737 | 742 |
738 | 743 |
739 if __name__ == '__main__': | 744 if __name__ == '__main__': |
740 git_cl.logging.basicConfig( | 745 git_cl.logging.basicConfig( |
741 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) | 746 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) |
742 unittest.main() | 747 unittest.main() |
OLD | NEW |