Skip to content
Advertisement

How to test if composer.lock is up to date?

During development (multiple people in the team) sometimes composer install returns:

Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. Run update to update them.

Is there a way to check for this very quickly (in milliseconds, without making any changes)?

I understand how composer works. However when code merges in it doesn’t necessarily cause merge conflicts on the composer.json or composer.lock file and it’s not fun to run composer install all the time when theres almost never any changes and that command takes several minutes.

If I’m able to quick test if the lock fail has fallen out of sync I can build it into the bash environment to notify every command. Similar to how people like their git status to be built into their bash prompt.

Further more this makes sense in CI to make sure it does sneak it’s way into the stable branch.

Advertisement

Answer

For composer < 1.3.0

Extending from @Domster, the solution in pure bash:

COMPOSER_IN_SYNC=$(expr "`cat composer.lock | grep '"hash":' | cut -d'"' -f4`" = "`md5sum composer.json | cut -d ' ' -f 1`")

$COMPOSER_IN_SYNC will be 0 or 1 respectively.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement