summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorChristian Halstrick <christian.halstrick@sap.com>2014-10-21 11:17:34 +0200
committerStefan Lay <stefan.lay@sap.com>2014-11-03 04:33:10 -0500
commit696de653f3ba99df7da50708bac21257d8beb718 (patch)
treef1cbaaf15b89e31f4209e3c508a72cf8d7342bfb /org.eclipse.jgit
parent6f0b92ff22ff58a4c8eb9de8d9b3281d77852070 (diff)
downloadjgit-696de653f3ba99df7da50708bac21257d8beb718.tar.gz
jgit-696de653f3ba99df7da50708bac21257d8beb718.zip
Enhance SubmoduleWalk with a fast check whether a repo contains
submodules Change-Id: Id37efb4f4dd77f3b8eb5607d15d32adeda3992d4
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/submodule/SubmoduleWalk.java22
1 files changed, 22 insertions, 0 deletions
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 30eca741f3..62621cc733 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 <code>true</code> 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();