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