]> source.dussan.org Git - jgit.git/commitdiff
Make sure test repositories are closed 87/3587/1
authorChristian Halstrick <christian.halstrick@sap.com>
Tue, 24 May 2011 07:36:45 +0000 (09:36 +0200)
committerShawn O. Pearce <spearce@spearce.org>
Tue, 31 May 2011 15:58:45 +0000 (08:58 -0700)
Some repositories created during tests are not added to the 'toClose'
list in LocalDiskRepositoryTestCase. Therefore when the tests end
we may have open FileHandles and on Windows this may cause the
tests to fail because we can't delete those files.

This is fixed by adding the possibility to explicitly add
repositories to the list of repos which are closed automatically.

Change-Id: I1261baeef4c7d9aaedd7c34b546393bfa005bbcc
Signed-off-by: Christian Halstrick <christian.halstrick@sap.com>
org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/GitConstructionTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/InitCommandTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LsRemoteCommandTest.java

index 30d437540f7fa205e98bdb84429b0b25c6fedbd6..8ed51fb908d2d90f66994e64a70cf4cc482432ca 100644 (file)
@@ -302,6 +302,17 @@ public abstract class LocalDiskRepositoryTestCase {
                return db;
        }
 
+       /**
+        * Adds a repository to the list of repositories which is closed at the end
+        * of the tests
+        *
+        * @param r
+        *            the repository to be closed
+        */
+       public void addRepoToClose(Repository r) {
+               toClose.add(r);
+       }
+
        /**
         * Creates a new unique directory for a test repository
         *
index 9d01291b7a72138333d8e854c0c154647c353129..2e3345756d33a70212b629eb341d8ce06cd231fe 100644 (file)
@@ -101,6 +101,7 @@ public class CloneCommandTest extends RepositoryTestCase {
                        command.setURI("file://"
                                        + git.getRepository().getWorkTree().getPath());
                        Git git2 = command.call();
+                       addRepoToClose(git2.getRepository());
                        assertNotNull(git2);
                        ObjectId id = git2.getRepository().resolve("tag-for-blob");
                        assertNotNull(id);
@@ -135,6 +136,8 @@ public class CloneCommandTest extends RepositoryTestCase {
                        command.setURI("file://"
                                        + git.getRepository().getWorkTree().getPath());
                        Git git2 = command.call();
+                       addRepoToClose(git2.getRepository());
+
                        assertNotNull(git2);
                        assertEquals(git2.getRepository().getFullBranch(),
                                        "refs/heads/master");
@@ -152,6 +155,8 @@ public class CloneCommandTest extends RepositoryTestCase {
                                        + git.getRepository().getWorkTree().getPath());
                        command.setNoCheckout(true);
                        git2 = command.call();
+                       addRepoToClose(git2.getRepository());
+
                        assertNotNull(git2);
                        assertEquals(git2.getRepository().getFullBranch(),
                                        "refs/heads/master");
@@ -169,6 +174,8 @@ public class CloneCommandTest extends RepositoryTestCase {
                                        + git.getRepository().getWorkTree().getPath());
                        command.setBare(true);
                        git2 = command.call();
+                       addRepoToClose(git2.getRepository());
+
                        assertNotNull(git2);
                        assertEquals(git2.getRepository().getFullBranch(),
                                        "refs/heads/master");
@@ -191,6 +198,7 @@ public class CloneCommandTest extends RepositoryTestCase {
                        command.setURI("file://"
                                        + git.getRepository().getWorkTree().getPath());
                        Git git2 = command.call();
+                       addRepoToClose(git2.getRepository());
                        assertNotNull(git2);
                        assertEquals(git2.getRepository().getFullBranch(),
                                        "refs/heads/master");
@@ -209,6 +217,7 @@ public class CloneCommandTest extends RepositoryTestCase {
                                        + git.getRepository().getWorkTree().getPath());
                        command.setBare(true);
                        git2 = command.call();
+                       addRepoToClose(git2.getRepository());
                        assertNotNull(git2);
                        assertEquals(git2.getRepository().getFullBranch(),
                                        "refs/heads/master");
index b6ba4c927de999aba0e15184f410cdd22ae3ae7e..4d2b241dcb1c3b1c73f758691cd3fe9aae589dfe 100644 (file)
@@ -71,6 +71,7 @@ public class GitConstructionTest extends RepositoryTestCase {
                                .setURI(db.getDirectory().toURI().toString())
                                .setDirectory(createUniqueTestGitDir(true)).call()
                                .getRepository();
+               addRepoToClose(bareRepo);
        }
 
        @Test
index 15aafc9060b7591659a094d3d1833ee000df02f8..28c54c269f0e4abf53d64a71d813686c0b639307 100644 (file)
@@ -70,6 +70,7 @@ public class InitCommandTest extends RepositoryTestCase {
                        InitCommand command = new InitCommand();
                        command.setDirectory(directory);
                        Repository repository = command.call().getRepository();
+                       addRepoToClose(repository);
                        assertNotNull(repository);
                } catch (Exception e) {
                        fail(e.getMessage());
@@ -84,6 +85,7 @@ public class InitCommandTest extends RepositoryTestCase {
                        command.setDirectory(directory);
                        command.setBare(true);
                        Repository repository = command.call().getRepository();
+                       addRepoToClose(repository);
                        assertNotNull(repository);
                        assertTrue(repository.isBare());
                } catch (Exception e) {
index 81aa25f981205fe9cf0c4da169f473a3449ff61f..a4a5a2671b1b5f38916e5112f1c874af1fda2e8e 100644 (file)
@@ -89,6 +89,8 @@ public class LsRemoteCommandTest extends RepositoryTestCase {
                                        + git.getRepository().getWorkTree().getPath());
                        command.setCloneAllBranches(true);
                        Git git2 = command.call();
+                       addRepoToClose(git2.getRepository());
+
 
                        LsRemoteCommand lsRemoteCommand = git2.lsRemote();
                        Collection<Ref> refs = lsRemoteCommand.call();
@@ -109,6 +111,7 @@ public class LsRemoteCommandTest extends RepositoryTestCase {
                                        + git.getRepository().getWorkTree().getPath());
                        command.setCloneAllBranches(true);
                        Git git2 = command.call();
+                       addRepoToClose(git2.getRepository());
 
                        LsRemoteCommand lsRemoteCommand = git2.lsRemote();
                        lsRemoteCommand.setTags(true);
@@ -130,6 +133,7 @@ public class LsRemoteCommandTest extends RepositoryTestCase {
                                        + git.getRepository().getWorkTree().getPath());
                        command.setCloneAllBranches(true);
                        Git git2 = command.call();
+                       addRepoToClose(git2.getRepository());
 
                        LsRemoteCommand lsRemoteCommand = git2.lsRemote();
                        lsRemoteCommand.setHeads(true);