From 696de653f3ba99df7da50708bac21257d8beb718 Mon Sep 17 00:00:00 2001 From: Christian Halstrick Date: Tue, 21 Oct 2014 11:17:34 +0200 Subject: [PATCH] Enhance SubmoduleWalk with a fast check whether a repo contains submodules Change-Id: Id37efb4f4dd77f3b8eb5607d15d32adeda3992d4 --- .../eclipse/jgit/submodule/SubmoduleWalk.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) 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 30eca741f..62621cc73 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/submodule/SubmoduleWalk.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/submodule/SubmoduleWalk.java @@ -451,6 +451,28 @@ public class SubmoduleWalk { return this; } + /** + * 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. + * + * @param repository + * the repository to check + * @return true if the repo contains a .gitmodules file + * @throws IOException + * @throws CorruptObjectException + */ + public static boolean containsGitModulesFile(Repository repository) + throws IOException { + if (repository.isBare()) { + DirCache dc = repository.readDirCache(); + return (dc.findEntry(Constants.DOT_GIT_MODULES) >= 0); + } + File modulesFile = new File(repository.getWorkTree(), + Constants.DOT_GIT_MODULES); + return (modulesFile.exists()); + } + private void lazyLoadModulesConfig() throws IOException, ConfigInvalidException { if (modulesConfig == null) loadModulesConfig();