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 21 matching lines...) Expand all Loading... |
32 import rietveld | 32 import rietveld |
33 import scm | 33 import scm |
34 import subprocess2 | 34 import subprocess2 |
35 import watchlists | 35 import watchlists |
36 | 36 |
37 | 37 |
38 DEFAULT_SERVER = 'https://codereview.appspot.com' | 38 DEFAULT_SERVER = 'https://codereview.appspot.com' |
39 POSTUPSTREAM_HOOK_PATTERN = '.git/hooks/post-cl-%s' | 39 POSTUPSTREAM_HOOK_PATTERN = '.git/hooks/post-cl-%s' |
40 DESCRIPTION_BACKUP_FILE = '~/.git_cl_description_backup' | 40 DESCRIPTION_BACKUP_FILE = '~/.git_cl_description_backup' |
41 GIT_INSTRUCTIONS_URL = 'http://code.google.com/p/chromium/wiki/UsingNewGit' | 41 GIT_INSTRUCTIONS_URL = 'http://code.google.com/p/chromium/wiki/UsingNewGit' |
| 42 CHANGE_ID_STR = 'Change-Id:' |
42 | 43 |
43 | 44 |
44 # Initialized in main() | 45 # Initialized in main() |
45 settings = None | 46 settings = None |
46 | 47 |
47 | 48 |
48 def DieWithError(message): | 49 def DieWithError(message): |
49 print >> sys.stderr, message | 50 print >> sys.stderr, message |
50 sys.exit(1) | 51 sys.exit(1) |
51 | 52 |
(...skipping 928 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
980 base_branch = args[0] | 981 base_branch = args[0] |
981 else: | 982 else: |
982 # Default to diffing against the "upstream" branch. | 983 # Default to diffing against the "upstream" branch. |
983 base_branch = cl.GetUpstreamBranch() | 984 base_branch = cl.GetUpstreamBranch() |
984 | 985 |
985 cl.RunHook(committing=not options.upload, upstream_branch=base_branch, | 986 cl.RunHook(committing=not options.upload, upstream_branch=base_branch, |
986 may_prompt=False, verbose=options.verbose, | 987 may_prompt=False, verbose=options.verbose, |
987 author=None) | 988 author=None) |
988 return 0 | 989 return 0 |
989 | 990 |
| 991 def AddChangeIdToCommitMessage(message): |
| 992 git_command = ['commit', '-a', '--amend', '-m %s' % message] |
| 993 RunGit(git_command) |
| 994 print "git-cl: Added Change-Id to commit message." |
990 | 995 |
991 def GerritUpload(options, args, cl): | 996 def GerritUpload(options, args, cl): |
992 """upload the current branch to gerrit.""" | 997 """upload the current branch to gerrit.""" |
993 # We assume the remote called "origin" is the one we want. | 998 # We assume the remote called "origin" is the one we want. |
994 # It is probably not worthwhile to support different workflows. | 999 # It is probably not worthwhile to support different workflows. |
995 remote = 'origin' | 1000 remote = 'origin' |
996 branch = 'master' | 1001 branch = 'master' |
997 if options.target_branch: | 1002 if options.target_branch: |
998 branch = options.target_branch | 1003 branch = options.target_branch |
999 | 1004 |
1000 log_desc = options.message or CreateDescriptionFromLog(args) | 1005 log_desc = options.message or CreateDescriptionFromLog(args) |
| 1006 if not re.search(CHANGE_ID_STR, log_desc): |
| 1007 AddChangeIdToCommitMessage(log_desc) |
1001 if options.reviewers: | 1008 if options.reviewers: |
1002 log_desc += '\nR=' + options.reviewers | 1009 log_desc += '\nR=' + options.reviewers |
1003 change_desc = ChangeDescription(log_desc, options.reviewers) | 1010 change_desc = ChangeDescription(log_desc, options.reviewers) |
1004 change_desc.ParseDescription() | 1011 change_desc.ParseDescription() |
1005 if change_desc.IsEmpty(): | 1012 if change_desc.IsEmpty(): |
1006 print "Description is empty; aborting." | 1013 print "Description is empty; aborting." |
1007 return 1 | 1014 return 1 |
1008 | 1015 |
1009 receive_options = [] | 1016 receive_options = [] |
1010 cc = cl.GetCCList().split(',') | 1017 cc = cl.GetCCList().split(',') |
(...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1758 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) | 1765 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) |
1759 | 1766 |
1760 # Not a known command. Default to help. | 1767 # Not a known command. Default to help. |
1761 GenUsage(parser, 'help') | 1768 GenUsage(parser, 'help') |
1762 return CMDhelp(parser, argv) | 1769 return CMDhelp(parser, argv) |
1763 | 1770 |
1764 | 1771 |
1765 if __name__ == '__main__': | 1772 if __name__ == '__main__': |
1766 fix_encoding.fix_encoding() | 1773 fix_encoding.fix_encoding() |
1767 sys.exit(main(sys.argv[1:])) | 1774 sys.exit(main(sys.argv[1:])) |
OLD | NEW |