Skip to content

Instantly share code, notes, and snippets.

@donatj
Created April 1, 2015 17:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save donatj/ad72578942801c85a197 to your computer and use it in GitHub Desktop.
Save donatj/ad72578942801c85a197 to your computer and use it in GitHub Desktop.
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