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 942 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
953 description += "\nPatch from %s." % options.contributor | 953 description += "\nPatch from %s." % options.contributor |
954 print 'Description:', repr(description) | 954 print 'Description:', repr(description) |
955 | 955 |
956 branches = [base_branch, cl.GetBranchRef()] | 956 branches = [base_branch, cl.GetBranchRef()] |
957 if not options.force: | 957 if not options.force: |
958 subprocess.call(['git', 'diff', '--stat'] + branches) | 958 subprocess.call(['git', 'diff', '--stat'] + branches) |
959 raw_input("About to commit; enter to confirm.") | 959 raw_input("About to commit; enter to confirm.") |
960 | 960 |
961 # We want to squash all this branch's commits into one commit with the | 961 # We want to squash all this branch's commits into one commit with the |
962 # proper description. | 962 # proper description. |
963 # We do this by doing a "merge --squash" into a new commit branch, then | 963 # We do this by doing a "reset --soft" to the base branch (which keeps |
964 # dcommitting that. | 964 # the working copy the same), then dcommitting that. |
965 MERGE_BRANCH = 'git-cl-commit' | 965 MERGE_BRANCH = 'git-cl-commit' |
966 # Delete the merge branch if it already exists. | 966 # Delete the merge branch if it already exists. |
967 if RunGitWithCode(['show-ref', '--quiet', '--verify', | 967 if RunGitWithCode(['show-ref', '--quiet', '--verify', |
968 'refs/heads/' + MERGE_BRANCH])[0] == 0: | 968 'refs/heads/' + MERGE_BRANCH])[0] == 0: |
969 RunGit(['branch', '-D', MERGE_BRANCH]) | 969 RunGit(['branch', '-D', MERGE_BRANCH]) |
970 | 970 |
971 # 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 |
972 # 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 |
973 # 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. |
974 rel_base_path = RunGit(['rev-parse', '--show-cdup']).strip() | 974 rel_base_path = RunGit(['rev-parse', '--show-cdup']).strip() |
975 if rel_base_path: | 975 if rel_base_path: |
976 os.chdir(rel_base_path) | 976 os.chdir(rel_base_path) |
977 | 977 |
978 # Stuff our change into the merge branch. | 978 # Stuff our change into the merge branch. |
979 # 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, |
980 # we clean up the branches. | 980 # we clean up the branches. |
981 retcode = -1 | 981 retcode = -1 |
982 try: | 982 try: |
983 RunGit(['checkout', '-q', '-b', MERGE_BRANCH, base_branch]) | 983 RunGit(['checkout', '-q', '-b', MERGE_BRANCH]) |
984 RunGit(['merge', '--squash', cl.GetBranchRef()]) | 984 RunGit(['reset', '--soft', base_branch]) |
985 if options.contributor: | 985 if options.contributor: |
986 RunGit(['commit', '--author', options.contributor, '-m', description]) | 986 RunGit(['commit', '--author', options.contributor, '-m', description]) |
987 else: | 987 else: |
988 RunGit(['commit', '-m', description]) | 988 RunGit(['commit', '-m', description]) |
989 if cmd == 'push': | 989 if cmd == 'push': |
990 # push the merge branch. | 990 # push the merge branch. |
991 remote, branch = cl.FetchUpstreamTuple() | 991 remote, branch = cl.FetchUpstreamTuple() |
992 retcode, output = RunGitWithCode( | 992 retcode, output = RunGitWithCode( |
993 ['push', '--porcelain', remote, 'HEAD:%s' % branch]) | 993 ['push', '--porcelain', remote, 'HEAD:%s' % branch]) |
994 logging.debug(output) | 994 logging.debug(output) |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1272 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' | 1272 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' |
1273 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) | 1273 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) |
1274 | 1274 |
1275 # Not a known command. Default to help. | 1275 # Not a known command. Default to help. |
1276 GenUsage(parser, 'help') | 1276 GenUsage(parser, 'help') |
1277 return CMDhelp(parser, argv) | 1277 return CMDhelp(parser, argv) |
1278 | 1278 |
1279 | 1279 |
1280 if __name__ == '__main__': | 1280 if __name__ == '__main__': |
1281 sys.exit(main(sys.argv[1:])) | 1281 sys.exit(main(sys.argv[1:])) |
OLD | NEW |