You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 4, 2025. It is now read-only.
Alternatively look into a pre-commit framework such as pre-commit which makes it easier to manage these hooks. An example hook for clang-format is at clang-format-precommit.
This script will automatically run clang-format on all changed files in a commit when set as a pre-commit hook. Proceed with caution.
Warning
Do not use this on an existing codebase that isn't already in your desired style. Doing so will lead to a string a dirty commits where your code changes are intermixed with clang-format's formatting changes.
Furthermore, every developer will need to install this hook. If they don't, you will again end up with commits with a mixture of code and formatting changes.
Installation
First, verify that clang-format is installed. On Linux this should be included with the regular clang package. For MacOSX with Homebrew, clang-format is available via brew install clang-format.
Now install clang-format.hook from this repository into your repo's .git/hooks. If you don't already have a pre-commit hook, you can simply copy clang-format.hook to .git/hooks/pre-commit. For example:
Once the pre-commit hook is installed, clang-format will be run on each file included in the commit when you run git commit.
By default, clang-format uses the LLVM style. To change this, either create a .clang-format file with your desired format in the top level of your repo, or set the hooks.clangformat.style config option in your repo. The .clang-format file method is preferred if you will be working with a team or will be doing any major customizations to the style.
You can generate the .clang-format file from your desired style (here, llvm) using: