summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2019-09-30 23:59:27 -0400
committerMike Frysinger <vapier@google.com>2019-10-01 05:44:09 +0000
commit0a9265e2d633b608090eff79ab4553f0e1c8c7c4 (patch)
treee82c95a7c44792af2e5848440f25be40ed4c00b3
parentdc1b59d2c0a7ee00b7e6b111285360c4cff32d2b (diff)
downloadgit-repo-0a9265e2d633b608090eff79ab4553f0e1c8c7c4.tar.gz
diff: handle errors gracefully
If `git diff` fails in any project checkout (e.g. an incomplete sync), make sure we print that error clearly rather than blowing up, and exit non-zero in the process. Bug: https://crbug.com/gerrit/11613 Change-Id: I12f278427cced20f23f8047e7e3dba8f442ee25e Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/239236 Reviewed-by: David Pursehouse <dpursehouse@collab.net> Tested-by: Mike Frysinger <vapier@google.com>
-rwxr-xr-xproject.py19
-rw-r--r--subcmds/diff.py5
2 files changed, 18 insertions, 6 deletions
diff --git a/project.py b/project.py
index a20b4134..b41a57cf 100755
--- a/project.py
+++ b/project.py
@@ -230,6 +230,7 @@ class DiffColoring(Coloring):
230 def __init__(self, config): 230 def __init__(self, config):
231 Coloring.__init__(self, config, 'diff') 231 Coloring.__init__(self, config, 'diff')
232 self.project = self.printer('header', attr='bold') 232 self.project = self.printer('header', attr='bold')
233 self.fail = self.printer('fail', fg='red')
233 234
234 235
235class _Annotation(object): 236class _Annotation(object):
@@ -1136,10 +1137,18 @@ class Project(object):
1136 cmd.append('--src-prefix=a/%s/' % self.relpath) 1137 cmd.append('--src-prefix=a/%s/' % self.relpath)
1137 cmd.append('--dst-prefix=b/%s/' % self.relpath) 1138 cmd.append('--dst-prefix=b/%s/' % self.relpath)
1138 cmd.append('--') 1139 cmd.append('--')
1139 p = GitCommand(self, 1140 try:
1140 cmd, 1141 p = GitCommand(self,
1141 capture_stdout=True, 1142 cmd,
1142 capture_stderr=True) 1143 capture_stdout=True,
1144 capture_stderr=True)
1145 except GitError as e:
1146 out.nl()
1147 out.project('project %s/' % self.relpath)
1148 out.nl()
1149 out.fail('%s', str(e))
1150 out.nl()
1151 return False
1143 has_diff = False 1152 has_diff = False
1144 for line in p.process.stdout: 1153 for line in p.process.stdout:
1145 if not hasattr(line, 'encode'): 1154 if not hasattr(line, 'encode'):
@@ -1150,7 +1159,7 @@ class Project(object):
1150 out.nl() 1159 out.nl()
1151 has_diff = True 1160 has_diff = True
1152 print(line[:-1]) 1161 print(line[:-1])
1153 p.Wait() 1162 return p.Wait() == 0
1154 1163
1155 1164
1156# Publish / Upload ## 1165# Publish / Upload ##
diff --git a/subcmds/diff.py b/subcmds/diff.py
index 1f3abd86..fa41e70e 100644
--- a/subcmds/diff.py
+++ b/subcmds/diff.py
@@ -37,5 +37,8 @@ to the Unix 'patch' command.
37 help='Paths are relative to the repository root') 37 help='Paths are relative to the repository root')
38 38
39 def Execute(self, opt, args): 39 def Execute(self, opt, args):
40 ret = 0
40 for project in self.GetProjects(args): 41 for project in self.GetProjects(args):
41 project.PrintWorkTreeDiff(opt.absolute) 42 if not project.PrintWorkTreeDiff(opt.absolute):
43 ret = 1
44 return ret