diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Die.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Die.java index a2f406082..f07df1a4b 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Die.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Die.java @@ -54,6 +54,8 @@ public class Die extends RuntimeException { private static final long serialVersionUID = 1L; + private boolean aborted; + /** * Construct a new message explaining what has gone wrong. * @@ -75,4 +77,25 @@ public Die(final String why) { public Die(final String why, final Throwable cause) { super(why, cause); } + + /** + * 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 + * @since 3.4 + */ + public Die(boolean aborted) { + this.aborted = aborted; + } + + /** + * Check if this exception should cause the execution to be aborted. + * + * @return boolean indicating that the execution should be aborted + * @since 3.4 + */ + public boolean isAborted() { + return aborted; + } } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java index 3648ffd8e..94591393a 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java @@ -123,6 +123,8 @@ protected void run(final String[] argv) { configureHttpProxy(); execute(argv); } catch (Die err) { + if (err.isAborted()) + System.exit(1); System.err.println(MessageFormat.format(CLIText.get().fatalError, err.getMessage())); if (showStackTrace) err.printStackTrace(); diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java index 3308fda0e..8e8b82fe0 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java @@ -227,7 +227,7 @@ protected void parseArguments(final String[] args) throws IOException { } catch (CmdLineException err) { if (!help) { this.errw.println(MessageFormat.format(CLIText.get().fatalError, err.getMessage())); - System.exit(1); + throw die(true); } } @@ -267,7 +267,7 @@ public void printUsageAndExit(final String message, final CmdLineParser clp) thr errw.println(); errw.flush(); - System.exit(1); + throw die(true); } /** @@ -324,6 +324,16 @@ protected static Die die(final String why, final Throwable cause) { return new Die(why, cause); } + /** + * @param aborted + * boolean indicating that the execution has been aborted before running + * @return a runtime exception the caller is expected to throw + * @since 3.4 + */ + protected static Die die(boolean aborted) { + return new Die(aborted); + } + String abbreviateRef(String dst, boolean abbreviateRemote) { if (dst.startsWith(R_HEADS)) dst = dst.substring(R_HEADS.length());