Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
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
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ dotnet_diagnostic.IL2026.severity = none
dotnet_diagnostic.IL2070.severity = none
dotnet_diagnostic.IL2075.severity = none
dotnet_diagnostic.IL2090.severity = none
dotnet_diagnostic.CA2255.severity = none

# This appears to be broken and results in false positives (causing dotnet format to delete valid test scenarios)
dotnet_diagnostic.xUnit1025.severity = none
44 changes: 44 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/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..."

# 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

View check run for this annotation

@sentry/warden / warden: find-bugs

`set -e` plus failed `dotnet format` causes silent abort leaving stash unrestored

With `set -e` at the top, if `dotnet format` exits non-zero (e.g., compile error, missing SDK, network issue during restore), the script terminates immediately at line 12. The stash pop on lines 22-24 is never reached, leaving the developer's unstaged changes trapped in the stash with a confusing name. The user sees no error message because stdout/stderr are redirected to `/dev/null`.

Check warning on line 13 in .githooks/pre-commit

View check run for this annotation

@sentry/warden / warden: find-bugs

Glob pattern `./**/*OptionsSetup.cs` is shell-expanded before being passed to dotnet format

Bash will expand `./**/*OptionsSetup.cs` (with globstar potentially disabled) and `./modules` before invoking `dotnet format`. Without `shopt -s globstar`, `**` is treated as `*`, so the exclude argument passed to dotnet format may not match the intended files. Additionally, multiple matched files become multiple positional arguments, which `--exclude` may not accept. This means CI and the hook can diverge in what files they exclude, defeating the stated goal of matching CI exactly.

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

View check run for this annotation

@sentry/warden / warden: code-review

Stashed unstaged changes are lost if `dotnet format` fails due to `set -e`

The script uses `set -e` at the top, then stashes unstaged changes before running `dotnet format`. If `dotnet format` exits non-zero (e.g., build/compilation error, invalid project state), `set -e` causes immediate script termination, skipping the `git stash pop` block entirely. The developer's unstaged work-in-progress changes remain in the stash with no notification, appearing lost. This is a data-loss risk and unintended side effect on every commit attempt where formatting tooling errors occur.

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

View check run for this annotation

@sentry/warden / warden: code-review

[VK8-BG5] Stashed unstaged changes are lost if `dotnet format` fails due to `set -e` (additional location)

The script uses `set -e` at the top, then stashes unstaged changes before running `dotnet format`. If `dotnet format` exits non-zero (e.g., build/compilation error, invalid project state), `set -e` causes immediate script termination, skipping the `git stash pop` block entirely. The developer's unstaged work-in-progress changes remain in the stash with no notification, appearing lost. This is a data-loss risk and unintended side effect on every commit attempt where formatting tooling errors occur.
Comment thread
sentry-warden[bot] marked this conversation as resolved.
Outdated
Comment thread
sentry-warden[bot] marked this conversation as resolved.
Outdated
Comment thread
jamescrosswell marked this conversation as resolved.
Outdated
Comment thread
sentry-warden[bot] marked this conversation as resolved.
Outdated
Comment thread
jamescrosswell marked this conversation as resolved.
Outdated

# Check if dotnet format made any changes
FORMAT_CHANGED=false
if ! git diff --quiet; then
Comment thread
sentry-warden[bot] marked this conversation as resolved.
Outdated
FORMAT_CHANGED=true
fi

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

View check run for this annotation

@sentry/warden / warden: find-bugs

[96D-DV3] `set -e` plus failed `dotnet format` causes silent abort leaving stash unrestored (additional location)

With `set -e` at the top, if `dotnet format` exits non-zero (e.g., compile error, missing SDK, network issue during restore), the script terminates immediately at line 12. The stash pop on lines 22-24 is never reached, leaving the developer's unstaged changes trapped in the stash with a confusing name. The user sees no error message because stdout/stderr are redirected to `/dev/null`.

# 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

View check run for this annotation

@sentry/warden / warden: find-bugs

Stash pop conflict can leave repository in inconsistent state without notifying developer

On line 23, `git stash pop --quiet 2>/dev/null || true` swallows any conflict that occurs when reapplying unstaged changes. If `dotnet format` modified files that the developer also had unstaged edits to, the pop will conflict and leave the stash in place — but the script reports success (or the formatting failure) and never tells the developer their unstaged work is still stashed.

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

View check run for this annotation

@sentry/warden / warden: code-review

[VK8-BG5] Stashed unstaged changes are lost if `dotnet format` fails due to `set -e` (additional location)

The script uses `set -e` at the top, then stashes unstaged changes before running `dotnet format`. If `dotnet format` exits non-zero (e.g., build/compilation error, invalid project state), `set -e` causes immediate script termination, skipping the `git stash pop` block entirely. The developer's unstaged work-in-progress changes remain in the stash with no notification, appearing lost. This is a data-loss risk and unintended side effect on every commit attempt where formatting tooling errors occur.
Comment thread
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"
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