xref: /freebsd/contrib/libcbor/misc/hooks/pre-commit (revision b5b9517bfe394e55088f5a05882eabae7e9b7b29)
110ff414cSEd Maste#!/bin/sh
210ff414cSEd Maste
310ff414cSEd Masteset -e
410ff414cSEd Maste
5*b5b9517bSEd Maste# Run cmake-lint, clang-format, and add modified files
610ff414cSEd MasteMODIFIED_UNSTAGED=$(git -C . diff --name-only)
710ff414cSEd MasteMODIFIED_STAGED=$(git -C . diff --name-only --cached --diff-filter=d)
810ff414cSEd Maste
9*b5b9517bSEd MasteCMAKE_FILES=$(echo "${MODIFIED_STAGED} ${MODIFIED_UNSTAGED}" | grep -oE '(\S*)CMakeLists.txt' | cat)
10*b5b9517bSEd Masteif ! cmake-lint --line-width 140 ${CMAKE_FILES} > /dev/null; then
11*b5b9517bSEd Maste  echo "cmake-lint failed:"
12*b5b9517bSEd Maste  cmake-lint --line-width 140 ${CMAKE_FILES}
13*b5b9517bSEd Mastefi
14*b5b9517bSEd Maste
1510ff414cSEd Maste./clang-format.sh
1610ff414cSEd Maste
1710ff414cSEd Mastegit add ${MODIFIED_STAGED}
1810ff414cSEd Maste
1910ff414cSEd Masteif [[ ${MODIFIED_UNSTAGED} != $(git -C . diff --name-only) ]]; then
2010ff414cSEd Maste  echo "WARNING: Non-staged files were reformatted. Please review and/or add" \
2110ff414cSEd Maste    "them"
2210ff414cSEd Mastefi
2310ff414cSEd Maste
24