2022年11月3日 星期四

clang-format-10 Ubuntu 20.04 pre-commit hook

https://stackoverflow.com/questions/55965712/how-do-i-add-clang-formatting-to-pre-commit-hook


system

cat /etc/*release

DISTRIB_ID=Ubuntu

DISTRIB_RELEASE=20.04

DISTRIB_CODENAME=focal

DISTRIB_DESCRIPTION="Ubuntu 20.04.4 LTS"


install

clang-format --version

clang-format version 10.0.0-4ubuntu1 


hook (dont use)

I'm adding the following to the top of my REPO_ROOT/.git/hooks/pre-commit file:

for FILE in $(git diff --cached --name-only)
do
        clang-format -i $FILE
done 

The .clang-format file is placed in the REPO_ROOT. 


chmod a+x pre-commit




hook (use)

#!/usr/bin/env bash

for FILE in *

do

    if [[ "$FILE" =~ \.(c|h|cpp|cc)$ ]]

    then

        echo "processing $FILE"

        clang-format -i $FILE

    else

        echo "skip $FILE"

    fi

done


沒有留言:

張貼留言

2007 to 2023 HP and Dell Servers Comparison

  HP Gen5 to Gen11  using ChatGPT HP ProLiant Gen Active Years CPU Socket Popular HP CPUs Cores Base Clock Max RAM Capacity Comparable Dell ...