Run lints at pre-commit

Install a hook to run lints at pre-commit to force issues to be fixed
during development.

This introduces a 5-10 second delay when committing due to how slow
clang-format is.

Signed-off-by: Tim Crawford <tcrawford@system76.com>
This commit is contained in:
Tim Crawford
2023-01-09 10:38:48 -07:00
committed by Jeremy Soller
parent 1aadc68257
commit 58f9ed4051
3 changed files with 15 additions and 0 deletions

View File

@ -76,3 +76,8 @@ clean:
.PHONY: lint .PHONY: lint
lint: lint:
./scripts/lint/lint.sh ./scripts/lint/lint.sh
.PHONY: git-config
git-config:
$(eval HOOKS = "$(shell git rev-parse --git-dir)/hooks")
ln -sfrv scripts/hooks/pre-commit.sh "$(HOOKS)/pre-commit"

View File

@ -66,6 +66,9 @@ fi
msg "Initializing submodules" msg "Initializing submodules"
git submodule update --init --recursive git submodule update --init --recursive
msg "Installing git hooks"
make git-config
RUSTUP_NEW_INSTALL=0 RUSTUP_NEW_INSTALL=0
if which rustup &> /dev/null; then if which rustup &> /dev/null; then
msg "Updating rustup" msg "Updating rustup"

7
scripts/hooks/pre-commit.sh Executable file
View File

@ -0,0 +1,7 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: GPL-3.0-only
make lint 2>/dev/null || {
echo -e "\nissues found, not committing"
exit 1
}