aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts
diff options
context:
space:
mode:
authorGravatar Paul Beusterien <paulbeusterien@google.com>2018-01-10 19:06:42 -0800
committerGravatar GitHub <noreply@github.com>2018-01-10 19:06:42 -0800
commit91ac9c069d429997848d34cad3f87649ef5a6cd5 (patch)
treef3f076c69a1ce5a2657dd84c5d2a0461338aa83d /scripts
parented671eee8cc7e3a7498aac3c23f5e0bcc35334d3 (diff)
Add test-only option to style.sh (#642)
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/style.sh19
1 files changed, 15 insertions, 4 deletions
diff --git a/scripts/style.sh b/scripts/style.sh
index 3e12d5a..72f7520 100755
--- a/scripts/style.sh
+++ b/scripts/style.sh
@@ -21,16 +21,22 @@
# Commonly
# ./scripts/style.sh master
-set -euo pipefail
-
if [[ $(clang-format --version) != **"version 6"** ]]; then
echo "Please upgrade to clang-format version 6."
echo "If it's installed via homebrew you can run: brew upgrade clang-format"
exit 1
fi
+if [[ $# -gt 0 && "$1" = "test-only" ]]; then
+ test_only=true
+ options="-output-replacements-xml"
+else
+ test_only=false
+ options="-i"
+fi
+
(
- if [[ $# -gt 0 ]]; then
+ if [[ "$test_only" = false && $# -gt 0 ]]; then
if git rev-parse "$1" -- >& /dev/null; then
# Argument was a branch name show files changed since that branch
git diff --name-only --relative "$1"
@@ -59,4 +65,9 @@ fi
# Format C-ish sources only
\%\.(h|m|mm|cc)$% p
-' | xargs clang-format -style=file -i
+' | xargs clang-format -style=file $options | grep "<replacement " > /dev/null
+
+if [[ "$test_only" = true && $? -ne 1 ]]; then
+ echo "Proposed commit is not style compliant. Run scripts/style.sh and git add the result."
+ exit 1
+fi