Created
April 1, 2015 17:47
-
-
Save donatj/ad72578942801c85a197 to your computer and use it in GitHub Desktop.
Fast Patch Redux
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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