diff options
author | David Pursehouse <david.pursehouse@gmail.com> | 2018-02-14 10:13:46 +0900 |
---|---|---|
committer | David Pursehouse <david.pursehouse@gmail.com> | 2018-02-14 14:09:40 +0900 |
commit | f527d4548f41436e6e77cd54134f25e1b89ba903 (patch) | |
tree | cc73b24eaa50b183297d08a631112a395bcf54b4 /org.eclipse.jgit | |
parent | 19355ce12330a85402fae699c2101275b4272874 (diff) | |
download | jgit-f527d4548f41436e6e77cd54134f25e1b89ba903.tar.gz jgit-f527d4548f41436e6e77cd54134f25e1b89ba903.zip |
InitCommand: Don't leave Repository open after Git is closed
The InitCommand returns a Git that is instantiated with the newly
created Repository, but the Repository is not closed with the Git
resulting in resource leaks.
Create the Git with `closeRepo` set to true, such that the Repository
is also closed when the Git is closed.
Adjust the tests to use try-with-resource on the Git instance.
Change-Id: Ib26e7428c7d8840956d1edb09e53b93e23e6fe5a
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/api/InitCommand.java | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/InitCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/InitCommand.java index f10bcdfcde..d48049f1ed 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/InitCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/InitCommand.java @@ -75,6 +75,9 @@ public class InitCommand implements Callable<Git> { * {@inheritDoc} * <p> * Executes the {@code Init} command. + * + * @return a {@code Git} instance that owns the {@code Repository} that it + * wraps. */ @Override public Git call() throws GitAPIException { @@ -120,7 +123,7 @@ public class InitCommand implements Callable<Git> { Repository repository = builder.build(); if (!repository.getObjectDatabase().exists()) repository.create(bare); - return new Git(repository); + return new Git(repository, true); } catch (IOException e) { throw new JGitInternalException(e.getMessage(), e); } |