首页 > 其他分享 >clang-format

clang-format

时间:2024-05-28 19:22:54浏览次数:33  
标签:git format -- clang file diff

format diff

git diff -U0 HEAD^ | clang-format-diff-16 -p1 -i

git hook
.git/hooks/pre-commit

#!/bin/bash

STYLE=$(git config --get hooks.clangformat.style)
if [ -n "${STYLE}" ] ; then
  STYLEARG="-style=${STYLE}"
else
  STYLEARG=""
fi

format_file() {
  file="${1}"
  if [ -f $file ]; then
    clang-format -i ${STYLEARG} ${1}
    git add ${1}
  fi
}

case "${1}" in
  --about )
    echo "Runs clang-format on source files"
    ;;
  * )
    for file in `git diff-index --cached --name-only HEAD | grep -iE '\.(cpp|cc|h|hpp)$' ` ; do
      format_file "${file}"
    done
    ;;
esac

标签:git,format,--,clang,file,diff
From: https://www.cnblogs.com/stdpain/p/18218671

相关文章