From 45689b4a2c39b820143140aa7185f23f445067ea Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Tue, 3 Sep 2024 19:35:16 +0200 Subject: [PATCH] Revert "Remove deprecated LocalDiskRepositoryTestCase#create(boolean,boolean)" This reverts commit 3682611cef41ade46cf5ac194f0674b46367a395. Reason: removing this deprecated method caused a ton of warnings about closing an already closed Repository when running tests. Change-Id: I3e9f224c55c167f92dad39caabfab5e43cf54cfb --- .../junit/LocalDiskRepositoryTestCase.java | 23 ++++++++++++++++++- .../eclipse/jgit/lib/RepositoryCacheTest.java | 13 +++++++---- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java index 98f69ed31c0..407290a3997 100644 --- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java +++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java @@ -422,11 +422,32 @@ protected FileRepository createWorkRepository() throws IOException { */ protected FileRepository createRepository(boolean bare) throws IOException { + return createRepository(bare, false /* auto close */); + } + + /** + * Creates a new empty repository. + * + * @param bare + * true to create a bare repository; false to make a repository + * within its working directory + * @param autoClose + * auto close the repository in {@link #tearDown()} + * @return the newly created repository, opened for access + * @throws IOException + * the repository could not be created in the temporary area + * @deprecated use {@link #createRepository(boolean)} instead + */ + @Deprecated + public FileRepository createRepository(boolean bare, boolean autoClose) + throws IOException { File gitdir = createUniqueTestGitDir(bare); FileRepository db = new FileRepository(gitdir); assertFalse(gitdir.exists()); db.create(bare); - addRepoToClose(db); + if (autoClose) { + addRepoToClose(db); + } return db; } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java index 2a6551787ff..cec69c49981 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java @@ -159,8 +159,8 @@ public void testRepositoryUsageCount() throws Exception { @Test public void testRepositoryUsageCountWithRegisteredRepository() throws IOException { - @SuppressWarnings("resource") // We are testing the close() method - Repository repo = createRepository(false); + @SuppressWarnings({"resource", "deprecation"}) // We are testing the close() method + Repository repo = createRepository(false, false); assertEquals(1, repo.useCnt.get()); RepositoryCache.register(repo); assertEquals(1, repo.useCnt.get()); @@ -207,8 +207,10 @@ public void testRepositoryUnregisteringWhenExpiredAndUsageCountNegative() @Test public void testRepositoryUnregisteringWhenExpired() throws Exception { - Repository repoA = createRepository(true); - Repository repoB = createRepository(true); + @SuppressWarnings({"resource", "deprecation"}) // We are testing the close() method + Repository repoA = createRepository(true, false); + @SuppressWarnings({"resource", "deprecation"}) // We are testing the close() method + Repository repoB = createRepository(true, false); Repository repoC = createBareRepository(); RepositoryCache.register(repoA); RepositoryCache.register(repoB); @@ -241,7 +243,8 @@ public void testRepositoryUnregisteringWhenExpired() throws Exception { @Test public void testReconfigure() throws InterruptedException, IOException { - Repository repo = createRepository(false); + @SuppressWarnings({"resource", "deprecation"}) // We are testing the close() method + Repository repo = createRepository(false, false); RepositoryCache.register(repo); assertTrue(RepositoryCache.isCached(repo)); repo.close();