Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Side by Side Diff: tests/git_cl_test.py

Issue 12388027: git cl upload now diffs HEAD rather than working tree (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « git_cl.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 find_copies_call = ((['git', 'config', '--int', '--get', 113 find_copies_call = ((['git', 'config', '--int', '--get',
114 'branch.master.git-find-copies'],), '') 114 'branch.master.git-find-copies'],), '')
115 else: 115 else:
116 val = str(int(find_copies)) 116 val = str(int(find_copies))
117 find_copies_call = ((['git', 'config', '--int', 117 find_copies_call = ((['git', 'config', '--int',
118 'branch.master.git-find-copies', val],), '') 118 'branch.master.git-find-copies', val],), '')
119 119
120 if find_copies: 120 if find_copies:
121 stat_call = ((['git', 'diff', '--no-ext-diff', '--stat', 121 stat_call = ((['git', 'diff', '--no-ext-diff', '--stat',
122 '--find-copies-harder', '-l100000', '-C'+similarity, 122 '--find-copies-harder', '-l100000', '-C'+similarity,
123 'fake_ancestor_sha'],), '+dat') 123 'fake_ancestor_sha', 'HEAD'],), '+dat')
124 else: 124 else:
125 stat_call = ((['git', 'diff', '--no-ext-diff', '--stat', 125 stat_call = ((['git', 'diff', '--no-ext-diff', '--stat',
126 '-M'+similarity, 'fake_ancestor_sha'],), '+dat') 126 '-M'+similarity, 'fake_ancestor_sha', 'HEAD'],), '+dat')
127 127
128 return [ 128 return [
129 ((['git', 'config', 'rietveld.server'],), 'codereview.example.com'), 129 ((['git', 'config', 'rietveld.server'],), 'codereview.example.com'),
130 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), 130 ((['git', 'symbolic-ref', 'HEAD'],), 'master'),
131 similarity_call, 131 similarity_call,
132 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), 132 ((['git', 'symbolic-ref', 'HEAD'],), 'master'),
133 find_copies_call, 133 find_copies_call,
134 ((['git', 'update-index', '--refresh', '-q'],), ''), 134 ((['git', 'update-index', '--refresh', '-q'],), ''),
135 ((['git', 'diff-index', '--name-status', 'HEAD'],), ''), 135 ((['git', 'diff-index', '--name-status', 'HEAD'],), ''),
136 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), 136 ((['git', 'symbolic-ref', 'HEAD'],), 'master'),
137 ((['git', 'config', 'branch.master.merge'],), 'master'), 137 ((['git', 'config', 'branch.master.merge'],), 'master'),
138 ((['git', 'config', 'branch.master.remote'],), 'origin'), 138 ((['git', 'config', 'branch.master.remote'],), 'origin'),
139 ((['git', 'merge-base', 'master', 'HEAD'],), 'fake_ancestor_sha'), 139 ((['git', 'merge-base', 'master', 'HEAD'],), 'fake_ancestor_sha'),
140 ] + cls._git_sanity_checks('fake_ancestor_sha', 'master') + [ 140 ] + cls._git_sanity_checks('fake_ancestor_sha', 'master') + [
141 ((['git', 'rev-parse', '--show-cdup'],), ''), 141 ((['git', 'rev-parse', '--show-cdup'],), ''),
142 ((['git', 'rev-parse', 'HEAD'],), '12345'), 142 ((['git', 'rev-parse', 'HEAD'],), '12345'),
143 ((['git', 'diff', '--name-status', '-r', 'fake_ancestor_sha...', '.'],), 143 ((['git', 'diff', '--name-status', '-r', 'fake_ancestor_sha...', '.'],),
144 'M\t.gitignore\n'), 144 'M\t.gitignore\n'),
145 ((['git', 'config', 'branch.master.rietveldissue'],), ''), 145 ((['git', 'config', 'branch.master.rietveldissue'],), ''),
146 ((['git', 'config', 'branch.master.rietveldpatchset'],), ''), 146 ((['git', 'config', 'branch.master.rietveldpatchset'],), ''),
147 ((['git', 'log', '--pretty=format:%s%n%n%b', 'fake_ancestor_sha...'],), 147 ((['git', 'log', '--pretty=format:%s%n%n%b', 'fake_ancestor_sha...'],),
148 'foo'), 148 'foo'),
149 ((['git', 'config', 'user.email'],), 'me@example.com'), 149 ((['git', 'config', 'user.email'],), 'me@example.com'),
150 stat_call, 150 stat_call,
151 ((['git', 'config', 'gerrit.host'],), ''), 151 ((['git', 'config', 'gerrit.host'],), ''),
152 ((['git', 'log', '--pretty=format:%s\n\n%b', 'fake_ancestor_sha..'],), 152 ((['git', 'log', '--pretty=format:%s\n\n%b', 'fake_ancestor_sha..HEAD'],),
153 'desc\n'), 153 'desc\n'),
154 ] 154 ]
155 155
156 @classmethod 156 @classmethod
157 def _git_upload_calls(cls): 157 def _git_upload_calls(cls):
158 return [ 158 return [
159 ((['git', 'config', 'rietveld.cc'],), ''), 159 ((['git', 'config', 'rietveld.cc'],), ''),
160 ((['git', 'config', 'branch.master.base-url'],), ''), 160 ((['git', 'config', 'branch.master.base-url'],), ''),
161 ((['git', 'config', '--get-regexp', '^svn-remote\\.'],), 161 ((['git', 'config', '--get-regexp', '^svn-remote\\.'],),
162 (('', None), 0)), 162 (('', None), 0)),
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 def _cmd_line(description, args, similarity, find_copies): 280 def _cmd_line(description, args, similarity, find_copies):
281 """Returns the upload command line passed to upload.RealMain().""" 281 """Returns the upload command line passed to upload.RealMain()."""
282 return [ 282 return [
283 'upload', '--assume_yes', '--server', 283 'upload', '--assume_yes', '--server',
284 'https://codereview.example.com', 284 'https://codereview.example.com',
285 '--message', description 285 '--message', description
286 ] + args + [ 286 ] + args + [
287 '--cc', 'joe@example.com', 287 '--cc', 'joe@example.com',
288 '--git_similarity', similarity or '50' 288 '--git_similarity', similarity or '50'
289 ] + (['--git_no_find_copies'] if find_copies == False else []) + [ 289 ] + (['--git_no_find_copies'] if find_copies == False else []) + [
290 'fake_ancestor_sha' 290 'fake_ancestor_sha', 'HEAD'
291 ] 291 ]
292 292
293 def _run_reviewer_test( 293 def _run_reviewer_test(
294 self, 294 self,
295 upload_args, 295 upload_args,
296 expected_description, 296 expected_description,
297 returned_description, 297 returned_description,
298 final_description, 298 final_description,
299 reviewers): 299 reviewers):
300 """Generic reviewer test framework.""" 300 """Generic reviewer test framework."""
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 ((['git', 'rev-parse', '--show-cdup'],), ''), 450 ((['git', 'rev-parse', '--show-cdup'],), ''),
451 ((['git', 'rev-parse', 'HEAD'],), '12345'), 451 ((['git', 'rev-parse', 'HEAD'],), '12345'),
452 ((['git', 'diff', '--name-status', '-r', 'fake_ancestor_sha...', '.'],), 452 ((['git', 'diff', '--name-status', '-r', 'fake_ancestor_sha...', '.'],),
453 'M\t.gitignore\n'), 453 'M\t.gitignore\n'),
454 ((['git', 'config', 'branch.master.rietveldissue'],), ''), 454 ((['git', 'config', 'branch.master.rietveldissue'],), ''),
455 ((['git', 'config', 'branch.master.rietveldpatchset'],), ''), 455 ((['git', 'config', 'branch.master.rietveldpatchset'],), ''),
456 ((['git', 'log', '--pretty=format:%s%n%n%b', 'fake_ancestor_sha...'],), 456 ((['git', 'log', '--pretty=format:%s%n%n%b', 'fake_ancestor_sha...'],),
457 'foo'), 457 'foo'),
458 ((['git', 'config', 'user.email'],), 'me@example.com'), 458 ((['git', 'config', 'user.email'],), 'me@example.com'),
459 ((['git', 'diff', '--no-ext-diff', '--stat', '--find-copies-harder', 459 ((['git', 'diff', '--no-ext-diff', '--stat', '--find-copies-harder',
460 '-l100000', '-C50', 'fake_ancestor_sha'],), 460 '-l100000', '-C50', 'fake_ancestor_sha', 'HEAD'],),
461 '+dat'), 461 '+dat'),
462 ] 462 ]
463 463
464 @staticmethod 464 @staticmethod
465 def _gerrit_upload_calls(description, reviewers): 465 def _gerrit_upload_calls(description, reviewers):
466 calls = [ 466 calls = [
467 ((['git', 'config', 'gerrit.host'],), 'gerrit.example.com'), 467 ((['git', 'config', 'gerrit.host'],), 'gerrit.example.com'),
468 ((['git', 'log', '--pretty=format:%s\n\n%b', 'fake_ancestor_sha..'],), 468 ((['git', 'log', '--pretty=format:%s\n\n%b',
469 'fake_ancestor_sha..HEAD'],),
469 description) 470 description)
470 ] 471 ]
471 if git_cl.CHANGE_ID not in description: 472 if git_cl.CHANGE_ID not in description:
472 calls += [ 473 calls += [
473 ((['git', 'log', '--pretty=format:%s\n\n%b', 'fake_ancestor_sha..'],), 474 ((['git', 'log', '--pretty=format:%s\n\n%b',
475 'fake_ancestor_sha..HEAD'],),
474 description), 476 description),
475 ((['git', 'commit', '--amend', '-m', description],), 477 ((['git', 'commit', '--amend', '-m', description],),
476 ''), 478 ''),
477 ((['git', 'log', '--pretty=format:%s\n\n%b', 'fake_ancestor_sha..'],), 479 ((['git', 'log', '--pretty=format:%s\n\n%b',
480 'fake_ancestor_sha..HEAD'],),
478 description) 481 description)
479 ] 482 ]
480 calls += [ 483 calls += [
481 ((['git', 'config', 'rietveld.cc'],), '') 484 ((['git', 'config', 'rietveld.cc'],), '')
482 ] 485 ]
483 receive_pack = '--receive-pack=git receive-pack ' 486 receive_pack = '--receive-pack=git receive-pack '
484 receive_pack += '--cc=joe@example.com' # from watch list 487 receive_pack += '--cc=joe@example.com' # from watch list
485 if reviewers: 488 if reviewers:
486 receive_pack += ' ' 489 receive_pack += ' '
487 receive_pack += ' '.join(['--reviewer=' + email for email in reviewers]) 490 receive_pack += ' '.join(['--reviewer=' + email for email in reviewers])
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 ((['git', 'config', 'rietveld.viewvc-url'],), ''), 583 ((['git', 'config', 'rietveld.viewvc-url'],), ''),
581 (('ViewVC URL:',), ''), 584 (('ViewVC URL:',), ''),
582 # DownloadHooks(True) 585 # DownloadHooks(True)
583 ((commit_msg_path, os.X_OK,), True), 586 ((commit_msg_path, os.X_OK,), True),
584 ] 587 ]
585 git_cl.main(['config']) 588 git_cl.main(['config'])
586 589
587 590
588 if __name__ == '__main__': 591 if __name__ == '__main__':
589 unittest.main() 592 unittest.main()
OLDNEW
« no previous file with comments | « git_cl.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698