From 58f9ed4051ecea7994580e2d7493198782b5b1a0 Mon Sep 17 00:00:00 2001 From: Tim Crawford Date: Mon, 9 Jan 2023 10:38:48 -0700 Subject: [PATCH] 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 --- Makefile | 5 +++++ scripts/deps.sh | 3 +++ scripts/hooks/pre-commit.sh | 7 +++++++ 3 files changed, 15 insertions(+) create mode 100755 scripts/hooks/pre-commit.sh diff --git a/Makefile b/Makefile index a4a0a0c..1ebba7d 100644 --- a/Makefile +++ b/Makefile @@ -76,3 +76,8 @@ clean: .PHONY: lint lint: ./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" diff --git a/scripts/deps.sh b/scripts/deps.sh index c12e16b..0900796 100755 --- a/scripts/deps.sh +++ b/scripts/deps.sh @@ -66,6 +66,9 @@ fi msg "Initializing submodules" git submodule update --init --recursive +msg "Installing git hooks" +make git-config + RUSTUP_NEW_INSTALL=0 if which rustup &> /dev/null; then msg "Updating rustup" diff --git a/scripts/hooks/pre-commit.sh b/scripts/hooks/pre-commit.sh new file mode 100755 index 0000000..0221520 --- /dev/null +++ b/scripts/hooks/pre-commit.sh @@ -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 +}