mercurial/ui.py
changeset 31108 3f8f53190d6a
parent 31107 fbce78c58f1e
child 31113 268caf97c38f
--- a/mercurial/ui.py	Sun Feb 19 01:00:10 2017 +0900
+++ b/mercurial/ui.py	Sun Feb 19 01:16:45 2017 +0900
@@ -1281,6 +1281,9 @@
                blockedtag=None):
         '''execute shell command with appropriate output stream. command
         output will be redirected if fout is not stdout.
+
+        if command fails and onerr is None, return status, else raise onerr
+        object as exception.
         '''
         if blockedtag is None:
             blockedtag = 'unknown_system_' + cmd.translate(None, _keepalnum)
@@ -1288,14 +1291,19 @@
         if any(s[1] for s in self._bufferstates):
             out = self
         with self.timeblockedsection(blockedtag):
-            return self._runsystem(cmd, environ=environ, cwd=cwd, onerr=onerr,
-                                   errprefix=errprefix, out=out)
+            rc = self._runsystem(cmd, environ=environ, cwd=cwd, out=out)
+        if rc and onerr:
+            errmsg = '%s %s' % (os.path.basename(cmd.split(None, 1)[0]),
+                                util.explainexit(rc)[0])
+            if errprefix:
+                errmsg = '%s: %s' % (errprefix, errmsg)
+            raise onerr(errmsg)
+        return rc
 
-    def _runsystem(self, cmd, environ, cwd, onerr, errprefix, out):
+    def _runsystem(self, cmd, environ, cwd, out):
         """actually execute the given shell command (can be overridden by
         extensions like chg)"""
-        return util.system(cmd, environ=environ, cwd=cwd, onerr=onerr,
-                           errprefix=errprefix, out=out)
+        return util.system(cmd, environ=environ, cwd=cwd, out=out)
 
     def traceback(self, exc=None, force=False):
         '''print exception traceback if traceback printing enabled or forced.