]> source.dussan.org Git - jgit.git/commitdiff
Provide a root cause for aborted commands 20/63320/2
authorAndrey Loskutov <loskutov@gmx.de>
Mon, 28 Dec 2015 17:13:35 +0000 (18:13 +0100)
committerAndrey Loskutov <loskutov@gmx.de>
Tue, 29 Dec 2015 01:33:23 +0000 (02:33 +0100)
Change-Id: Iafaa03dbacbe7f1b2b074d3294db988b08fdb0d7
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Die.java
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java

index f07df1a4b5d6b91ab4314d5938644478a6da315d..a25f1e93052d74855ff81683c013e29af1d60fc7 100644 (file)
@@ -86,6 +86,21 @@ public class Die extends RuntimeException {
         * @since 3.4
         */
        public Die(boolean aborted) {
+               this(aborted, null);
+       }
+
+       /**
+        * Construct a new exception reflecting the fact that the command execution
+        * has been aborted before running.
+        *
+        * @param aborted
+        *            boolean indicating the fact the execution has been aborted
+        * @param cause
+        *            can be null
+        * @since 4.2
+        */
+       public Die(boolean aborted, final Throwable cause) {
+               super(cause != null ? cause.getMessage() : null, cause);
                this.aborted = aborted;
        }
 
index 56cfc7e8ef866e47c354ceeb4ee12c0935679c4a..40a42e5207a5696e8d76283f23518b43d83dff75 100644 (file)
@@ -217,7 +217,7 @@ public abstract class TextBuiltin {
                } catch (CmdLineException err) {
                        if (!help) {
                                this.errw.println(MessageFormat.format(CLIText.get().fatalError, err.getMessage()));
-                               throw die(true);
+                               throw die(true, err);
                        }
                }
 
@@ -324,6 +324,19 @@ public abstract class TextBuiltin {
                return new Die(aborted);
        }
 
+       /**
+        * @param aborted
+        *            boolean indicating that the execution has been aborted before
+        *            running
+        * @param cause
+        *            why the command has failed.
+        * @return a runtime exception the caller is expected to throw
+        * @since 4.2
+        */
+       protected static Die die(boolean aborted, final Throwable cause) {
+               return new Die(aborted, cause);
+       }
+
        String abbreviateRef(String dst, boolean abbreviateRemote) {
                if (dst.startsWith(R_HEADS))
                        dst = dst.substring(R_HEADS.length());