]> source.dussan.org Git - jgit.git/commitdiff
Enhance SubmoduleWalk with a fast check whether a repo contains 90/35190/3
authorChristian Halstrick <christian.halstrick@sap.com>
Tue, 21 Oct 2014 09:17:34 +0000 (11:17 +0200)
committerStefan Lay <stefan.lay@sap.com>
Mon, 3 Nov 2014 09:33:10 +0000 (04:33 -0500)
submodules

Change-Id: Id37efb4f4dd77f3b8eb5607d15d32adeda3992d4

org.eclipse.jgit/src/org/eclipse/jgit/submodule/SubmoduleWalk.java

index 30eca741f3fdb13a8612b372eb363ce03fee3425..62621cc733594bfb9f712ef59416cb3f043d833d 100644 (file)
@@ -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();