From 07854bb9f0ac1ad5b5fad757395e04824c3fe9f3 Mon Sep 17 00:00:00 2001 From: Andreas Cord-Landwehr Date: Thu, 27 May 2021 16:37:24 +0200 Subject: Provide fallback error when no .clang-format file is present This check fixes a probably rare case, where we land in a repository that contains this clang-format.sh hook but where the format file went missing. In such cases, clang-format falls back to the system defaults, which brings undesired defaults, e.g. enforced line breaks in comments after 90 chars, which cannot easily be reverted by a reformat. Since clang-format's --fallback-style=none option is not available for git clang-format, this comment reimplements the logic. --- kde-modules/kde-git-commit-hooks/clang-format.sh | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'kde-modules/kde-git-commit-hooks') diff --git a/kde-modules/kde-git-commit-hooks/clang-format.sh b/kde-modules/kde-git-commit-hooks/clang-format.sh index d351e3cd..42a16a1d 100755 --- a/kde-modules/kde-git-commit-hooks/clang-format.sh +++ b/kde-modules/kde-git-commit-hooks/clang-format.sh @@ -4,6 +4,11 @@ readonly output=$(git clang-format -v --diff) +if [[ ! -f .clang-format ]]; then + echo "ERROR: no .clang-format file found in repository root, abort format" + echo " run cmake for this repository to generate it" + exit 1 +fi if [[ "$output" == *"no modified files to format"* ]]; then exit 0; fi if [[ "$output" == *"clang-format did not modify any files"* ]]; then exit 0; fi -- cgit v1.2.1