diff --git a/scripts/dev/format_pull_request.php b/scripts/dev/format_pull_request.php new file mode 100644 index 0000000000000..7b2e23e5ceb79 --- /dev/null +++ b/scripts/dev/format_pull_request.php @@ -0,0 +1,86 @@ + 'WebKit', + 'UseTab' => 'ForIndentation', + // clang-format's support for tabs isn't great, and we have to say "4 spaces" to get 1 tab + 'IndentWidth' => 4, + 'TabWidth' => 4, +); +$cmd = array( + 'git diff -U0 --no-color --relative HEAD^ |', + 'clang-format-diff -i -p1 -style=' . escapeshellarg(json_encode($clangFormatOptions)), + '-iregex=' . escapeshellarg('.*\.(c|cc|cpp|c\+\+|cxx|h|hh|hpp|h\+\+|h)$'), +); +$cmd = implode(' ', $cmd); +passthru($cmd, $ret); +if ($ret !== 0) { + fwrite(STDERR, "Error: clang-format-diff failed with exit code {$ret}\n"); + fwrite(STDERR, "cmd:\n{$cmd}\n"); + if (!$force) { + // remove last commit and reset + passthru('git reset --hard HEAD^ --quiet'); + } + exit(1); +} +passthru('git diff'); +if (!$force) { + // remove last commit and reset + passthru('git reset --hard HEAD^ --quiet'); +}