From 130952656432ec9c5d7f56fc84049ff95bfaed56 Mon Sep 17 00:00:00 2001 From: Andrey Loskutov Date: Sun, 2 Aug 2015 23:46:09 +0200 Subject: [PATCH] Clone should close repository after errors in fetch or checkout Bug: 474093 Change-Id: Ia0a1478260b94a71a947aa8c04ee0c836d390aec Signed-off-by: Andrey Loskutov --- .../src/org/eclipse/jgit/api/CloneCommand.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java index 9de2803c0..4aaee8d96 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java @@ -127,16 +127,23 @@ public CloneCommand() { */ public Git call() throws GitAPIException, InvalidRemoteException, org.eclipse.jgit.api.errors.TransportException { + Repository repository = null; try { URIish u = new URIish(uri); - Repository repository = init(u); + repository = init(u); FetchResult result = fetch(repository, u); if (!noCheckout) checkout(repository, result); return new Git(repository); } catch (IOException ioe) { + if (repository != null) { + repository.close(); + } throw new JGitInternalException(ioe.getMessage(), ioe); } catch (URISyntaxException e) { + if (repository != null) { + repository.close(); + } throw new InvalidRemoteException(MessageFormat.format( JGitText.get().invalidRemote, remote)); }