-
-
Notifications
You must be signed in to change notification settings - Fork 231
Add optional pre-commit hook for code formatting #5178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jamescrosswell
wants to merge
17
commits into
main
Choose a base branch
from
feature/pre-commit-formatting-hooks
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
419f26e
Add optional pre-commit hook for code formatting verification
jamescrosswell 539134b
Fix pre-commit hook to use dotnet format exit code
jamescrosswell 9770082
Suppress CA2255 in test projects
jamescrosswell aa396a3
Match pre-commit hook to CI formatting behavior
jamescrosswell aed5d9a
fix(pre-commit): ensure stashed changes are always restored
jamescrosswell 1c00577
fix(pre-commit): improve stash conflict guidance
jamescrosswell d0f43cf
simplify(pre-commit): remove stash logic
jamescrosswell bff2d6c
feat(dev): add setup-hooks command
jamescrosswell d3acfd4
remove: scripts/setup-hooks.sh
jamescrosswell ff80f08
fix(pre-commit): scope dotnet format to staged files only
jamescrosswell 348ff62
fix(pre-commit): guard against grep exit code when no C# files staged
jamescrosswell cb7245a
feat(dev): add remove-hooks command
jamescrosswell 17254ac
fix(pre-commit): handle file paths with spaces correctly
jamescrosswell 38f435d
fix(pre-commit): skip format check when unstaged changes are present
jamescrosswell a3f0dd5
docs(contributing): update git hooks setup instructions
jamescrosswell d1f2687
fix(pre-commit): show dotnet format output on failure
jamescrosswell 2db003e
fix(gitattributes): enforce LF line endings for .githooks/
jamescrosswell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| #!/bin/bash | ||
| set -e | ||
|
cursor[bot] marked this conversation as resolved.
|
||
|
|
||
| echo "🔍 Checking code formatting..." | ||
|
|
||
| # Run dotnet format in verify mode (check only, don't modify) | ||
| # This matches the CI command exactly | ||
| if dotnet format Sentry.slnx --verify-no-changes --no-restore \ | ||
| --exclude ./modules ./**/*OptionsSetup.cs ./test/Sentry.Tests/AttributeReaderTests.cs 2>&1 | grep -q "formatted"; then | ||
|
Check warning on line 9 in .githooks/pre-commit
|
||
|
sentry-warden[bot] marked this conversation as resolved.
Outdated
|
||
|
|
||
| echo "" | ||
| echo "❌ Code formatting issues found!" | ||
| echo "" | ||
| echo "Please run the following command to fix formatting:" | ||
| echo "" | ||
| echo " dotnet format Sentry.slnx --no-restore --exclude ./modules ./**/*OptionsSetup.cs ./test/Sentry.Tests/AttributeReaderTests.cs" | ||
| echo "" | ||
| echo "Then stage the changes and commit again:" | ||
| echo "" | ||
| echo " git add -u" | ||
|
sentry-warden[bot] marked this conversation as resolved.
|
||
| echo " git commit" | ||
| echo "" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "✅ Code formatting looks good!" | ||
| exit 0 | ||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| #!/bin/bash | ||
| set -e | ||
|
|
||
| echo "Setting up git hooks..." | ||
|
|
||
| # Configure git to use .githooks directory for hooks | ||
| git config core.hooksPath .githooks | ||
|
|
||
| echo "" | ||
| echo "✅ Git hooks configured successfully!" | ||
| echo "" | ||
| echo "The pre-commit hook will now verify code formatting before each commit." | ||
| echo "To bypass the hook for a specific commit, use: git commit --no-verify" | ||
| echo "" |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.