diff options
author | Matthias Sohn <matthias.sohn@sap.com> | 2019-01-21 00:48:33 +0100 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2019-01-21 00:54:13 +0100 |
commit | 2d7806da31d5b459b56277e08f38a65863c2b067 (patch) | |
tree | 200a24f344c274e4287d5471ad3693a767842005 /org.eclipse.jgit.pgm/src | |
parent | 8b15ff57c8b376f60ad40b0e41ba10395bcfbf5d (diff) | |
download | jgit-2d7806da31d5b459b56277e08f38a65863c2b067.tar.gz jgit-2d7806da31d5b459b56277e08f38a65863c2b067.zip |
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>
Diffstat (limited to 'org.eclipse.jgit.pgm/src')
-rw-r--r-- | org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Init.java | 17 |
1 files changed, 12 insertions, 5 deletions
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); + } } } |