Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Fast Patch Redux
#!/usr/bin/env php
<?php
if( count($argv) < 3 ) {
echo "Requires at least two arguments\n";
die(1);
}
$dir = realpath($argv[1]);
if( !is_dir($dir) ) {
echo "{$dir} is not a directory\n";
die(1);
}
if( !is_dir($dir . '/.git') ) {
echo "{$dir} is not a git repo\n";
die(1);
}
$refs = array_slice($argv, 2);
$patch_files = [ ];
foreach( $refs as $ref ) {
$fn = tempnam(sys_get_temp_dir(), "fastpatch");
exec('git format-patch --stdout ' . escapeshellarg($ref) . '^..' . escapeshellarg($ref) . ' -- > ' . escapeshellcmd($fn), $output, $return);
if( $return ) {
echo "\nError generating patch for {$ref}\n";
die(1);
}
$patch_files[$ref] = $fn;
}
chdir($dir);
foreach( $patch_files as $ref => $patch ) {
exec('git am --reject --whitespace=fix < ' . escapeshellcmd($patch), $output, $return);
if( $return ) {
`git am --abort`;
echo "\nError applying patch {$patch} for {$ref}\n";
die(1);
}
echo "Applied patch {$patch} ref {$ref}:";
}
shell_exec('git log -n ' . count($patch_files));
echo "\n\nDone!\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.