diff options
author | Christian Halstrick <christian.halstrick@sap.com> | 2013-11-19 12:44:19 +0100 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2013-11-20 00:16:39 +0100 |
commit | 7dce16018e05c0a094b3eb20009e0438764f046e (patch) | |
tree | cec6ee0316c0d389f41ec944419f2db6500cb439 /org.eclipse.jgit.test | |
parent | 3cf2a8542af2373c1f249d05bc97c4d0abc0bcf8 (diff) | |
download | jgit-7dce16018e05c0a094b3eb20009e0438764f046e.tar.gz jgit-7dce16018e05c0a094b3eb20009e0438764f046e.zip |
Add close() method to API
The API in org.eclipse.jgit.api does allow to open repositories but it
did not allow to close them. This commit fixes this and allows
API users to close a repository without having to use lower-level
classes.
Bug: 420502
Change-Id: I866225cc8534ae5916113fa24eb1c7513fd4472e
Signed-off-by: Christian Halstrick <christian.halstrick@sap.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/api/GitConstructionTest.java | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/GitConstructionTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/GitConstructionTest.java index 8d7758cb7a..64bb8bfa4d 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/GitConstructionTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/GitConstructionTest.java @@ -45,6 +45,7 @@ package org.eclipse.jgit.api; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; +import java.io.File; import java.io.IOException; import org.eclipse.jgit.api.ListBranchCommand.ListMode; @@ -53,6 +54,7 @@ import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.errors.RepositoryNotFoundException; import org.eclipse.jgit.junit.RepositoryTestCase; import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.util.FileUtils; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -123,4 +125,30 @@ public class GitConstructionTest extends RepositoryTestCase { // should not get here } } + + @Test + /** + * Tests that a repository with packfiles can be deleted after calling + * Git.close(). On Windows the first try to delete the worktree will fail + * (because file handles on packfiles are still open) but the second + * attempt after a close will succeed. + * + * @throws IOException + * @throws JGitInternalException + * @throws GitAPIException + */ + public void testClose() throws IOException, JGitInternalException, + GitAPIException { + File workTree = db.getWorkTree(); + Git git = Git.wrap(db); + git.gc().setExpire(null).call(); + git.checkout().setName(git.getRepository().resolve("HEAD^").getName()) + .call(); + try { + FileUtils.delete(workTree, FileUtils.RECURSIVE); + } catch (IOException e) { + git.close(); + FileUtils.delete(workTree, FileUtils.RECURSIVE); + } + } } |