From 2d7806da31d5b459b56277e08f38a65863c2b067 Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Mon, 21 Jan 2019 00:48:33 +0100 Subject: 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 --- org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Init.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'org.eclipse.jgit.pgm/src') diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Init.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Init.java index f880fc2076..d24733dee8 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Init.java +++ b/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); + } } } -- cgit v1.2.3