Skip to content

add instruction to add pre-commit clang-format hook#103

Open
xianshijing-lk wants to merge 1 commit intomainfrom
sxian/clang-format_pre-commit_hook
Open

add instruction to add pre-commit clang-format hook#103
xianshijing-lk wants to merge 1 commit intomainfrom
sxian/clang-format_pre-commit_hook

Conversation

@xianshijing-lk
Copy link
Copy Markdown
Collaborator

git does not track any file under .git/ folder, so we need to add some instruction for developers to setup their env manually

Comment thread README.md
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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏼

Comment thread README.md
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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there are some more automatic/elegant solutions, example: https://github.com/polymathrobotics/livekit_ros2_bridge/blob/main/.pre-commit-config.yaml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants