/** * Tries to find the root directory for a given repository path * * @param string $path The file system path * @return string|null NULL if the root cannot be found, the root path otherwise */ public static function findRepositoryRoot($path) { return FileSystem::bubble($path, function ($p) { $gitDir = $p . '/' . '.git'; return file_exists($gitDir) && is_dir($gitDir); }); }
/** * Tries to find the root directory for a given repository path * * @param Binary $svn The SVN binary * @param string $path The file system path * @return string|null NULL if the root cannot be found, the root path otherwise */ public static function findRepositoryRoot(Binary $svn, $path) { $hasSvnDir = function ($path) { $svnDir = $path . '/' . '.svn'; return file_exists($svnDir) && is_dir($svnDir); }; $pathWithSvnDir = FileSystem::bubble($path, $hasSvnDir); $root = $pathWithSvnDir; $parentDir = dirname($pathWithSvnDir); while ($hasSvnDir($parentDir) && strlen($root) > 1) { $root = dirname($root); $parentDir = dirname($parentDir); } return $root; }