Skip to content

Commit

Permalink
fix(documentator): Requirements command will work correctly inside …
Browse files Browse the repository at this point in the history
…repository.
  • Loading branch information
LastDragon-ru committed Aug 28, 2023
1 parent e65dbad commit 61c494d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/documentator/src/Commands/Requirements.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down
4 changes: 4 additions & 0 deletions packages/documentator/src/Utils/Git.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 61c494d

Please sign in to comment.