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


沒有留言:

張貼留言

2023 Promox on Morefine N6000 16GB 512GB

2023 Promox on Morefine N6000 16GB 512GB Software Etcher 100MB (not but can be rufus-4.3.exe 1.4MB) Proxmox VE 7.4 ISO Installer (1st ISO re...