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

Unified 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: rebase Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: git_cl.py
diff --git a/git_cl.py b/git_cl.py
index 95bf695e4e811b3d7758149fc2b38671f9a103a5..6470575fd188246b74f42294f07e88234d75a021 100755
--- a/git_cl.py
+++ b/git_cl.py
@@ -2531,6 +2531,10 @@ def CMDpatch(parser, args):
return 1
issue_arg = args[0]
+ # We don't want uncommitted changes mixed up with the patch.
+ if is_dirty_git_tree('patch'):
+ return 1
+
# TODO(maruel): Use apply_issue.py
# TODO(ukai): use gerrit-cherry-pick for gerrit repository?
@@ -2546,6 +2550,10 @@ def CMDpatch(parser, args):
def PatchIssue(issue_arg, reject, nocommit, directory):
+ # There's a "reset --hard" when failing to apply the patch. In order
+ # not to destroy users' data, make sure the tree is not dirty here.
+ assert(not is_dirty_git_tree('apply'))
+
if type(issue_arg) is int or issue_arg.isdigit():
# Input is an issue id. Figure out the URL.
issue = int(issue_arg)
@@ -2594,6 +2602,7 @@ def PatchIssue(issue_arg, reject, nocommit, directory):
subprocess2.check_call(cmd, env=GetNoGitPagerEnv(),
stdin=patch_data, stdout=subprocess2.VOID)
except subprocess2.CalledProcessError:
+ RunGit(['reset', '--hard'])
yoichio 2015/04/27 07:52:31 This resets working tree. Why? I prefer the state
DieWithError('Failed to apply the patch')
# If we had an issue, commit the current state and register the issue.
@@ -2900,6 +2909,15 @@ def CMDset_close(parser, args):
def CMDdiff(parser, args):
"""Shows differences between local tree and last upload."""
parser.parse_args(args)
+
+ # Uncommitted (staged and unstaged) changes will be destroyed by
+ # "git reset --hard" if there are merging conflicts in PatchIssue().
+ # Staged changes would be committed along with the patch from last
+ # upload, hence counted toward the "last upload" side in the final
+ # diff output, and this is not what we want.
+ if is_dirty_git_tree('diff'):
+ return 1
+
cl = Changelist()
issue = cl.GetIssue()
branch = cl.GetBranch()
« 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