IonBazan / composer-diff

Compares composer.lock changes and generates Markdown report so you can use it in PR description.
https://packagist.org/packages/ion-bazan/composer-diff
MIT License
143 stars 6 forks source link

Could not open file branch-name:composer.lock or find it in git as branch-name:composer.lock: fatal: invalid object name 'branch-name' #30

Closed janedbal closed 7 months ago

janedbal commented 8 months ago

See job output: https://github.com/qossmic/deptrac/actions/runs/8007789467/job/21872726582?pr=1374

In PackageDiff.php line 136:

  [RuntimeException]                                                           
  Could not open file composer-dependency-analyser:composer.lock or find it i  
  n git as composer-dependency-analyser:composer.lock: fatal: invalid object   
  name 'composer-dependency-analyser'.                                         

Exception trace:
  at /workdir/vendor/ion-bazan/composer-diff/src/PackageDiff.php:136
 IonBazan\ComposerDiff\PackageDiff->getFileContents() at /workdir/vendor/ion-bazan/composer-diff/src/PackageDiff.php:92
 IonBazan\ComposerDiff\PackageDiff->loadPackages() at /workdir/vendor/ion-bazan/composer-diff/src/PackageDiff.php:79
 IonBazan\ComposerDiff\PackageDiff->getPackageDiff() at /workdir/vendor/ion-bazan/composer-diff/src/Command/DiffCommand.php:141
 IonBazan\ComposerDiff\Command\DiffCommand->execute() at /workdir/vendor/symfony/console/Command/Command.php:312
 Symfony\Component\Console\Command\Command->run() at /workdir/vendor/symfony/console/Application.php:1022
 Symfony\Component\Console\Application->doRunCommand() at /workdir/vendor/symfony/console/Application.php:314
 Symfony\Component\Console\Application->doRun() at /workdir/vendor/symfony/console/Application.php:168
 Symfony\Component\Console\Application->run() at /workdir/vendor/ion-bazan/composer-diff/composer-diff:[30](https://github.com/qossmic/deptrac/actions/runs/8007723786/job/21872510353?pr=1374#step:4:31)
 include() at /workdir/vendor/bin/composer-diff:120

Maybe related to the fact that the newly added package in the PR has composer.lock committed and not export-ignored in .gitattributes, but I'm guessing here.

IonBazan commented 8 months ago

@janedbal I think this action: WyriHaximus/github-action-composer.lock-diff is not resolving the HEAD branch correctly and as far as I can see, it doesn't allow to customize it. Can you try with the action I created: https://github.com/marketplace/actions/composer-diff? It allows to customize the target and base branch, but I recommend leaving them at default settings. I'm using the same action in my other projects and they are working fine.

The issue is that above action resolves your base branch as composer-dependency-analyser which is not in the repository as you are submitting aa PR from your fork, so the branch does not exist. It should either leave that parameter empty, or set it to composer.lock or HEAD:composer.lock to simply take the content of the current local file.

IonBazan commented 7 months ago

Closing as it looks that it's not caused by this package. Please feel free to reopen this issue if needed.

janedbal commented 7 months ago

Maybe the error message can be improved here?

WyriHaximus commented 7 months ago

@IonBazan Turned out the issue was in @janedbal using v1 which is indeed broken for PR's. v2 does not have that issue because it's using the checkout actions internally. Just added reasoning to my action's readme with the difference between yours and mine: https://github.com/WyriHaximus/github-action-composer.lock-diff?tab=readme-ov-file#reasoning

IonBazan commented 7 months ago

@WyriHaximus that explains a lot! Thanks for updating the readme and helping us with the issue. Let me know if you have any ideas or improvements for the action I created, feel free to propose PRs there too.