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

Side by Side Diff: git_cl.py

Issue 896453002: Disallow applying patches when git tree is dirty (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 5 years, 10 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 | no next file » | no next file with comments »
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 2383 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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'])
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
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 if is_dirty_git_tree('diff'):
2777 return 1
iannucci 2015/02/02 15:49:42 Hm... why is this necessary?
wychen 2015/02/02 17:09:25 This is basically a safety measure. If the user ha
2778
2772 cl = Changelist() 2779 cl = Changelist()
2773 issue = cl.GetIssue() 2780 issue = cl.GetIssue()
2774 branch = cl.GetBranch() 2781 branch = cl.GetBranch()
2775 if not issue: 2782 if not issue:
2776 DieWithError('No issue found for current branch (%s)' % branch) 2783 DieWithError('No issue found for current branch (%s)' % branch)
2777 TMP_BRANCH = 'git-cl-diff' 2784 TMP_BRANCH = 'git-cl-diff'
2778 base_branch = cl.GetCommonAncestorWithUpstream() 2785 base_branch = cl.GetCommonAncestorWithUpstream()
2779 2786
2780 # Create a new branch based on the merge-base 2787 # Create a new branch based on the merge-base
2781 RunGit(['checkout', '-q', '-b', TMP_BRANCH, base_branch]) 2788 RunGit(['checkout', '-q', '-b', TMP_BRANCH, base_branch])
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
2974 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' 2981 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith '
2975 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) 2982 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e)))
2976 2983
2977 2984
2978 if __name__ == '__main__': 2985 if __name__ == '__main__':
2979 # These affect sys.stdout so do it outside of main() to simplify mocks in 2986 # These affect sys.stdout so do it outside of main() to simplify mocks in
2980 # unit testing. 2987 # unit testing.
2981 fix_encoding.fix_encoding() 2988 fix_encoding.fix_encoding()
2982 colorama.init() 2989 colorama.init()
2983 sys.exit(main(sys.argv[1:])) 2990 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698