diff options
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleWalkTest.java | 8 | ||||
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/submodule/SubmoduleWalk.java | 12 |
2 files changed, 14 insertions, 6 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleWalkTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleWalkTest.java index f7acaa7880..72b4611df5 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleWalkTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleWalkTest.java @@ -65,6 +65,7 @@ import org.eclipse.jgit.dircache.DirCacheEditor.PathEdit; import org.eclipse.jgit.dircache.DirCacheEntry; import org.eclipse.jgit.errors.ConfigInvalidException; import org.eclipse.jgit.errors.NoWorkTreeException; +import org.eclipse.jgit.internal.storage.file.FileRepository; import org.eclipse.jgit.junit.RepositoryTestCase; import org.eclipse.jgit.junit.TestRepository; import org.eclipse.jgit.lib.Config; @@ -101,6 +102,13 @@ public class SubmoduleWalkTest extends RepositoryTestCase { } @Test + public void bareRepositoryWithNoSubmodules() throws IOException { + FileRepository bareRepo = createBareRepository(); + boolean result = SubmoduleWalk.containsGitModulesFile(bareRepo); + assertFalse(result); + } + + @Test public void repositoryWithRootLevelSubmodule() throws IOException, ConfigInvalidException, NoWorkTreeException, GitAPIException { final ObjectId id = ObjectId diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/submodule/SubmoduleWalk.java b/org.eclipse.jgit/src/org/eclipse/jgit/submodule/SubmoduleWalk.java index 7d9bca0d1b..6263d4b74d 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/submodule/SubmoduleWalk.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/submodule/SubmoduleWalk.java @@ -451,13 +451,14 @@ public class SubmoduleWalk implements AutoCloseable { } /** - * Checks whether the working tree (or the index in case of a bare repo) - * contains a .gitmodules file. That's a hint that the repo contains - * submodules. + * Checks whether the working tree contains a .gitmodules file. That's a + * hint that the repo contains submodules. * * @param repository * the repository to check - * @return <code>true</code> if the repo contains a .gitmodules file + * @return <code>true</code> if the working tree contains a .gitmodules file, + * <code>false</code> otherwise. Always returns <code>false</code> + * for bare repositories. * @throws IOException * @throws CorruptObjectException * @since 3.6 @@ -465,8 +466,7 @@ public class SubmoduleWalk implements AutoCloseable { public static boolean containsGitModulesFile(Repository repository) throws IOException { if (repository.isBare()) { - DirCache dc = repository.readDirCache(); - return (dc.findEntry(Constants.DOT_GIT_MODULES) >= 0); + return false; } File modulesFile = new File(repository.getWorkTree(), Constants.DOT_GIT_MODULES); |