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

Side by Side Diff: git_cl.py

Issue 7484002: Fix git-cl --contributor flag support for presubmit checks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Fixed whth --contributor is not used, duh Created 9 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « gclient_scm.py ('k') | tests/gclient_scm_test.py » ('j') | 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) 2011 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2011 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 # Copyright (C) 2008 Evan Martin <martine@danga.com> 6 # Copyright (C) 2008 Evan Martin <martine@danga.com>
7 7
8 """A git-command for integrating reviews on Rietveld.""" 8 """A git-command for integrating reviews on Rietveld."""
9 9
10 import errno 10 import errno
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 if issue: 525 if issue:
526 description = self.GetDescription() 526 description = self.GetDescription()
527 else: 527 else:
528 # If the change was never uploaded, use the log messages of all commits 528 # If the change was never uploaded, use the log messages of all commits
529 # up to the branch point, as git cl upload will prefill the description 529 # up to the branch point, as git cl upload will prefill the description
530 # with these log messages. 530 # with these log messages.
531 description = RunCommand(['git', 'log', '--pretty=format:%s%n%n%b', 531 description = RunCommand(['git', 'log', '--pretty=format:%s%n%n%b',
532 '%s...' % (upstream_branch)]).strip() 532 '%s...' % (upstream_branch)]).strip()
533 533
534 if not author: 534 if not author:
535 author = RunGit(['config', 'user.email']).strip() 535 author = RunGit(['config', 'user.email']).strip() or None
536 change = presubmit_support.GitChange( 536 change = presubmit_support.GitChange(
537 name, 537 name,
538 description, 538 description,
539 absroot, 539 absroot,
540 files, 540 files,
541 issue, 541 issue,
542 patchset, 542 patchset,
543 author) 543 author)
544 544
545 # Apply watchlists on upload. 545 # Apply watchlists on upload.
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
1057 help="external contributor for patch (appended to " + 1057 help="external contributor for patch (appended to " +
1058 "description and used as author for git). Should be " + 1058 "description and used as author for git). Should be " +
1059 "formatted as 'First Last <email@example.com>'") 1059 "formatted as 'First Last <email@example.com>'")
1060 (options, args) = parser.parse_args(args) 1060 (options, args) = parser.parse_args(args)
1061 cl = Changelist() 1061 cl = Changelist()
1062 1062
1063 if not args or cmd == 'push': 1063 if not args or cmd == 'push':
1064 # Default to merging against our best guess of the upstream branch. 1064 # Default to merging against our best guess of the upstream branch.
1065 args = [cl.GetUpstreamBranch()] 1065 args = [cl.GetUpstreamBranch()]
1066 1066
1067 if options.contributor:
1068 if not re.match('^.*\s<\S+@\S+>$', options.contributor):
1069 print "Please provide contibutor as 'First Last <email@example.com>'"
1070 return 1
1071
1067 base_branch = args[0] 1072 base_branch = args[0]
1068 1073
1069 # Make sure index is up-to-date before running diff-index. 1074 # Make sure index is up-to-date before running diff-index.
1070 RunGit(['update-index', '--refresh', '-q'], error_ok=True) 1075 RunGit(['update-index', '--refresh', '-q'], error_ok=True)
1071 if RunGit(['diff-index', 'HEAD']): 1076 if RunGit(['diff-index', 'HEAD']):
1072 print 'Cannot %s with a dirty tree. You must commit locally first.' % cmd 1077 print 'Cannot %s with a dirty tree. You must commit locally first.' % cmd
1073 return 1 1078 return 1
1074 1079
1075 # This rev-list syntax means "show all commits not in my branch that 1080 # This rev-list syntax means "show all commits not in my branch that
1076 # are in base_branch". 1081 # are in base_branch".
(...skipping 11 matching lines...) Expand all
1088 '--pretty=format:%H']) 1093 '--pretty=format:%H'])
1089 extra_commits = RunGit(['rev-list', '^' + svn_head, base_branch]) 1094 extra_commits = RunGit(['rev-list', '^' + svn_head, base_branch])
1090 if extra_commits: 1095 if extra_commits:
1091 print ('This branch has %d additional commits not upstreamed yet.' 1096 print ('This branch has %d additional commits not upstreamed yet.'
1092 % len(extra_commits.splitlines())) 1097 % len(extra_commits.splitlines()))
1093 print ('Upstream "%s" or rebase this branch on top of the upstream trunk ' 1098 print ('Upstream "%s" or rebase this branch on top of the upstream trunk '
1094 'before attempting to %s.' % (base_branch, cmd)) 1099 'before attempting to %s.' % (base_branch, cmd))
1095 return 1 1100 return 1
1096 1101
1097 if not options.bypass_hooks and not options.force: 1102 if not options.bypass_hooks and not options.force:
1103 author = None
1104 if options.contributor:
1105 author = re.search(r'\<(.*)\>', options.contributor).group(1)
1098 cl.RunHook(committing=True, upstream_branch=base_branch, 1106 cl.RunHook(committing=True, upstream_branch=base_branch,
1099 may_prompt=True, verbose=options.verbose, 1107 may_prompt=True, verbose=options.verbose,
1100 author=options.contributor) 1108 author=author)
1101 1109
1102 if cmd == 'dcommit': 1110 if cmd == 'dcommit':
1103 # Check the tree status if the tree status URL is set. 1111 # Check the tree status if the tree status URL is set.
1104 status = GetTreeStatus() 1112 status = GetTreeStatus()
1105 if 'closed' == status: 1113 if 'closed' == status:
1106 print ('The tree is closed. Please wait for it to reopen. Use ' 1114 print ('The tree is closed. Please wait for it to reopen. Use '
1107 '"git cl dcommit -f" to commit on a closed tree.') 1115 '"git cl dcommit -f" to commit on a closed tree.')
1108 return 1 1116 return 1
1109 elif 'unknown' == status: 1117 elif 'unknown' == status:
1110 print ('Unable to determine tree status. Please verify manually and ' 1118 print ('Unable to determine tree status. Please verify manually and '
1111 'use "git cl dcommit -f" to commit on a closed tree.') 1119 'use "git cl dcommit -f" to commit on a closed tree.')
1112 1120
1113 description = options.message 1121 description = options.message
1114 if not description and cl.GetIssue(): 1122 if not description and cl.GetIssue():
1115 description = cl.GetDescription() 1123 description = cl.GetDescription()
1116 1124
1117 if not description: 1125 if not description:
1118 print 'No description set.' 1126 print 'No description set.'
1119 print 'Visit %s/edit to set it.' % (cl.GetIssueURL()) 1127 print 'Visit %s/edit to set it.' % (cl.GetIssueURL())
1120 return 1 1128 return 1
1121 1129
1122 if cl.GetIssue(): 1130 if cl.GetIssue():
1123 description += "\n\nReview URL: %s" % cl.GetIssueURL() 1131 description += "\n\nReview URL: %s" % cl.GetIssueURL()
1124 1132
1125 if options.contributor: 1133 if options.contributor:
1126 if not re.match('^.*\s<\S+@\S+>$', options.contributor):
1127 print "Please provide contibutor as 'First Last <email@example.com>'"
1128 return 1
1129 description += "\nPatch from %s." % options.contributor 1134 description += "\nPatch from %s." % options.contributor
1130 print 'Description:', repr(description) 1135 print 'Description:', repr(description)
1131 1136
1132 branches = [base_branch, cl.GetBranchRef()] 1137 branches = [base_branch, cl.GetBranchRef()]
1133 if not options.force: 1138 if not options.force:
1134 subprocess.call(['git', 'diff', '--stat'] + branches) 1139 subprocess.call(['git', 'diff', '--stat'] + branches)
1135 ask_for_data('About to commit; enter to confirm.') 1140 ask_for_data('About to commit; enter to confirm.')
1136 1141
1137 # We want to squash all this branch's commits into one commit with the 1142 # We want to squash all this branch's commits into one commit with the
1138 # proper description. 1143 # proper description.
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
1446 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) 1451 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e)))
1447 1452
1448 # Not a known command. Default to help. 1453 # Not a known command. Default to help.
1449 GenUsage(parser, 'help') 1454 GenUsage(parser, 'help')
1450 return CMDhelp(parser, argv) 1455 return CMDhelp(parser, argv)
1451 1456
1452 1457
1453 if __name__ == '__main__': 1458 if __name__ == '__main__':
1454 fix_encoding.fix_encoding() 1459 fix_encoding.fix_encoding()
1455 sys.exit(main(sys.argv[1:])) 1460 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « gclient_scm.py ('k') | tests/gclient_scm_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698