aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.pgm
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2019-01-21 23:36:32 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2019-01-21 23:36:32 +0100
commit795c265c11bcab6b54772194fae6cb91bc66ac00 (patch)
tree239e90ed51a19544f10c074bad9ff192732bce76 /org.eclipse.jgit.pgm
parent23af4452e882e382c966b9d23e04a4b969a41773 (diff)
downloadjgit-795c265c11bcab6b54772194fae6cb91bc66ac00.tar.gz
jgit-795c265c11bcab6b54772194fae6cb91bc66ac00.zip
pgm: Handle exceptions in RevParse command
This avoids we show a stacktrace on the console by default when this type of exception is thrown during the run method is executed. Change-Id: Iae510d8c6af9acd587822a28ad48eab0b2a96ccd Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.pgm')
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevParse.java41
1 files changed, 23 insertions, 18 deletions
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevParse.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevParse.java
index ac08cd6ac3..9ff12d8246 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevParse.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevParse.java
@@ -45,6 +45,7 @@
package org.eclipse.jgit.pgm;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -69,27 +70,31 @@ class RevParse extends TextBuiltin {
/** {@inheritDoc} */
@Override
- protected void run() throws Exception {
- if (all) {
- for (Ref r : db.getRefDatabase().getRefs()) {
- ObjectId objectId = r.getObjectId();
- // getRefs skips dangling symrefs, so objectId should never be
- // null.
- if (objectId == null) {
- throw new NullPointerException();
+ protected void run() {
+ try {
+ if (all) {
+ for (Ref r : db.getRefDatabase().getRefs()) {
+ ObjectId objectId = r.getObjectId();
+ // getRefs skips dangling symrefs, so objectId should never
+ // be null.
+ if (objectId == null) {
+ throw new NullPointerException();
+ }
+ outw.println(objectId.name());
+ }
+ } else {
+ if (verify && commits.size() > 1) {
+ final CmdLineParser clp = new CmdLineParser(this);
+ throw new CmdLineException(clp,
+ CLIText.format(CLIText.get().needSingleRevision));
}
- outw.println(objectId.name());
- }
- } else {
- if (verify && commits.size() > 1) {
- final CmdLineParser clp = new CmdLineParser(this);
- throw new CmdLineException(clp,
- CLIText.format(CLIText.get().needSingleRevision));
- }
- for (ObjectId o : commits) {
- outw.println(o.name());
+ for (ObjectId o : commits) {
+ outw.println(o.name());
+ }
}
+ } catch (IOException | CmdLineException e) {
+ throw die(e.getMessage(), e);
}
}
}