Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
27 changes: 27 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash
Comment thread
cursor[bot] marked this conversation as resolved.
set -e
Comment thread
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

View check run for this annotation

@sentry/warden / warden: code-review

Hook ignores dotnet format exit code and relies on fragile grep for "formatted"

The hook pipes `dotnet format --verify-no-changes` output through `grep -q "formatted"` to decide pass/fail, discarding the tool's actual exit code. If `dotnet format` fails for an unrelated reason (e.g., restore needed, SDK/workload missing, project load error) and its error output does not contain the word "formatted", the hook will silently report success and allow the commit. Conversely, benign output containing the substring "formatted" could cause false failures. The CI workflow relies on `--verify-no-changes`'s non-zero exit code, so the hook diverges from CI behavior despite the comment claiming otherwise.

Check failure on line 9 in .githooks/pre-commit

View check run for this annotation

@sentry/warden / warden: find-bugs

`set -e` combined with piped grep causes hook to silently pass on dotnet format errors

The script uses `set -e` but the formatting check uses a pipeline `dotnet format ... | grep -q "formatted"`. If `dotnet format` fails for any reason (e.g., restore issues, tool not installed, invalid args), grep won't find "formatted" and the `if` branch is skipped, causing the hook to print '✅ Code formatting looks good!' and exit 0. This means real formatting violations or tool failures can be silently bypassed, defeating the purpose of the pre-commit hook and allowing unformatted code to be committed.
Comment thread
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"
Comment thread
sentry-warden[bot] marked this conversation as resolved.
echo " git commit"
echo ""
exit 1
fi

echo "✅ Code formatting looks good!"
exit 0
18 changes: 18 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,24 @@ For a big feature it's advised to raise an issue to discuss it first.
* To quickly get up and running, you can just run `dotnet build SentryNoMobile.slnf` (you're skipping the mobile targets)
* To run a full build in Release mode and test, before pushing, run `./build.sh` or `./build.cmd`

## Git Hooks (Optional but Recommended)

To automatically verify code formatting before committing, you can set up a pre-commit hook:

```bash
./scripts/setup-hooks.sh
```
Comment thread
sentry[bot] marked this conversation as resolved.

This configures git to run `dotnet format --verify-no-changes` before each commit. If formatting issues are found, the commit will be prevented and you'll need to run:
Comment thread
sentry[bot] marked this conversation as resolved.
Outdated

```bash
dotnet format Sentry.slnx --no-restore --exclude ./modules ./**/*OptionsSetup.cs ./test/Sentry.Tests/AttributeReaderTests.cs
```

Then stage the formatting changes and commit again. This helps catch formatting issues early and reduces CI failures.

**Note:** You can bypass the hook for a specific commit using `git commit --no-verify` if needed.

## Minimal Dependencies

* The latest versions of the following .NET SDKs:
Expand Down
14 changes: 14 additions & 0 deletions scripts/setup-hooks.sh
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 ""
Loading