Browse Source

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

17
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Init.java

@ -49,10 +49,12 @@
package org.eclipse.jgit.pgm;
import java.io.File;
import java.io.IOException;
import java.text.MessageFormat;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.InitCommand;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.pgm.internal.CLIText;
import org.kohsuke.args4j.Argument;
@ -74,7 +76,7 @@ class Init extends TextBuiltin {
/** {@inheritDoc} */
@Override
protected void run() throws Exception {
protected void run() {
InitCommand command = Git.init();
command.setBare(bare);
if (gitdir != null) {
@ -83,9 +85,14 @@ class Init extends TextBuiltin {
if (directory != null) {
command.setDirectory(new File(directory));
}
Repository repository = command.call().getRepository();
outw.println(MessageFormat.format(
CLIText.get().initializedEmptyGitRepositoryIn, repository
.getDirectory().getAbsolutePath()));
Repository repository;
try {
repository = command.call().getRepository();
outw.println(MessageFormat.format(
CLIText.get().initializedEmptyGitRepositoryIn,
repository.getDirectory().getAbsolutePath()));
} catch (GitAPIException | IOException e) {
throw die(e.getMessage(), e);
}
}
}

Loading…
Cancel
Save