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