Browse Source

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>
stable-5.4
Matthias Sohn 6 years ago
parent
commit
d8fec824e4
  1. 6
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Reflog.java

6
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Reflog.java

@ -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 @@ class Reflog extends TextBuiltin {
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);
} }
} }

Loading…
Cancel
Save