Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(463)

Side by Side Diff: git_cl.py

Issue 1091283004: Don't clean up after conflict in "git cl patch" (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tests/git_cl_test.py » ('j') | tests/git_cl_test.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 # When a patch fails to apply, it mixes with local changes. In order
2587 # not to destroy users' data, make sure the tree is not dirty here. 2587 # not to destroy users' data, make sure the tree is not dirty here.
Sam Clegg 2015/04/20 23:32:16 How about: PatchIssue should never be called with
wychen 2015/04/22 00:23:18 Done.
2588 assert(not git_common.is_dirty_git_tree('apply')) 2588 assert(not git_common.is_dirty_git_tree('apply'))
2589 2589
2590 if type(issue_arg) is int or issue_arg.isdigit(): 2590 if type(issue_arg) is int or issue_arg.isdigit():
2591 # Input is an issue id. Figure out the URL. 2591 # Input is an issue id. Figure out the URL.
2592 issue = int(issue_arg) 2592 issue = int(issue_arg)
2593 cl = Changelist(issue=issue, auth_config=auth_config) 2593 cl = Changelist(issue=issue, auth_config=auth_config)
2594 patchset = cl.GetMostRecentPatchset() 2594 patchset = cl.GetMostRecentPatchset()
2595 patch_data = cl.GetPatchSetDiff(issue, patchset) 2595 patch_data = cl.GetPatchSetDiff(issue, patchset)
2596 else: 2596 else:
2597 # Assume it's a URL to the patch. Default to https. 2597 # Assume it's a URL to the patch. Default to https.
(...skipping 30 matching lines...) Expand all
2628 if directory: 2628 if directory:
2629 cmd.extend(('--directory', directory)) 2629 cmd.extend(('--directory', directory))
2630 if reject: 2630 if reject:
2631 cmd.append('--reject') 2631 cmd.append('--reject')
2632 elif IsGitVersionAtLeast('1.7.12'): 2632 elif IsGitVersionAtLeast('1.7.12'):
2633 cmd.append('--3way') 2633 cmd.append('--3way')
2634 try: 2634 try:
2635 subprocess2.check_call(cmd, env=GetNoGitPagerEnv(), 2635 subprocess2.check_call(cmd, env=GetNoGitPagerEnv(),
2636 stdin=patch_data, stdout=subprocess2.VOID) 2636 stdin=patch_data, stdout=subprocess2.VOID)
2637 except subprocess2.CalledProcessError: 2637 except subprocess2.CalledProcessError:
2638 RunGit(['reset', '--hard']) 2638 print 'Failed to apply the patch'
2639 DieWithError('Failed to apply the patch') 2639 return 1
2640 2640
2641 # If we had an issue, commit the current state and register the issue. 2641 # If we had an issue, commit the current state and register the issue.
2642 if not nocommit: 2642 if not nocommit:
2643 RunGit(['commit', '-m', ('patch from issue %(i)s at patchset ' 2643 RunGit(['commit', '-m', ('patch from issue %(i)s at patchset '
2644 '%(p)s (http://crrev.com/%(i)s#ps%(p)s)' 2644 '%(p)s (http://crrev.com/%(i)s#ps%(p)s)'
2645 % {'i': issue, 'p': patchset})]) 2645 % {'i': issue, 'p': patchset})])
2646 cl = Changelist(auth_config=auth_config) 2646 cl = Changelist(auth_config=auth_config)
2647 cl.SetIssue(issue) 2647 cl.SetIssue(issue)
2648 cl.SetPatchset(patchset) 2648 cl.SetPatchset(patchset)
2649 print "Committed patch locally." 2649 print "Committed patch locally."
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
2968 DieWithError('No issue found for current branch (%s)' % branch) 2968 DieWithError('No issue found for current branch (%s)' % branch)
2969 TMP_BRANCH = 'git-cl-diff' 2969 TMP_BRANCH = 'git-cl-diff'
2970 base_branch = cl.GetCommonAncestorWithUpstream() 2970 base_branch = cl.GetCommonAncestorWithUpstream()
2971 2971
2972 # Create a new branch based on the merge-base 2972 # Create a new branch based on the merge-base
2973 RunGit(['checkout', '-q', '-b', TMP_BRANCH, base_branch]) 2973 RunGit(['checkout', '-q', '-b', TMP_BRANCH, base_branch])
2974 try: 2974 try:
2975 # Patch in the latest changes from rietveld. 2975 # Patch in the latest changes from rietveld.
2976 rtn = PatchIssue(issue, False, False, None, auth_config) 2976 rtn = PatchIssue(issue, False, False, None, auth_config)
2977 if rtn != 0: 2977 if rtn != 0:
2978 RunGit(['reset', '--hard'])
2978 return rtn 2979 return rtn
2979 2980
2980 # Switch back to starting branch and diff against the temporary 2981 # Switch back to starting branch and diff against the temporary
2981 # branch containing the latest rietveld patch. 2982 # branch containing the latest rietveld patch.
2982 subprocess2.check_call(['git', 'diff', TMP_BRANCH, branch, '--']) 2983 subprocess2.check_call(['git', 'diff', TMP_BRANCH, branch, '--'])
2983 finally: 2984 finally:
2984 RunGit(['checkout', '-q', branch]) 2985 RunGit(['checkout', '-q', branch])
2985 RunGit(['branch', '-D', TMP_BRANCH]) 2986 RunGit(['branch', '-D', TMP_BRANCH])
2986 2987
2987 return 0 2988 return 0
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
3202 if __name__ == '__main__': 3203 if __name__ == '__main__':
3203 # These affect sys.stdout so do it outside of main() to simplify mocks in 3204 # These affect sys.stdout so do it outside of main() to simplify mocks in
3204 # unit testing. 3205 # unit testing.
3205 fix_encoding.fix_encoding() 3206 fix_encoding.fix_encoding()
3206 colorama.init() 3207 colorama.init()
3207 try: 3208 try:
3208 sys.exit(main(sys.argv[1:])) 3209 sys.exit(main(sys.argv[1:]))
3209 except KeyboardInterrupt: 3210 except KeyboardInterrupt:
3210 sys.stderr.write('interrupted\n') 3211 sys.stderr.write('interrupted\n')
3211 sys.exit(1) 3212 sys.exit(1)
OLDNEW
« no previous file with comments | « no previous file | tests/git_cl_test.py » ('j') | tests/git_cl_test.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698