| 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 2565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2576 RunGit(['branch', '-D', options.newbranch], | 2576 RunGit(['branch', '-D', options.newbranch], |
| 2577 stderr=subprocess2.PIPE, error_ok=True) | 2577 stderr=subprocess2.PIPE, error_ok=True) |
| 2578 RunGit(['checkout', '-b', options.newbranch, | 2578 RunGit(['checkout', '-b', options.newbranch, |
| 2579 Changelist().GetUpstreamBranch()]) | 2579 Changelist().GetUpstreamBranch()]) |
| 2580 | 2580 |
| 2581 return PatchIssue(issue_arg, options.reject, options.nocommit, | 2581 return PatchIssue(issue_arg, options.reject, options.nocommit, |
| 2582 options.directory, auth_config) | 2582 options.directory, auth_config) |
| 2583 | 2583 |
| 2584 | 2584 |
| 2585 def PatchIssue(issue_arg, reject, nocommit, directory, auth_config): | 2585 def PatchIssue(issue_arg, reject, nocommit, directory, auth_config): |
| 2586 # There's a "reset --hard" when failing to apply the patch. In order | 2586 # PatchIssue should never be called with a dirty tree. It is up to the |
| 2587 # not to destroy users' data, make sure the tree is not dirty here. | 2587 # caller to check this, but just in case we assert here since the |
| 2588 # consequences of the caller not checking this could be dire. |
| 2588 assert(not git_common.is_dirty_git_tree('apply')) | 2589 assert(not git_common.is_dirty_git_tree('apply')) |
| 2589 | 2590 |
| 2590 if type(issue_arg) is int or issue_arg.isdigit(): | 2591 if type(issue_arg) is int or issue_arg.isdigit(): |
| 2591 # Input is an issue id. Figure out the URL. | 2592 # Input is an issue id. Figure out the URL. |
| 2592 issue = int(issue_arg) | 2593 issue = int(issue_arg) |
| 2593 cl = Changelist(issue=issue, auth_config=auth_config) | 2594 cl = Changelist(issue=issue, auth_config=auth_config) |
| 2594 patchset = cl.GetMostRecentPatchset() | 2595 patchset = cl.GetMostRecentPatchset() |
| 2595 patch_data = cl.GetPatchSetDiff(issue, patchset) | 2596 patch_data = cl.GetPatchSetDiff(issue, patchset) |
| 2596 else: | 2597 else: |
| 2597 # Assume it's a URL to the patch. Default to https. | 2598 # Assume it's a URL to the patch. Default to https. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 2628 if directory: | 2629 if directory: |
| 2629 cmd.extend(('--directory', directory)) | 2630 cmd.extend(('--directory', directory)) |
| 2630 if reject: | 2631 if reject: |
| 2631 cmd.append('--reject') | 2632 cmd.append('--reject') |
| 2632 elif IsGitVersionAtLeast('1.7.12'): | 2633 elif IsGitVersionAtLeast('1.7.12'): |
| 2633 cmd.append('--3way') | 2634 cmd.append('--3way') |
| 2634 try: | 2635 try: |
| 2635 subprocess2.check_call(cmd, env=GetNoGitPagerEnv(), | 2636 subprocess2.check_call(cmd, env=GetNoGitPagerEnv(), |
| 2636 stdin=patch_data, stdout=subprocess2.VOID) | 2637 stdin=patch_data, stdout=subprocess2.VOID) |
| 2637 except subprocess2.CalledProcessError: | 2638 except subprocess2.CalledProcessError: |
| 2638 RunGit(['reset', '--hard']) | 2639 print 'Failed to apply the patch' |
| 2639 DieWithError('Failed to apply the patch') | 2640 return 1 |
| 2640 | 2641 |
| 2641 # If we had an issue, commit the current state and register the issue. | 2642 # If we had an issue, commit the current state and register the issue. |
| 2642 if not nocommit: | 2643 if not nocommit: |
| 2643 RunGit(['commit', '-m', ('patch from issue %(i)s at patchset ' | 2644 RunGit(['commit', '-m', ('patch from issue %(i)s at patchset ' |
| 2644 '%(p)s (http://crrev.com/%(i)s#ps%(p)s)' | 2645 '%(p)s (http://crrev.com/%(i)s#ps%(p)s)' |
| 2645 % {'i': issue, 'p': patchset})]) | 2646 % {'i': issue, 'p': patchset})]) |
| 2646 cl = Changelist(auth_config=auth_config) | 2647 cl = Changelist(auth_config=auth_config) |
| 2647 cl.SetIssue(issue) | 2648 cl.SetIssue(issue) |
| 2648 cl.SetPatchset(patchset) | 2649 cl.SetPatchset(patchset) |
| 2649 print "Committed patch locally." | 2650 print "Committed patch locally." |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2968 DieWithError('No issue found for current branch (%s)' % branch) | 2969 DieWithError('No issue found for current branch (%s)' % branch) |
| 2969 TMP_BRANCH = 'git-cl-diff' | 2970 TMP_BRANCH = 'git-cl-diff' |
| 2970 base_branch = cl.GetCommonAncestorWithUpstream() | 2971 base_branch = cl.GetCommonAncestorWithUpstream() |
| 2971 | 2972 |
| 2972 # Create a new branch based on the merge-base | 2973 # Create a new branch based on the merge-base |
| 2973 RunGit(['checkout', '-q', '-b', TMP_BRANCH, base_branch]) | 2974 RunGit(['checkout', '-q', '-b', TMP_BRANCH, base_branch]) |
| 2974 try: | 2975 try: |
| 2975 # Patch in the latest changes from rietveld. | 2976 # Patch in the latest changes from rietveld. |
| 2976 rtn = PatchIssue(issue, False, False, None, auth_config) | 2977 rtn = PatchIssue(issue, False, False, None, auth_config) |
| 2977 if rtn != 0: | 2978 if rtn != 0: |
| 2979 RunGit(['reset', '--hard']) |
| 2978 return rtn | 2980 return rtn |
| 2979 | 2981 |
| 2980 # Switch back to starting branch and diff against the temporary | 2982 # Switch back to starting branch and diff against the temporary |
| 2981 # branch containing the latest rietveld patch. | 2983 # branch containing the latest rietveld patch. |
| 2982 subprocess2.check_call(['git', 'diff', TMP_BRANCH, branch, '--']) | 2984 subprocess2.check_call(['git', 'diff', TMP_BRANCH, branch, '--']) |
| 2983 finally: | 2985 finally: |
| 2984 RunGit(['checkout', '-q', branch]) | 2986 RunGit(['checkout', '-q', branch]) |
| 2985 RunGit(['branch', '-D', TMP_BRANCH]) | 2987 RunGit(['branch', '-D', TMP_BRANCH]) |
| 2986 | 2988 |
| 2987 return 0 | 2989 return 0 |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3202 if __name__ == '__main__': | 3204 if __name__ == '__main__': |
| 3203 # These affect sys.stdout so do it outside of main() to simplify mocks in | 3205 # These affect sys.stdout so do it outside of main() to simplify mocks in |
| 3204 # unit testing. | 3206 # unit testing. |
| 3205 fix_encoding.fix_encoding() | 3207 fix_encoding.fix_encoding() |
| 3206 colorama.init() | 3208 colorama.init() |
| 3207 try: | 3209 try: |
| 3208 sys.exit(main(sys.argv[1:])) | 3210 sys.exit(main(sys.argv[1:])) |
| 3209 except KeyboardInterrupt: | 3211 except KeyboardInterrupt: |
| 3210 sys.stderr.write('interrupted\n') | 3212 sys.stderr.write('interrupted\n') |
| 3211 sys.exit(1) | 3213 sys.exit(1) |
| OLD | NEW |