Support diffing against a non-existing composer.lock file#46
Support diffing against a non-existing composer.lock file#46wikando-ck wants to merge 4 commits into
Conversation
1d7c65b to
b43eea6
Compare
b43eea6 to
fe68bd4
Compare
|
Thanks for the bug report and your contribution. Could you help to check why the Windows build is failing? This must have something to do with using |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #46 +/- ##
===========================================
Coverage 100.00% 100.00%
- Complexity 242 247 +5
===========================================
Files 22 22
Lines 611 632 +21
===========================================
+ Hits 611 632 +21 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
7dddef0 to
2d13833
Compare
|
Fixed the windows issue and covered that by tests. |
Add regression tests for Windows absolute base lock paths and one-letter ref:path syntax.
1820246 to
c8e7b3e
Compare
|
|
||
| /* @infection-ignore-all False-positive */ | ||
| return '{}'; // Do not throw exception for composer.json as it might not exist and that's fine | ||
| if (!$this->looksLikeJsonDocument($outputString)) { |
There was a problem hiding this comment.
This will cause decoding the json twice. Also, if the file exists but is not a well-formed JSON, I wouldn't consider it a skippable IO error and throw exception here. Let me know what you think.
| return substr($path, 0, -strlen(self::EXTENSION_LOCK)).self::EXTENSION_JSON; | ||
| } | ||
|
|
||
| return $path; |
There was a problem hiding this comment.
Somehow there is an escaped mutant here now 🤔
|
|
||
| if ($lockFile) { | ||
| $candidates[] = $path; | ||
| $candidates[] = $path.self::GIT_SEPARATOR.self::COMPOSER.self::EXTENSION_LOCK; |
There was a problem hiding this comment.
Previously there was a GIT_SEPARATOR strpos() check. Is it replaced by trial and error instead to better handle Windows absolute paths?
Summary
When comparing against a
composer.lockthat doesn't exist yet (e.g. a path on a branch where no lockfile has been committed), the diff now treats it as an empty lockfile ({}) instead of throwing an error. All packages in the target are reported as new installs.This covers two scenarios:
composer.lockfile but doesn't exist on disk (e.g.composer diff /new/project/composer.lock composer.lock)composer diff HEAD:new-dir/composer.lock)Motivation
We use composer-bin to manage tooling in separate directories away from the main
composer.json/composer.lock. When a new tool directory is introduced on a branch, there is no correspondingcomposer.lockon the base branch yet. Runningcomposer diffagainst that non-existing base lockfile currently throws an error, making it impossible to review the newly added dependencies.Changes
composer.lockpaths by returning{}instead of falling through to gitgit showand return{}instead of throwing