Skip to content

Instantly share code, notes, and snippets.

@kerbyfc
Last active August 29, 2015 14:18
Show Gist options
  • Save kerbyfc/28c41e6109526f0611de to your computer and use it in GitHub Desktop.
Save kerbyfc/28c41e6109526f0611de to your computer and use it in GitHub Desktop.
Small php script create file-separated patches with git
#!/usr/bin/env php
<?php
# usage: ./patch kerbyfc origin/devel 'json|yml|js|html|yaml|rb|Gemfile|lock|coffee|png|jpg|ico|gif|txt|scss|css|stylus|cfg|md|map$'
$auth = $argv[1];
$to = $argv[2];
$grep = $argv[3];
$preview_only = $argv[4];
$cmd = "git diff --name-only --author='$auth' $to HEAD | grep -E '$grep'";
exec($cmd, $files, $returnGit);
if ($preview_only) {
var_dump($files);
var_dump($cmd);
} else {
if ($returnGit == 0) {
$mdReturn = 0;
$csReturn = 0;
$mdErrors = [];
$csErrors = [];
foreach ($files as $file) {
if (!file_exists($file)) {
echo $file, PHP_EOL;
continue;
}
$i = strripos($file, "/");
$path = substr($file, 0, $i);
exec(
"git format-patch $to '$file' --output-directory=$path",
$csErrors,
$csReturnOne
);
}
echo $csVersion, PHP_EOL, trim(implode(PHP_EOL, $csErrors));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment