Browse Source

pgm: Handle exceptions in Diff 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: Iba0e4338381519dc55c2892d95181ddfb881adf2
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
stable-5.4
Matthias Sohn 6 years ago
parent
commit
a6212392d5
  1. 5
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Diff.java

5
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Diff.java

@ -62,6 +62,7 @@ import org.eclipse.jgit.diff.DiffFormatter;
import org.eclipse.jgit.diff.RawTextComparator; import org.eclipse.jgit.diff.RawTextComparator;
import org.eclipse.jgit.diff.RenameDetector; import org.eclipse.jgit.diff.RenameDetector;
import org.eclipse.jgit.dircache.DirCacheIterator; import org.eclipse.jgit.dircache.DirCacheIterator;
import org.eclipse.jgit.errors.RevisionSyntaxException;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectReader; import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
@ -177,7 +178,7 @@ class Diff extends TextBuiltin {
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
protected void run() throws Exception { protected void run() {
diffFmt.setRepository(db); diffFmt.setRepository(db);
try { try {
if (cached) { if (cached) {
@ -217,6 +218,8 @@ class Diff extends TextBuiltin {
diffFmt.format(oldTree, newTree); diffFmt.format(oldTree, newTree);
diffFmt.flush(); diffFmt.flush();
} }
} catch (RevisionSyntaxException | IOException e) {
throw die(e.getMessage(), e);
} finally { } finally {
diffFmt.close(); diffFmt.close();
} }

Loading…
Cancel
Save