Skip to content

202 - Use Git Commit Hooks to Automatically Format Code Into Github Codebase#208

Open
agandbhir123 wants to merge 9 commits into
developfrom
202-feature--use-git-commit-hooks-to-automatically-format-code-into-github-codebase
Open

202 - Use Git Commit Hooks to Automatically Format Code Into Github Codebase#208
agandbhir123 wants to merge 9 commits into
developfrom
202-feature--use-git-commit-hooks-to-automatically-format-code-into-github-codebase

Conversation

@agandbhir123

Copy link
Copy Markdown
Contributor

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 Checks and Files changed tabs.
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.

  • All commits are tagged with the ticket number
  • No linting errors / newline at end of file warnings
  • All code follows repository-configured prettier formatting
  • No merge conflicts
  • All checks passing
  • Remove any non-applicable sections of this template
  • Assign the PR to yourself
  • Request reviewers & ping on Slack
  • PR is linked to the ticket (fill in the closes line below)

Closes #202

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 bracyw left a comment

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.

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)

Comment thread hooks/pre-commit Outdated
@@ -0,0 +1,30 @@
#!/bin/bash

# Find qmlformat dynamically

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.

this should be static, instead of auto find formatter. Also make sure it works with gitbash on windows.

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.

see @TheJeffreyKuo pr (will be updated soon) #207

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.

[Codebase] - Use Git Commit Hooks to Automatically Format Code Into Github Codebase

3 participants