From 79caa00d0949138b237ecced794a903237bcf2b5 Mon Sep 17 00:00:00 2001 From: Alexander Lohnau Date: Sat, 30 Apr 2022 08:57:26 +0200 Subject: KDEGitCommitHooks: Check if KDEClangFormat was included If the module is not included, the current message would be misleading. Including the module by default is undesirable, because we print out a warning that we do not override an existing module. While this warning is reasonable in most cases, it is annoying for projects that have a custom clang-format file. Checking if a .clang-format file exists and if not including KDEClangFormat is fragile, because it depends on the include order of the modules. Considering all that, a proper warning with instructions on how to fix the issue is IMHO the best way to go. --- kde-modules/kde-git-commit-hooks/clang-format.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (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 3e072768..6b6233eb 100755 --- a/kde-modules/kde-git-commit-hooks/clang-format.sh +++ b/kde-modules/kde-git-commit-hooks/clang-format.sh @@ -5,8 +5,14 @@ readonly output=$(git clang-format --extensions 'cpp,h,hpp,c' -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" + if [[ @HAS_CLANG_FORMAT_COMMAND_INCLUDED@ = TRUE ]]; then + echo "ERROR: no .clang-format file found in repository root, abort format" + echo " run cmake for this repository to generate it" + else + echo "ERROR: no .clang-format file found in repository root, abort format" + echo "Make sure the KDEClangFormat CMake module is included, which will copy the KDE .clang-format file during the CMake configuration." + echo "Alternatively you can manually copy a .clang-format file to the repository root directory." + fi exit 1 fi if [[ "$output" == *"no modified files to format"* ]]; then exit 0; fi -- cgit v1.2.1