xref: /xnu-11417.140.69/tools/pre-commit.sh (revision 43a90889846e00bfb5cf1d255cdc0a701a1e05a4)
1*43a90889SApple OSS Distributions#!/bin/sh
2*43a90889SApple OSS Distributionsset -e
3*43a90889SApple OSS Distributions
4*43a90889SApple OSS Distributions# Abort a commit if the code style is incorrect.
5*43a90889SApple OSS Distributions
6*43a90889SApple OSS Distributions# Get a list of paths with staged changes.
7*43a90889SApple OSS DistributionsFILES=$(git diff --staged --name-only --diff-filter=d)
8*43a90889SApple OSS Distributions# Check the paths for style issues.
9*43a90889SApple OSS DistributionsRESULT=0
10*43a90889SApple OSS Distributionsif [ ! -z "$FILES" ]; then
11*43a90889SApple OSS Distributions    # Stash any unstaged changes.
12*43a90889SApple OSS Distributions    git stash --quiet --keep-index
13*43a90889SApple OSS Distributions    ./tools/uncrustify.sh $FILES || RESULT=$?
14*43a90889SApple OSS Distributions    # Restore the unstaged changes.
15*43a90889SApple OSS Distributions    git stash pop --quiet
16*43a90889SApple OSS Distributionsfi
17*43a90889SApple OSS Distributionsexit $RESULT
18