Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
# - trailing-whitespace: Removes trailing whitespace from lines
# (preserves Markdown hard line breaks with --markdown-linebreak-ext=md)
# - end-of-file-fixer: Ensures files end with exactly one newline
# - git-clang-format-fix: Applies clang-format to staged C/C++/CUDA files (only the diff)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add a note that it will use the .clang-format file in the root? Also what will happen if git-clang-format is not installed?

#
# Note:
# - The git-clang-format-fix hook will re-stage any changes it makes. After it runs, you will need to review the changes and re-run your commit.
# - The git-clang-format-fix can be disabled by setting SKIP=git-clang-format-fix=1 in your environment, eg. `SKIP=git-clang-format-fix=1 git commit -m "Your commit message"`

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand All @@ -40,3 +44,30 @@ repos:
- id: end-of-file-fixer
types_or: [c, c++, python, shell, yaml, cmake, markdown, text]
exclude: '^(build/|\.git/)'
- repo: local
hooks:
- id: git-clang-format-fix
name: git-clang-format (diff-only, auto-fix)
entry: |
bash -c '
Copy link
Member

Choose a reason for hiding this comment

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

there should be no need for bash. I would rather use sh.

# First check if anything needs formatting
if git clang-format --staged --diff --quiet; then
# No changes needed
exit 0
fi

echo "[git-clang-format] Applying formatting to staged changes..."
git clang-format --staged
# Re-add anything the formatter touched
git add -A
Copy link
Contributor

Choose a reason for hiding this comment

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

This will stage everything in the repo, right? We should not add back files that were not staged originally.


echo
echo "[git-clang-format] Changes have been applied."
echo "Please review and re-run your commit."
echo
# Force user to re-run commit so they see the changes
exit 1
'
language: system
types_or: [c++, c, cuda]
pass_filenames: false