Browse Source

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

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

@ -49,6 +49,7 @@ import java.util.List;
import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.ResetCommand; import org.eclipse.jgit.api.ResetCommand;
import org.eclipse.jgit.api.ResetCommand.ResetType; import org.eclipse.jgit.api.ResetCommand.ResetType;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.kohsuke.args4j.Argument; import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.Option; import org.kohsuke.args4j.Option;
import org.kohsuke.args4j.spi.RestOfArgumentsHandler; import org.kohsuke.args4j.spi.RestOfArgumentsHandler;
@ -74,7 +75,7 @@ class Reset 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)) {
ResetCommand command = git.reset(); ResetCommand command = git.reset();
command.setRef(commit); command.setRef(commit);
@ -94,6 +95,8 @@ class Reset extends TextBuiltin {
command.setMode(mode); command.setMode(mode);
} }
command.call(); command.call();
} catch (GitAPIException e) {
throw die(e.getMessage(), e);
} }
} }

Loading…
Cancel
Save