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 from distutils.version import LooseVersion | 10 from distutils.version import LooseVersion |
(...skipping 2383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2394 help='failed patches spew .rej files rather than ' | 2394 help='failed patches spew .rej files rather than ' |
2395 'attempting a 3-way merge') | 2395 'attempting a 3-way merge') |
2396 parser.add_option('-n', '--no-commit', action='store_true', dest='nocommit', | 2396 parser.add_option('-n', '--no-commit', action='store_true', dest='nocommit', |
2397 help="don't commit after patch applies") | 2397 help="don't commit after patch applies") |
2398 (options, args) = parser.parse_args(args) | 2398 (options, args) = parser.parse_args(args) |
2399 if len(args) != 1: | 2399 if len(args) != 1: |
2400 parser.print_help() | 2400 parser.print_help() |
2401 return 1 | 2401 return 1 |
2402 issue_arg = args[0] | 2402 issue_arg = args[0] |
2403 | 2403 |
2404 if is_dirty_git_tree('patch'): | |
2405 return 1 | |
2406 | |
2404 # TODO(maruel): Use apply_issue.py | 2407 # TODO(maruel): Use apply_issue.py |
2405 # TODO(ukai): use gerrit-cherry-pick for gerrit repository? | 2408 # TODO(ukai): use gerrit-cherry-pick for gerrit repository? |
2406 | 2409 |
2407 if options.newbranch: | 2410 if options.newbranch: |
2408 if options.force: | 2411 if options.force: |
2409 RunGit(['branch', '-D', options.newbranch], | 2412 RunGit(['branch', '-D', options.newbranch], |
2410 stderr=subprocess2.PIPE, error_ok=True) | 2413 stderr=subprocess2.PIPE, error_ok=True) |
2411 RunGit(['checkout', '-b', options.newbranch, | 2414 RunGit(['checkout', '-b', options.newbranch, |
2412 Changelist().GetUpstreamBranch()]) | 2415 Changelist().GetUpstreamBranch()]) |
2413 | 2416 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2457 if directory: | 2460 if directory: |
2458 cmd.extend(('--directory', directory)) | 2461 cmd.extend(('--directory', directory)) |
2459 if reject: | 2462 if reject: |
2460 cmd.append('--reject') | 2463 cmd.append('--reject') |
2461 elif IsGitVersionAtLeast('1.7.12'): | 2464 elif IsGitVersionAtLeast('1.7.12'): |
2462 cmd.append('--3way') | 2465 cmd.append('--3way') |
2463 try: | 2466 try: |
2464 subprocess2.check_call(cmd, env=GetNoGitPagerEnv(), | 2467 subprocess2.check_call(cmd, env=GetNoGitPagerEnv(), |
2465 stdin=patch_data, stdout=subprocess2.VOID) | 2468 stdin=patch_data, stdout=subprocess2.VOID) |
2466 except subprocess2.CalledProcessError: | 2469 except subprocess2.CalledProcessError: |
2470 RunGit(['reset', '--hard']) | |
Sam Clegg
2015/02/02 17:43:18
I find this a little scary. Perhaps skip this and
wychen
2015/02/03 02:33:44
Done.
| |
2467 DieWithError('Failed to apply the patch') | 2471 DieWithError('Failed to apply the patch') |
2468 | 2472 |
2469 # If we had an issue, commit the current state and register the issue. | 2473 # If we had an issue, commit the current state and register the issue. |
2470 if not nocommit: | 2474 if not nocommit: |
2471 RunGit(['commit', '-m', ('patch from issue %(i)s at patchset ' | 2475 RunGit(['commit', '-m', ('patch from issue %(i)s at patchset ' |
2472 '%(p)s (http://crrev.com/%(i)s#ps%(p)s)' | 2476 '%(p)s (http://crrev.com/%(i)s#ps%(p)s)' |
2473 % {'i': issue, 'p': patchset})]) | 2477 % {'i': issue, 'p': patchset})]) |
2474 cl = Changelist() | 2478 cl = Changelist() |
2475 cl.SetIssue(issue) | 2479 cl.SetIssue(issue) |
2476 cl.SetPatchset(patchset) | 2480 cl.SetPatchset(patchset) |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2762 parser.error('Unrecognized args: %s' % ' '.join(args)) | 2766 parser.error('Unrecognized args: %s' % ' '.join(args)) |
2763 cl = Changelist() | 2767 cl = Changelist() |
2764 # Ensure there actually is an issue to close. | 2768 # Ensure there actually is an issue to close. |
2765 cl.GetDescription() | 2769 cl.GetDescription() |
2766 cl.CloseIssue() | 2770 cl.CloseIssue() |
2767 return 0 | 2771 return 0 |
2768 | 2772 |
2769 | 2773 |
2770 def CMDdiff(parser, args): | 2774 def CMDdiff(parser, args): |
2771 """shows differences between local tree and last upload.""" | 2775 """shows differences between local tree and last upload.""" |
2776 | |
2777 # Uncommitted (staged and unstaged) changes will be destroyed by | |
2778 # "git reset --hard" if there are merging conflicts in PatchIssue(). | |
2779 # Staged changes would be committed along with the patch from last | |
2780 # upload, hence counted toward the "last upload" side in the final | |
2781 # diff output, and this is not what we want. | |
2782 if is_dirty_git_tree('diff'): | |
2783 return 1 | |
2784 | |
2772 cl = Changelist() | 2785 cl = Changelist() |
2773 issue = cl.GetIssue() | 2786 issue = cl.GetIssue() |
2774 branch = cl.GetBranch() | 2787 branch = cl.GetBranch() |
2775 if not issue: | 2788 if not issue: |
2776 DieWithError('No issue found for current branch (%s)' % branch) | 2789 DieWithError('No issue found for current branch (%s)' % branch) |
2777 TMP_BRANCH = 'git-cl-diff' | 2790 TMP_BRANCH = 'git-cl-diff' |
2778 base_branch = cl.GetCommonAncestorWithUpstream() | 2791 base_branch = cl.GetCommonAncestorWithUpstream() |
2779 | 2792 |
2780 # Create a new branch based on the merge-base | 2793 # Create a new branch based on the merge-base |
2781 RunGit(['checkout', '-q', '-b', TMP_BRANCH, base_branch]) | 2794 RunGit(['checkout', '-q', '-b', TMP_BRANCH, base_branch]) |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2974 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' | 2987 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' |
2975 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) | 2988 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) |
2976 | 2989 |
2977 | 2990 |
2978 if __name__ == '__main__': | 2991 if __name__ == '__main__': |
2979 # These affect sys.stdout so do it outside of main() to simplify mocks in | 2992 # These affect sys.stdout so do it outside of main() to simplify mocks in |
2980 # unit testing. | 2993 # unit testing. |
2981 fix_encoding.fix_encoding() | 2994 fix_encoding.fix_encoding() |
2982 colorama.init() | 2995 colorama.init() |
2983 sys.exit(main(sys.argv[1:])) | 2996 sys.exit(main(sys.argv[1:])) |
OLD | NEW |