pgm: Handle exceptions in Reflog 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: Id25eb523c12c07cbd14e31edfb8b5d7ec9b3ccf3
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
Matthias Sohn 2019-01-21 23:17:00 +01:00
parent 8615c042ff
commit d8fec824e4
1 changed files with 5 additions and 1 deletions

View File

@ -42,10 +42,12 @@
*/ */
package org.eclipse.jgit.pgm; package org.eclipse.jgit.pgm;
import java.io.IOException;
import java.util.Collection; import java.util.Collection;
import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.ReflogCommand; import org.eclipse.jgit.api.ReflogCommand;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ReflogEntry; import org.eclipse.jgit.lib.ReflogEntry;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
@ -59,7 +61,7 @@ class Reflog extends TextBuiltin {
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
protected void run() throws Exception { protected void run() {
try (Git git = new Git(db)) { try (Git git = new Git(db)) {
ReflogCommand cmd = git.reflog(); ReflogCommand cmd = git.reflog();
if (ref != null) if (ref != null)
@ -69,6 +71,8 @@ protected void run() throws Exception {
for (ReflogEntry entry : entries) { for (ReflogEntry entry : entries) {
outw.println(toString(entry, i++)); outw.println(toString(entry, i++));
} }
} catch (GitAPIException | IOException e) {
throw die(e.getMessage(), e);
} }
} }