Chromium Code Reviews| 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 940 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 951 print 'Description:', repr(description) | 951 print 'Description:', repr(description) |
| 952 | 952 |
| 953 branches = [base_branch, cl.GetBranchRef()] | 953 branches = [base_branch, cl.GetBranchRef()] |
| 954 if not options.force: | 954 if not options.force: |
| 955 subprocess.call(['git', 'diff', '--stat'] + branches) | 955 subprocess.call(['git', 'diff', '--stat'] + branches) |
| 956 raw_input("About to commit; enter to confirm.") | 956 raw_input("About to commit; enter to confirm.") |
| 957 | 957 |
| 958 # We want to squash all this branch's commits into one commit with the | 958 # We want to squash all this branch's commits into one commit with the |
| 959 # proper description. | 959 # proper description. |
| 960 # We do this by doing a "merge --squash" into a new commit branch, then | 960 # We do this by doing a "merge --squash" into a new commit branch, then |
| 961 # dcommitting that. | 961 # dcommitting that. |
|
evanm
2011/02/25 18:13:15
This comment needs to be updated.
Bernhard Bauer
2011/02/27 15:03:16
Done.
| |
| 962 MERGE_BRANCH = 'git-cl-commit' | 962 MERGE_BRANCH = 'git-cl-commit' |
| 963 # Delete the merge branch if it already exists. | 963 # Delete the merge branch if it already exists. |
| 964 if RunGitWithCode(['show-ref', '--quiet', '--verify', | 964 if RunGitWithCode(['show-ref', '--quiet', '--verify', |
| 965 'refs/heads/' + MERGE_BRANCH])[0] == 0: | 965 'refs/heads/' + MERGE_BRANCH])[0] == 0: |
| 966 RunGit(['branch', '-D', MERGE_BRANCH]) | 966 RunGit(['branch', '-D', MERGE_BRANCH]) |
| 967 | 967 |
| 968 # We might be in a directory that's present in this branch but not in the | 968 # We might be in a directory that's present in this branch but not in the |
| 969 # trunk. Move up to the top of the tree so that git commands that expect a | 969 # trunk. Move up to the top of the tree so that git commands that expect a |
| 970 # valid CWD won't fail after we check out the merge branch. | 970 # valid CWD won't fail after we check out the merge branch. |
| 971 rel_base_path = RunGit(['rev-parse', '--show-cdup']).strip() | 971 rel_base_path = RunGit(['rev-parse', '--show-cdup']).strip() |
| 972 if rel_base_path: | 972 if rel_base_path: |
| 973 os.chdir(rel_base_path) | 973 os.chdir(rel_base_path) |
| 974 | 974 |
| 975 # Stuff our change into the merge branch. | 975 # Stuff our change into the merge branch. |
| 976 # We wrap in a try...finally block so if anything goes wrong, | 976 # We wrap in a try...finally block so if anything goes wrong, |
| 977 # we clean up the branches. | 977 # we clean up the branches. |
| 978 retcode = -1 | 978 retcode = -1 |
| 979 try: | 979 try: |
| 980 RunGit(['checkout', '-q', '-b', MERGE_BRANCH, base_branch]) | 980 RunGit(['checkout', '-q', '-b', MERGE_BRANCH]) |
| 981 RunGit(['merge', '--squash', cl.GetBranchRef()]) | 981 RunGit(['reset', '--soft', base_branch]) |
| 982 if options.contributor: | 982 if options.contributor: |
| 983 RunGit(['commit', '--author', options.contributor, '-m', description]) | 983 RunGit(['commit', '--author', options.contributor, '-m', description]) |
| 984 else: | 984 else: |
| 985 RunGit(['commit', '-m', description]) | 985 RunGit(['commit', '-m', description]) |
| 986 if cmd == 'push': | 986 if cmd == 'push': |
| 987 # push the merge branch. | 987 # push the merge branch. |
| 988 remote, branch = cl.FetchUpstreamTuple() | 988 remote, branch = cl.FetchUpstreamTuple() |
| 989 retcode, output = RunGitWithCode( | 989 retcode, output = RunGitWithCode( |
| 990 ['push', '--porcelain', remote, 'HEAD:%s' % branch]) | 990 ['push', '--porcelain', remote, 'HEAD:%s' % branch]) |
| 991 logging.debug(output) | 991 logging.debug(output) |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1269 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' | 1269 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' |
| 1270 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) | 1270 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) |
| 1271 | 1271 |
| 1272 # Not a known command. Default to help. | 1272 # Not a known command. Default to help. |
| 1273 GenUsage(parser, 'help') | 1273 GenUsage(parser, 'help') |
| 1274 return CMDhelp(parser, argv) | 1274 return CMDhelp(parser, argv) |
| 1275 | 1275 |
| 1276 | 1276 |
| 1277 if __name__ == '__main__': | 1277 if __name__ == '__main__': |
| 1278 sys.exit(main(sys.argv[1:])) | 1278 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |