Chromium Code Reviews| Index: trychange.py |
| =================================================================== |
| --- trychange.py (revision 150342) |
| +++ trychange.py (working copy) |
| @@ -65,6 +65,21 @@ |
| -f include/b.h |
| """ |
|
cmp
2012/08/10 23:51:50
nit: insert an empty line before line 67
gavinp
2012/08/12 16:52:16
Done.
|
| +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) |
| + |
|
cmp
2012/08/10 23:51:50
nit: insert an empty line before line 82
gavinp
2012/08/12 16:52:16
Done.
|
| class InvalidScript(Exception): |
| def __str__(self): |
| return self.args[0] + '\n' + HELP_STRING |
| @@ -272,6 +287,10 @@ |
| self.diff_against) |
| def GenerateDiff(self): |
| + if RunGit(['diff-index', 'HEAD']): |
| + # TODO(gavinp): Can we just include the index? |
|
cmp
2012/08/10 23:51:50
safe to remove this line, we can't include the ind
gavinp
2012/08/12 16:52:16
I've removed the comment, and I'll think about thi
|
| + 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 +769,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]) |