202 - Use Git Commit Hooks to Automatically Format Code Into Github Codebase#208
Open
agandbhir123 wants to merge 9 commits into
Conversation
CPP_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.(cpp|h)$')
QML_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.qml$')
for FILE in $CPP_FILES; do
clang-format -i "$FILE"
git add "$FILE"
done
for FILE in $QML_FILES; do
qmlformat -i "$FILE"
git add "$FILE"
done
exit 0
EOFRevert "Test commit hook"
This reverts commit 183a2ba.
bracyw
requested changes
Mar 29, 2026
bracyw
left a comment
Contributor
There was a problem hiding this comment.
some changes you can wait for #207 to be finished and then update the bash on this to be more simple. you may be able to bake in the hooks to the project instead of users having to add them (you'll have to check online though)
| @@ -0,0 +1,30 @@ | |||
| #!/bin/bash | |||
|
|
|||
| # Find qmlformat dynamically | |||
Contributor
There was a problem hiding this comment.
this should be static, instead of auto find formatter. Also make sure it works with gitbash on windows.
Contributor
There was a problem hiding this comment.
see @TheJeffreyKuo pr (will be updated soon) #207
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.
Changes
Added git hook that automatically formats staged files before committing. Uses clang-format for .cpp and .h files and qmlformat for .qml files. Also added an install-hooks.sh script for easy setup.
Notes
You need to run ./hooks/install-hooks.sh from the repo root to install the hook.
Checklist
It can be helpful to check the
ChecksandFiles changedtabs.Please review the contributor guide and reach out to your Tech Lead if anything is unclear.
Please request reviewers and ping on slack only after you've gone through this whole checklist.
Closes #202