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

Unified Diff: trychange.py

Issue 10836180: Make git try warn on a dirty index. (Closed) Base URL: http://src.chromium.org/svn/trunk/tools/depot_tools/
Patch Set: minimize unittest diff a bit... Created 8 years, 4 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 | « tests/trychange_unittest.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: trychange.py
===================================================================
--- trychange.py (revision 151034)
+++ trychange.py (working copy)
@@ -65,6 +65,28 @@
-f include/b.h
"""
+
+def DieWithError(message):
+ print >> sys.stderr, message
+ sys.exit(1)
+
+
+def RunCommand(args, error_ok=False, error_message=None, **kwargs):
+ try:
+ return subprocess2.check_output(args, shell=False, **kwargs)
+ except subprocess2.CalledProcessError, e:
+ if not error_ok:
+ DieWithError(
+ 'Command "%s" failed.\n%s' % (
+ ' '.join(args), error_message or e.stdout or ''))
+ return e.stdout
+
+
+def RunGit(args, **kwargs):
+ """Returns stdout."""
+ return RunCommand(['git'] + args, **kwargs)
+
+
class InvalidScript(Exception):
def __str__(self):
return self.args[0] + '\n' + HELP_STRING
@@ -272,6 +294,9 @@
self.diff_against)
def GenerateDiff(self):
+ if RunGit(['diff-index', 'HEAD']):
+ print 'Cannot try with a dirty tree. You must commit locally first.'
+ return None
return scm.GIT.GenerateDiff(
self.checkout_root,
files=self.files,
@@ -750,7 +775,10 @@
root = checkouts[0].checkout_root
diffs = []
for checkout in checkouts:
- diff = checkout.GenerateDiff().splitlines(True)
+ raw_diff = checkout.GenerateDiff()
+ if not raw_diff:
+ return 1
+ diff = raw_diff.splitlines(True)
path_diff = gclient_utils.PathDifference(root, checkout.checkout_root)
# Munge it.
diffs.extend(GetMungedDiff(path_diff, diff)[0])
« no previous file with comments | « tests/trychange_unittest.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698