Skip to content

Commit

Permalink
fix(documentator): requirements command will use local `composer.js…
Browse files Browse the repository at this point in the history
…on` for `HEAD`.

To use the newest dependencies and avoid "Path exists on disk, but not in HEAD" git error.

(cherry picked from commit 80486bd)
  • Loading branch information
LastDragon-ru committed Jan 18, 2024
1 parent 4a76c86 commit eaa095e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/documentator/src/Commands/Requirements.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use function count;
use function end;
use function explode;
use function file_get_contents;
use function getcwd;
use function is_array;
use function json_decode;
Expand All @@ -45,7 +46,7 @@
description: 'Generates a table with the required versions of PHP/Laravel in Markdown format.',
)]
class Requirements extends Command {
public const Name = Package::Name.':requirements';
public const Name = Package::Name.':requirements';
private const HEAD = 'HEAD';

/**
Expand Down Expand Up @@ -175,10 +176,12 @@ protected function getPackageInfo(Git $git, string $tag, string $cwd): ?array {
try {
$root = Path::normalize($git->getRoot($cwd));
$path = Path::join($cwd, 'composer.json');
$path = str_starts_with($path, $root)
$gitPath = str_starts_with($path, $root)
? mb_substr($path, mb_strlen($root) + 1)
: $path;
$package = $git->getFile($path, $tag, $cwd);
$package = $tag !== self::HEAD
? $git->getFile($gitPath, $tag, $cwd)
: (string) file_get_contents($path);
$package = json_decode($package, true, flags: JSON_THROW_ON_ERROR);

assert(is_array($package));
Expand Down

0 comments on commit eaa095e

Please sign in to comment.