diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleDeinitTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleDeinitTest.java index df4b96398..815ce9b35 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleDeinitTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleDeinitTest.java @@ -136,10 +136,12 @@ public class SubmoduleDeinitTest extends RepositoryTestCase { generator.next(); //want to create a commit inside the repo... - Repository submoduleLocalRepo = generator.getRepository(); - JGitTestUtil.writeTrashFile(submoduleLocalRepo, "file.txt", "new data"); - Git.wrap(submoduleLocalRepo).commit().setAll(true).setMessage("local commit").call(); - + try (Repository submoduleLocalRepo = generator.getRepository()) { + JGitTestUtil.writeTrashFile(submoduleLocalRepo, "file.txt", + "new data"); + Git.wrap(submoduleLocalRepo).commit().setAll(true) + .setMessage("local commit").call(); + } SubmoduleDeinitResult result = runDeinit(new SubmoduleDeinitCommand(db).addPath("sub")); assertEquals(path, result.getPath()); assertEquals(SubmoduleDeinitCommand.SubmoduleDeinitStatus.DIRTY, result.getStatus()); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleDeinitCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleDeinitCommand.java index 569a8e359..5a0528b0f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleDeinitCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleDeinitCommand.java @@ -227,11 +227,11 @@ public class SubmoduleDeinitCommand return SubmoduleDeinitStatus.DIRTY; } - Repository submoduleRepo = w.getRepository(); - - Status status = Git.wrap(submoduleRepo).status().call(); - return status.isClean() ? SubmoduleDeinitStatus.SUCCESS - : SubmoduleDeinitStatus.DIRTY; + try (Repository submoduleRepo = w.getRepository()) { + Status status = Git.wrap(submoduleRepo).status().call(); + return status.isClean() ? SubmoduleDeinitStatus.SUCCESS + : SubmoduleDeinitStatus.DIRTY; + } } }