if ($this->submodules === null) {
foreach ($files as $file) {
if ($file[4] === '.gitmodules') {
$branch = $hash;
$gitsubmodule = $this->getRepository()->getBlob("$branch:\"$file[4]\"")->output();
$this->submodules = parse_ini_string($gitsubmodule, true);
}
}
if ($this->submodules === null && strpos($hash, ':') !== false) {
// Search in root folder
$data = $this->getRepository()->getClient()->run($this->getRepository(), 'ls-tree -lz ' . explode(':', $hash)[0]);
$lines = explode("\0", $data);
$rootFolderFiles = array();
$root = array();
foreach ($lines as $key => $line) {
if (empty($line)) {
unset($lines[$key]);
continue;
}
$rootFolderFiles[] = preg_split("/[\s]+/", $line, 5);
}
$this->submodules = $this->getSubmodules($rootFolderFiles, explode(':', $hash)[0]);
}
}
return $this->submodules;
}