mercurial/scmutil.py
changeset 45826 21733e8c924f
parent 45825 8f07f5a9c3de
child 45827 8d72e29ad1e0
--- a/mercurial/scmutil.py	Sat Nov 07 21:50:28 2020 -0800
+++ b/mercurial/scmutil.py	Wed Oct 21 19:00:16 2020 -0700
@@ -148,6 +148,8 @@
     return func() if no exception happens. otherwise do some error handling
     and return an exit code accordingly. does not handle all exceptions.
     """
+    coarse_exit_code = -1
+    detailed_exit_code = -1
     try:
         try:
             return func()
@@ -212,7 +214,8 @@
         ui.error(b"%s\n" % inst)
         if inst.hint:
             ui.error(_(b"(%s)\n") % inst.hint)
-        return 1
+        detailed_exit_code = 240
+        coarse_exit_code = 1
     except error.WdirUnsupported:
         ui.error(_(b"abort: working directory revision cannot be specified\n"))
     except error.Abort as inst:
@@ -266,9 +269,13 @@
     except SystemExit as inst:
         # Commands shouldn't sys.exit directly, but give a return code.
         # Just in case catch this and and pass exit code to caller.
-        return inst.code
+        detailed_exit_code = 254
+        coarse_exit_code = inst.code
 
-    return -1
+    if ui.configbool(b'ui', b'detailed-exit-code'):
+        return detailed_exit_code
+    else:
+        return coarse_exit_code
 
 
 def checknewlabel(repo, lbl, kind):