Enhance SubmoduleWalk with a fast check whether a repo contains
submodules Change-Id: Id37efb4f4dd77f3b8eb5607d15d32adeda3992d4
This commit is contained in:
parent
6f0b92ff22
commit
696de653f3
|
@ -451,6 +451,28 @@ public SubmoduleWalk loadModulesConfig() throws IOException, ConfigInvalidExcept
|
|||
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();
|
||||
|
|
Loading…
Reference in New Issue