diff --git a/packages/documentator/src/Commands/Requirements.php b/packages/documentator/src/Commands/Requirements.php index 9c1e4abb9..e9d8c9d33 100644 --- a/packages/documentator/src/Commands/Requirements.php +++ b/packages/documentator/src/Commands/Requirements.php @@ -26,8 +26,11 @@ use function getcwd; use function is_array; use function json_decode; +use function mb_strlen; +use function mb_substr; use function range; use function reset; +use function str_starts_with; use function trim; use function uksort; use function view; @@ -152,7 +155,12 @@ protected function getPackageVersions(Git $git, string $cwd, array $tags = []): */ protected function getPackageInfo(Git $git, string $tag, string $cwd): ?array { try { - $package = $git->getFile(Path::join($cwd, 'composer.json'), $tag, $cwd); + $root = Path::normalize($git->getRoot($cwd)); + $path = Path::join($cwd, 'composer.json'); + $path = str_starts_with($path, $root) + ? mb_substr($path, mb_strlen($root) + 1) + : $path; + $package = $git->getFile($path, $tag, $cwd); $package = json_decode($package, true, flags: JSON_THROW_ON_ERROR); assert(is_array($package)); diff --git a/packages/documentator/src/Utils/Git.php b/packages/documentator/src/Utils/Git.php index efa47592a..9cc473018 100644 --- a/packages/documentator/src/Utils/Git.php +++ b/packages/documentator/src/Utils/Git.php @@ -34,4 +34,8 @@ public function getFile(string $path, string $revision = 'HEAD', string $root = public function getBranch(string $root = null): string { return $this->process->run(['git', 'rev-parse', '--abbrev-ref=HEAD'], $root); } + + public function getRoot(string $root = null): string { + return $this->process->run(['git', 'rev-parse', '--show-toplevel'], $root); + } }