OLD | NEW |
---|---|
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # git-cl -- a git-command for integrating reviews on Rietveld | 2 # git-cl -- a git-command for integrating reviews on Rietveld |
3 # Copyright (C) 2008 Evan Martin <martine@danga.com> | 3 # Copyright (C) 2008 Evan Martin <martine@danga.com> |
4 | 4 |
5 import errno | 5 import errno |
6 import logging | 6 import logging |
7 import optparse | 7 import optparse |
8 import os | 8 import os |
9 import re | 9 import re |
10 import subprocess | 10 import subprocess |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
210 self.tree_status_url = self._GetConfig('rietveld.tree-status-url', | 210 self.tree_status_url = self._GetConfig('rietveld.tree-status-url', |
211 error_ok=error_ok, | 211 error_ok=error_ok, |
212 error_message=error_message) | 212 error_message=error_message) |
213 return self.tree_status_url | 213 return self.tree_status_url |
214 | 214 |
215 def GetViewVCUrl(self): | 215 def GetViewVCUrl(self): |
216 if not self.viewvc_url: | 216 if not self.viewvc_url: |
217 self.viewvc_url = self._GetConfig('rietveld.viewvc-url', error_ok=True) | 217 self.viewvc_url = self._GetConfig('rietveld.viewvc-url', error_ok=True) |
218 return self.viewvc_url | 218 return self.viewvc_url |
219 | 219 |
220 def GetRenamedBranch(self, cmd, branch): | |
221 rename = self._GetConfig('rietveld.rename-after-%s' % cmd, | |
222 error_ok=True) | |
M-A Ruel
2010/12/22 20:28:21
align either at ( or at +4 from previous line.
sadrul
2010/12/22 20:39:50
Done.
| |
223 if rename: | |
224 rename = rename.replace('%s', branch) | |
225 return rename | |
226 | |
220 def _GetConfig(self, param, **kwargs): | 227 def _GetConfig(self, param, **kwargs): |
221 self.LazyUpdateIfNeeded() | 228 self.LazyUpdateIfNeeded() |
222 return RunGit(['config', param], **kwargs).strip() | 229 return RunGit(['config', param], **kwargs).strip() |
223 | 230 |
224 | 231 |
225 settings = Settings() | 232 settings = Settings() |
226 | 233 |
227 | 234 |
228 did_migrate_check = False | 235 did_migrate_check = False |
229 def CheckForMigration(): | 236 def CheckForMigration(): |
(...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
964 # We might be in a directory that's present in this branch but not in the | 971 # We might be in a directory that's present in this branch but not in the |
965 # trunk. Move up to the top of the tree so that git commands that expect a | 972 # trunk. Move up to the top of the tree so that git commands that expect a |
966 # valid CWD won't fail after we check out the merge branch. | 973 # valid CWD won't fail after we check out the merge branch. |
967 rel_base_path = RunGit(['rev-parse', '--show-cdup']).strip() | 974 rel_base_path = RunGit(['rev-parse', '--show-cdup']).strip() |
968 if rel_base_path: | 975 if rel_base_path: |
969 os.chdir(rel_base_path) | 976 os.chdir(rel_base_path) |
970 | 977 |
971 # Stuff our change into the merge branch. | 978 # Stuff our change into the merge branch. |
972 # We wrap in a try...finally block so if anything goes wrong, | 979 # We wrap in a try...finally block so if anything goes wrong, |
973 # we clean up the branches. | 980 # we clean up the branches. |
981 success = False | |
M-A Ruel
2010/12/22 20:28:21
You could use instead;
retcode = 0
and check for
sadrul
2010/12/22 20:39:50
I set retcode = 1 here so that the branch doesn't
| |
974 try: | 982 try: |
975 RunGit(['checkout', '-q', '-b', MERGE_BRANCH, base_branch]) | 983 RunGit(['checkout', '-q', '-b', MERGE_BRANCH, base_branch]) |
976 RunGit(['merge', '--squash', cl.GetBranchRef()]) | 984 RunGit(['merge', '--squash', cl.GetBranchRef()]) |
977 if options.contributor: | 985 if options.contributor: |
978 RunGit(['commit', '--author', options.contributor, '-m', description]) | 986 RunGit(['commit', '--author', options.contributor, '-m', description]) |
979 else: | 987 else: |
980 RunGit(['commit', '-m', description]) | 988 RunGit(['commit', '-m', description]) |
981 if cmd == 'push': | 989 if cmd == 'push': |
982 # push the merge branch. | 990 # push the merge branch. |
983 remote, branch = cl.FetchUpstreamTuple() | 991 remote, branch = cl.FetchUpstreamTuple() |
984 retcode, output = RunGitWithCode( | 992 retcode, output = RunGitWithCode( |
985 ['push', '--porcelain', remote, 'HEAD:%s' % branch]) | 993 ['push', '--porcelain', remote, 'HEAD:%s' % branch]) |
994 success = True | |
986 logging.debug(output) | 995 logging.debug(output) |
987 else: | 996 else: |
988 # dcommit the merge branch. | 997 # dcommit the merge branch. |
989 output = RunGit(['svn', 'dcommit', '--no-rebase']) | 998 output = RunGit(['svn', 'dcommit', '--no-rebase']) |
999 success = True | |
1000 | |
990 finally: | 1001 finally: |
991 # And then swap back to the original branch and clean up. | 1002 # And then swap back to the original branch and clean up. |
992 RunGit(['checkout', '-q', cl.GetBranch()]) | 1003 RunGit(['checkout', '-q', cl.GetBranch()]) |
993 RunGit(['branch', '-D', MERGE_BRANCH]) | 1004 RunGit(['branch', '-D', MERGE_BRANCH]) |
994 | 1005 |
1006 if success: | |
1007 rename = settings.GetRenamedBranch(cmd, cl.GetBranch()) | |
1008 if rename: | |
1009 RunGit(['branch', '-m', cl.GetBranch(), rename]) | |
1010 | |
995 if cl.GetIssue(): | 1011 if cl.GetIssue(): |
996 if cmd == 'dcommit' and 'Committed r' in output: | 1012 if cmd == 'dcommit' and 'Committed r' in output: |
997 revision = re.match('.*?\nCommitted r(\\d+)', output, re.DOTALL).group(1) | 1013 revision = re.match('.*?\nCommitted r(\\d+)', output, re.DOTALL).group(1) |
998 elif cmd == 'push' and retcode == 0: | 1014 elif cmd == 'push' and retcode == 0: |
999 revision = output.splitlines()[1].split('\t')[2].split('..')[1] | 1015 revision = output.splitlines()[1].split('\t')[2].split('..')[1] |
1000 else: | 1016 else: |
1001 return 1 | 1017 return 1 |
1002 viewvc_url = settings.GetViewVCUrl() | 1018 viewvc_url = settings.GetViewVCUrl() |
1003 if viewvc_url and revision: | 1019 if viewvc_url and revision: |
1004 cl.description += ('\n\nCommitted: ' + viewvc_url + revision) | 1020 cl.description += ('\n\nCommitted: ' + viewvc_url + revision) |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1245 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' | 1261 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' |
1246 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) | 1262 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) |
1247 | 1263 |
1248 # Not a known command. Default to help. | 1264 # Not a known command. Default to help. |
1249 GenUsage(parser, 'help') | 1265 GenUsage(parser, 'help') |
1250 return CMDhelp(parser, argv) | 1266 return CMDhelp(parser, argv) |
1251 | 1267 |
1252 | 1268 |
1253 if __name__ == '__main__': | 1269 if __name__ == '__main__': |
1254 sys.exit(main(sys.argv[1:])) | 1270 sys.exit(main(sys.argv[1:])) |
OLD | NEW |