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 # 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 json | 10 import json |
(...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
688 author = RunGit(['config', 'user.email']).strip() or None | 688 author = RunGit(['config', 'user.email']).strip() or None |
689 return presubmit_support.GitChange( | 689 return presubmit_support.GitChange( |
690 name, | 690 name, |
691 description, | 691 description, |
692 absroot, | 692 absroot, |
693 files, | 693 files, |
694 issue, | 694 issue, |
695 patchset, | 695 patchset, |
696 author) | 696 author) |
697 | 697 |
698 def RunHook(self, committing, upstream_branch, may_prompt, verbose, author): | 698 def RunHook(self, committing, may_prompt, verbose, change): |
699 """Calls sys.exit() if the hook fails; returns a HookResults otherwise.""" | 699 """Calls sys.exit() if the hook fails; returns a HookResults otherwise.""" |
700 change = self.GetChange(upstream_branch, author) | |
701 | |
702 # Apply watchlists on upload. | |
703 if not committing: | |
704 watchlist = watchlists.Watchlists(change.RepositoryRoot()) | |
705 files = [f.LocalPath() for f in change.AffectedFiles()] | |
706 self.SetWatchers(watchlist.GetWatchersForPaths(files)) | |
707 | 700 |
708 try: | 701 try: |
709 return presubmit_support.DoPresubmitChecks(change, committing, | 702 return presubmit_support.DoPresubmitChecks(change, committing, |
710 verbose=verbose, output_stream=sys.stdout, input_stream=sys.stdin, | 703 verbose=verbose, output_stream=sys.stdout, input_stream=sys.stdin, |
711 default_presubmit=None, may_prompt=may_prompt, | 704 default_presubmit=None, may_prompt=may_prompt, |
712 rietveld_obj=self.RpcServer()) | 705 rietveld_obj=self.RpcServer()) |
713 except presubmit_support.PresubmitFailure, e: | 706 except presubmit_support.PresubmitFailure, e: |
714 DieWithError( | 707 DieWithError( |
715 ('%s\nMaybe your depot_tools is out of date?\n' | 708 ('%s\nMaybe your depot_tools is out of date?\n' |
716 'If all fails, contact maruel@') % e) | 709 'If all fails, contact maruel@') % e) |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1063 print 'use --force to check even if tree is dirty.' | 1056 print 'use --force to check even if tree is dirty.' |
1064 return 1 | 1057 return 1 |
1065 | 1058 |
1066 cl = Changelist() | 1059 cl = Changelist() |
1067 if args: | 1060 if args: |
1068 base_branch = args[0] | 1061 base_branch = args[0] |
1069 else: | 1062 else: |
1070 # Default to diffing against the common ancestor of the upstream branch. | 1063 # Default to diffing against the common ancestor of the upstream branch. |
1071 base_branch = RunGit(['merge-base', cl.GetUpstreamBranch(), 'HEAD']).strip() | 1064 base_branch = RunGit(['merge-base', cl.GetUpstreamBranch(), 'HEAD']).strip() |
1072 | 1065 |
1073 cl.RunHook(committing=not options.upload, upstream_branch=base_branch, | 1066 cl.RunHook( |
1074 may_prompt=False, verbose=options.verbose, | 1067 committing=not options.upload, |
1075 author=None) | 1068 may_prompt=False, |
| 1069 verbose=options.verbose, |
| 1070 change=cl.GetChange(base_branch, None)) |
1076 return 0 | 1071 return 0 |
1077 | 1072 |
1078 | 1073 |
1079 def AddChangeIdToCommitMessage(options, args): | 1074 def AddChangeIdToCommitMessage(options, args): |
1080 """Re-commits using the current message, assumes the commit hook is in | 1075 """Re-commits using the current message, assumes the commit hook is in |
1081 place. | 1076 place. |
1082 """ | 1077 """ |
1083 log_desc = options.message or CreateDescriptionFromLog(args) | 1078 log_desc = options.message or CreateDescriptionFromLog(args) |
1084 git_command = ['commit', '--amend', '-m', log_desc] | 1079 git_command = ['commit', '--amend', '-m', log_desc] |
1085 RunGit(git_command) | 1080 RunGit(git_command) |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1267 | 1262 |
1268 cl = Changelist() | 1263 cl = Changelist() |
1269 if args: | 1264 if args: |
1270 # TODO(ukai): is it ok for gerrit case? | 1265 # TODO(ukai): is it ok for gerrit case? |
1271 base_branch = args[0] | 1266 base_branch = args[0] |
1272 else: | 1267 else: |
1273 # Default to diffing against common ancestor of upstream branch | 1268 # Default to diffing against common ancestor of upstream branch |
1274 base_branch = RunGit(['merge-base', cl.GetUpstreamBranch(), 'HEAD']).strip() | 1269 base_branch = RunGit(['merge-base', cl.GetUpstreamBranch(), 'HEAD']).strip() |
1275 args = [base_branch, 'HEAD'] | 1270 args = [base_branch, 'HEAD'] |
1276 | 1271 |
| 1272 # Apply watchlists on upload. |
| 1273 change = cl.GetChange(base_branch, None) |
| 1274 watchlist = watchlists.Watchlists(change.RepositoryRoot()) |
| 1275 files = [f.LocalPath() for f in change.AffectedFiles()] |
| 1276 cl.SetWatchers(watchlist.GetWatchersForPaths(files)) |
| 1277 |
1277 if not options.bypass_hooks: | 1278 if not options.bypass_hooks: |
1278 hook_results = cl.RunHook(committing=False, upstream_branch=base_branch, | 1279 hook_results = cl.RunHook(committing=False, |
1279 may_prompt=not options.force, | 1280 may_prompt=not options.force, |
1280 verbose=options.verbose, | 1281 verbose=options.verbose, |
1281 author=None) | 1282 change=change) |
1282 if not hook_results.should_continue(): | 1283 if not hook_results.should_continue(): |
1283 return 1 | 1284 return 1 |
1284 if not options.reviewers and hook_results.reviewers: | 1285 if not options.reviewers and hook_results.reviewers: |
1285 options.reviewers = hook_results.reviewers | 1286 options.reviewers = hook_results.reviewers |
1286 | 1287 |
1287 print_stats(options.similarity, options.find_copies, args) | 1288 print_stats(options.similarity, options.find_copies, args) |
1288 if settings.GetIsGerrit(): | 1289 if settings.GetIsGerrit(): |
1289 return GerritUpload(options, args, cl) | 1290 return GerritUpload(options, args, cl) |
1290 return RietveldUpload(options, args, cl) | 1291 return RietveldUpload(options, args, cl) |
1291 | 1292 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1364 'before attempting to %s.' % (base_branch, cmd)) | 1365 'before attempting to %s.' % (base_branch, cmd)) |
1365 return 1 | 1366 return 1 |
1366 | 1367 |
1367 base_branch = RunGit(['merge-base', base_branch, 'HEAD']).strip() | 1368 base_branch = RunGit(['merge-base', base_branch, 'HEAD']).strip() |
1368 if not options.bypass_hooks: | 1369 if not options.bypass_hooks: |
1369 author = None | 1370 author = None |
1370 if options.contributor: | 1371 if options.contributor: |
1371 author = re.search(r'\<(.*)\>', options.contributor).group(1) | 1372 author = re.search(r'\<(.*)\>', options.contributor).group(1) |
1372 hook_results = cl.RunHook( | 1373 hook_results = cl.RunHook( |
1373 committing=True, | 1374 committing=True, |
1374 upstream_branch=base_branch, | |
1375 may_prompt=not options.force, | 1375 may_prompt=not options.force, |
1376 verbose=options.verbose, | 1376 verbose=options.verbose, |
1377 author=author) | 1377 change=cl.GetChange(base_branch, author)) |
1378 if not hook_results.should_continue(): | 1378 if not hook_results.should_continue(): |
1379 return 1 | 1379 return 1 |
1380 | 1380 |
1381 if cmd == 'dcommit': | 1381 if cmd == 'dcommit': |
1382 # Check the tree status if the tree status URL is set. | 1382 # Check the tree status if the tree status URL is set. |
1383 status = GetTreeStatus() | 1383 status = GetTreeStatus() |
1384 if 'closed' == status: | 1384 if 'closed' == status: |
1385 print('The tree is closed. Please wait for it to reopen. Use ' | 1385 print('The tree is closed. Please wait for it to reopen. Use ' |
1386 '"git cl dcommit --bypass-hooks" to commit on a closed tree.') | 1386 '"git cl dcommit --bypass-hooks" to commit on a closed tree.') |
1387 return 1 | 1387 return 1 |
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1883 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) | 1883 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) |
1884 | 1884 |
1885 # Not a known command. Default to help. | 1885 # Not a known command. Default to help. |
1886 GenUsage(parser, 'help') | 1886 GenUsage(parser, 'help') |
1887 return CMDhelp(parser, argv) | 1887 return CMDhelp(parser, argv) |
1888 | 1888 |
1889 | 1889 |
1890 if __name__ == '__main__': | 1890 if __name__ == '__main__': |
1891 fix_encoding.fix_encoding() | 1891 fix_encoding.fix_encoding() |
1892 sys.exit(main(sys.argv[1:])) | 1892 sys.exit(main(sys.argv[1:])) |
OLD | NEW |