Skip to content

Instantly share code, notes, and snippets.

@pulse00
Created February 14, 2013 12:09
Show Gist options
  • Save pulse00/4952380 to your computer and use it in GitHub Desktop.
Save pulse00/4952380 to your computer and use it in GitHub Desktop.
Simple git post-merge hook to check if your composer dependencies are in sync with the composer.lock file after merging a remote branch.
#!/usr/bin/env php
<?php
/**
* Simple git post-merge hook to check if your composer dependencies are in sync with the composer.lock file after merging a remote branch.
*
* Put this into a file called `post-merge` inside your `.git/hooks` directory and make it executable using `chmod +x .git/hooks/post-merge`.
*
* This script assumes you use the following Symfony components:
*
* - Console
* - Process
*/
require_once __DIR__ . '/../../vendor/autoload.php';
$output = new Symfony\Component\Console\Output\ConsoleOutput();
$output->writeln('Checking if your dependencies are in sync with <comment>composer.lock</comment>...');
$process = new Symfony\Component\Process\Process('./composer.phar install --dry-run --no-ansi', realpath(__DIR__ . '/../../'));
$process->run();
if (!$process->isSuccessful()) {
$output->writeln('Unable to determine dependency status, run <info>./composer.phar install</info> manually.');
exit();
}
if (strpos($process->getOutput(), 'Nothing to install or update') > 0) {
$output->writeln('Your composer dependencies are up to date.');
} else {
$output->writeln('Your composer dependencies are out of sync with the <comment>composer.lock</comment> file.');
$output->writeln('Run <info>./composer.phar install</info> to install the current versions of the dependencies.');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment