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

Side by Side Diff: git_cl.py

Issue 7134097: Fix support for AUTHOR presubmit check in git cl. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 9 years, 6 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 | « no previous file | 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) 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 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 """Set this branch's issue. If issue=0, clears the issue.""" 503 """Set this branch's issue. If issue=0, clears the issue."""
504 if issue: 504 if issue:
505 RunGit(['config', self._IssueSetting(), str(issue)]) 505 RunGit(['config', self._IssueSetting(), str(issue)])
506 if self.rietveld_server: 506 if self.rietveld_server:
507 RunGit(['config', self._RietveldServer(), self.rietveld_server]) 507 RunGit(['config', self._RietveldServer(), self.rietveld_server])
508 else: 508 else:
509 RunGit(['config', '--unset', self._IssueSetting()]) 509 RunGit(['config', '--unset', self._IssueSetting()])
510 self.SetPatchset(0) 510 self.SetPatchset(0)
511 self.has_issue = False 511 self.has_issue = False
512 512
513 def RunHook(self, committing, upstream_branch, tbr, may_prompt, verbose): 513 def RunHook(self, committing, upstream_branch, tbr, may_prompt, verbose,
514 author):
514 """Calls sys.exit() if the hook fails; returns a HookResults otherwise.""" 515 """Calls sys.exit() if the hook fails; returns a HookResults otherwise."""
515 root = RunCommand(['git', 'rev-parse', '--show-cdup']).strip() or '.' 516 root = RunCommand(['git', 'rev-parse', '--show-cdup']).strip() or '.'
516 absroot = os.path.abspath(root) 517 absroot = os.path.abspath(root)
517 518
518 # We use the sha1 of HEAD as a name of this change. 519 # We use the sha1 of HEAD as a name of this change.
519 name = RunCommand(['git', 'rev-parse', 'HEAD']).strip() 520 name = RunCommand(['git', 'rev-parse', 'HEAD']).strip()
520 # Need to pass a relative path for msysgit. 521 # Need to pass a relative path for msysgit.
521 files = scm.GIT.CaptureStatus([root], upstream_branch) 522 files = scm.GIT.CaptureStatus([root], upstream_branch)
522 523
523 issue = ConvertToInteger(self.GetIssue()) 524 issue = ConvertToInteger(self.GetIssue())
524 patchset = ConvertToInteger(self.GetPatchset()) 525 patchset = ConvertToInteger(self.GetPatchset())
525 if issue: 526 if issue:
526 description = self.GetDescription() 527 description = self.GetDescription()
527 else: 528 else:
528 # If the change was never uploaded, use the log messages of all commits 529 # 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 530 # up to the branch point, as git cl upload will prefill the description
530 # with these log messages. 531 # with these log messages.
531 description = RunCommand(['git', 'log', '--pretty=format:%s%n%n%b', 532 description = RunCommand(['git', 'log', '--pretty=format:%s%n%n%b',
532 '%s...' % (upstream_branch)]).strip() 533 '%s...' % (upstream_branch)]).strip()
534
535 if not author:
536 author = RunGit(['config', 'user.email'])
533 change = presubmit_support.GitChange( 537 change = presubmit_support.GitChange(
534 name, 538 name,
535 description, 539 description,
536 absroot, 540 absroot,
537 files, 541 files,
538 issue, 542 issue,
539 patchset, 543 patchset,
540 None) 544 author)
541 545
542 # Apply watchlists on upload. 546 # Apply watchlists on upload.
543 if not committing: 547 if not committing:
544 watchlist = watchlists.Watchlists(change.RepositoryRoot()) 548 watchlist = watchlists.Watchlists(change.RepositoryRoot())
545 files = [f.LocalPath() for f in change.AffectedFiles()] 549 files = [f.LocalPath() for f in change.AffectedFiles()]
546 self.SetWatchers(watchlist.GetWatchersForPaths(files)) 550 self.SetWatchers(watchlist.GetWatchersForPaths(files))
547 551
548 try: 552 try:
549 output = presubmit_support.DoPresubmitChecks(change, committing, 553 output = presubmit_support.DoPresubmitChecks(change, committing,
550 verbose=verbose, output_stream=sys.stdout, input_stream=sys.stdin, 554 verbose=verbose, output_stream=sys.stdout, input_stream=sys.stdin,
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 return 1 890 return 1
887 891
888 cl = Changelist() 892 cl = Changelist()
889 if args: 893 if args:
890 base_branch = args[0] 894 base_branch = args[0]
891 else: 895 else:
892 # Default to diffing against the "upstream" branch. 896 # Default to diffing against the "upstream" branch.
893 base_branch = cl.GetUpstreamBranch() 897 base_branch = cl.GetUpstreamBranch()
894 898
895 cl.RunHook(committing=not options.upload, upstream_branch=base_branch, 899 cl.RunHook(committing=not options.upload, upstream_branch=base_branch,
896 tbr=False, may_prompt=False, verbose=options.verbose) 900 tbr=False, may_prompt=False, verbose=options.verbose,
901 author=None)
897 return 0 902 return 0
898 903
899 904
900 @usage('[args to "git diff"]') 905 @usage('[args to "git diff"]')
901 def CMDupload(parser, args): 906 def CMDupload(parser, args):
902 """upload the current changelist to codereview""" 907 """upload the current changelist to codereview"""
903 parser.add_option('--bypass-hooks', action='store_true', dest='bypass_hooks', 908 parser.add_option('--bypass-hooks', action='store_true', dest='bypass_hooks',
904 help='bypass upload presubmit hook') 909 help='bypass upload presubmit hook')
905 parser.add_option('-f', action='store_true', dest='force', 910 parser.add_option('-f', action='store_true', dest='force',
906 help="force yes to questions (don't prompt)") 911 help="force yes to questions (don't prompt)")
(...skipping 25 matching lines...) Expand all
932 if args: 937 if args:
933 base_branch = args[0] 938 base_branch = args[0]
934 else: 939 else:
935 # Default to diffing against the "upstream" branch. 940 # Default to diffing against the "upstream" branch.
936 base_branch = cl.GetUpstreamBranch() 941 base_branch = cl.GetUpstreamBranch()
937 args = [base_branch + "..."] 942 args = [base_branch + "..."]
938 943
939 if not options.bypass_hooks and not options.force: 944 if not options.bypass_hooks and not options.force:
940 hook_results = cl.RunHook(committing=False, upstream_branch=base_branch, 945 hook_results = cl.RunHook(committing=False, upstream_branch=base_branch,
941 tbr=False, may_prompt=True, 946 tbr=False, may_prompt=True,
942 verbose=options.verbose) 947 verbose=options.verbose,
948 author=None)
943 if not options.reviewers and hook_results.reviewers: 949 if not options.reviewers and hook_results.reviewers:
944 options.reviewers = hook_results.reviewers 950 options.reviewers = hook_results.reviewers
945 951
946 952
947 # --no-ext-diff is broken in some versions of Git, so try to work around 953 # --no-ext-diff is broken in some versions of Git, so try to work around
948 # this by overriding the environment (but there is still a problem if the 954 # this by overriding the environment (but there is still a problem if the
949 # git config key "diff.external" is used). 955 # git config key "diff.external" is used).
950 env = os.environ.copy() 956 env = os.environ.copy()
951 if 'GIT_EXTERNAL_DIFF' in env: 957 if 'GIT_EXTERNAL_DIFF' in env:
952 del env['GIT_EXTERNAL_DIFF'] 958 del env['GIT_EXTERNAL_DIFF']
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1087 extra_commits = RunGit(['rev-list', '^' + svn_head, base_branch]) 1093 extra_commits = RunGit(['rev-list', '^' + svn_head, base_branch])
1088 if extra_commits: 1094 if extra_commits:
1089 print ('This branch has %d additional commits not upstreamed yet.' 1095 print ('This branch has %d additional commits not upstreamed yet.'
1090 % len(extra_commits.splitlines())) 1096 % len(extra_commits.splitlines()))
1091 print ('Upstream "%s" or rebase this branch on top of the upstream trunk ' 1097 print ('Upstream "%s" or rebase this branch on top of the upstream trunk '
1092 'before attempting to %s.' % (base_branch, cmd)) 1098 'before attempting to %s.' % (base_branch, cmd))
1093 return 1 1099 return 1
1094 1100
1095 if not options.bypass_hooks and not options.force: 1101 if not options.bypass_hooks and not options.force:
1096 cl.RunHook(committing=True, upstream_branch=base_branch, 1102 cl.RunHook(committing=True, upstream_branch=base_branch,
1097 tbr=options.tbr, may_prompt=True, verbose=options.verbose) 1103 tbr=options.tbr, may_prompt=True, verbose=options.verbose,
1104 author=options.contributor)
1098 1105
1099 if cmd == 'dcommit': 1106 if cmd == 'dcommit':
1100 # Check the tree status if the tree status URL is set. 1107 # Check the tree status if the tree status URL is set.
1101 status = GetTreeStatus() 1108 status = GetTreeStatus()
1102 if 'closed' == status: 1109 if 'closed' == status:
1103 print ('The tree is closed. Please wait for it to reopen. Use ' 1110 print ('The tree is closed. Please wait for it to reopen. Use '
1104 '"git cl dcommit -f" to commit on a closed tree.') 1111 '"git cl dcommit -f" to commit on a closed tree.')
1105 return 1 1112 return 1
1106 elif 'unknown' == status: 1113 elif 'unknown' == status:
1107 print ('Unable to determine tree status. Please verify manually and ' 1114 print ('Unable to determine tree status. Please verify manually and '
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
1472 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) 1479 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e)))
1473 1480
1474 # Not a known command. Default to help. 1481 # Not a known command. Default to help.
1475 GenUsage(parser, 'help') 1482 GenUsage(parser, 'help')
1476 return CMDhelp(parser, argv) 1483 return CMDhelp(parser, argv)
1477 1484
1478 1485
1479 if __name__ == '__main__': 1486 if __name__ == '__main__':
1480 fix_encoding.fix_encoding() 1487 fix_encoding.fix_encoding()
1481 sys.exit(main(sys.argv[1:])) 1488 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698