Add git hook that runs uncrustify before commits.
Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/commit/fe04a361 Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/tree/fe04a361 Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/diff/fe04a361 Branch: refs/heads/master Commit: fe04a3617057251dde9cefb72a19baec3fb2ae1a Parents: 934062a Author: Andrew Grieve <agri...@chromium.org> Authored: Fri Aug 31 12:24:50 2012 -0400 Committer: Andrew Grieve <agri...@chromium.org> Committed: Tue Sep 18 09:53:36 2012 -0400 ---------------------------------------------------------------------- hooks/pre-commit | 41 +++++++++++++++++++++++++++++++++++++++++ 1 files changed, 41 insertions(+), 0 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/fe04a361/hooks/pre-commit ---------------------------------------------------------------------- diff --git a/hooks/pre-commit b/hooks/pre-commit new file mode 100755 index 0000000..f7395b5 --- /dev/null +++ b/hooks/pre-commit @@ -0,0 +1,41 @@ +#!/bin/bash + +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +# Redirect output to stderr. +exec 1>&2 + +RET=0 +files=$(bin/uncrustify.sh --filter $(git diff --cached --name-only)) +for file in $files; do + if ! bin/uncrustify.sh --check-file $file; then + echo "Style fix-ups required: $file. Please run: $PWD/bin/uncrustify.sh $PWD/$file && git add $PWD/$file" + RET=1 + fi +done + +if [[ $RET = 1 ]]; then + echo + echo "Commit aborted!" + echo "Run the commands above to fix your files before committing." + echo "Alternatively, run \"$PWD/bin/uncrustify.sh --staged\" and then re-stage affected files." +fi + +exit $RET +