-
-
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
base: main
Are you sure you want to change the base?
Changes from 4 commits
419f26e
539134b
9770082
aa396a3
aed5d9a
1c00577
d0f43cf
bff2d6c
d3acfd4
ff80f08
348ff62
cb7245a
17254ac
38f435d
a3f0dd5
d1f2687
2db003e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| #!/bin/bash | ||
| set -e | ||
|
cursor[bot] marked this conversation as resolved.
|
||
|
|
||
| echo "🔍 Checking code formatting..." | ||
|
|
||
| # Stash unstaged changes (keep staged changes in working tree) | ||
| # This ensures we only check formatting on what's being committed | ||
| STASH_NAME="pre-commit-$(date +%s)" | ||
| git stash push --keep-index --quiet --message "$STASH_NAME" || true | ||
|
|
||
| # Run dotnet format (matches CI command exactly) | ||
| dotnet format Sentry.slnx --no-restore \ | ||
| --exclude ./modules ./**/*OptionsSetup.cs ./test/Sentry.Tests/AttributeReaderTests.cs > /dev/null 2>&1 | ||
|
Check failure on line 13 in .githooks/pre-commit
|
||
|
sentry-warden[bot] marked this conversation as resolved.
Outdated
sentry-warden[bot] marked this conversation as resolved.
Outdated
jamescrosswell marked this conversation as resolved.
Outdated
sentry-warden[bot] marked this conversation as resolved.
Outdated
jamescrosswell marked this conversation as resolved.
Outdated
|
||
|
|
||
| # Check if dotnet format made any changes | ||
| FORMAT_CHANGED=false | ||
| if ! git diff --quiet; then | ||
|
sentry-warden[bot] marked this conversation as resolved.
Outdated
|
||
| FORMAT_CHANGED=true | ||
| fi | ||
|
Check failure on line 19 in .githooks/pre-commit
|
||
|
|
||
| # Restore unstaged changes | ||
| if git stash list | grep -q "$STASH_NAME"; then | ||
| git stash pop --quiet 2>/dev/null || true | ||
| fi | ||
|
Check warning on line 24 in .githooks/pre-commit
|
||
|
sentry-warden[bot] marked this conversation as resolved.
Outdated
|
||
|
|
||
| # If formatting changes were detected, fail the commit | ||
| if [ "$FORMAT_CHANGED" = true ]; then | ||
| 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 | ||
| 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 "" |
Uh oh!
There was an error while loading. Please reload this page.