add instruction to add pre-commit clang-format hook#103
Open
xianshijing-lk wants to merge 1 commit intomainfrom
Open
add instruction to add pre-commit clang-format hook#103xianshijing-lk wants to merge 1 commit intomainfrom
xianshijing-lk wants to merge 1 commit intomainfrom
Conversation
stephen-derosa
approved these changes
Apr 17, 2026
| CPP SDK is using clang C++ format, and set up the pre-commit hook (run once): | ||
| ```bash | ||
| brew install clang-format | ||
| printf '#!/bin/sh\necho "Running clang-format..."\nFILES=$(git diff --cached --name-only -- "*.cpp" "*.cc" "*.h" "*.hpp")\n[ -z "$FILES" ] && exit 0\nfor f in $FILES; do clang-format -i "$f"; git add "$f"; done\necho "clang-format completed."\n' > .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit |
| CPP SDK is using clang C++ format, and set up the pre-commit hook (run once): | ||
| ```bash | ||
| brew install clang-format | ||
| printf '#!/bin/sh\necho "Running clang-format..."\nFILES=$(git diff --cached --name-only -- "*.cpp" "*.cc" "*.h" "*.hpp")\n[ -z "$FILES" ] && exit 0\nfor f in $FILES; do clang-format -i "$f"; git add "$f"; done\necho "clang-format completed."\n' > .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit |
Contributor
There was a problem hiding this comment.
As an alternative (or an addition), could we add this to the build scripts? I.e. check if the hook exists, then create it if not? That way we could have better enforcement
Contributor
There was a problem hiding this comment.
Looks like there are some more automatic/elegant solutions, example: https://github.com/polymathrobotics/livekit_ros2_bridge/blob/main/.pre-commit-config.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
git does not track any file under .git/ folder, so we need to add some instruction for developers to setup their env manually