Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
45 changes: 45 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hook may break on Windows checkouts

Medium Severity

pre-commit is an extensionless Bash script, while the repo only forces LF endings for *.sh. Windows checkouts with core.autocrlf can write CRLF here, making the shebang fail before the hook runs.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit d1f2687. Configure here.

set -e
Comment thread
cursor[bot] marked this conversation as resolved.

echo "🔍 Checking code formatting..."

if ! git diff --quiet; then
echo "⚠️ Skipping format check: unstaged changes present."
echo " Stage or stash all changes before committing to enable the format check."
exit 0
fi

INCLUDE_ARGS=()
while IFS= read -r f; do
INCLUDE_ARGS+=(--include "$f")
done < <(git diff --cached --name-only --diff-filter=ACM | grep '\.cs$' || true)

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

View check run for this annotation

@sentry/warden / warden: find-bugs

Staged filenames passed unquoted to dotnet format via --include

The hook reads staged .cs file names from `git diff --cached --name-only` and appends them to INCLUDE_ARGS. While each filename is passed as a separate array element (avoiding shell word-splitting), filenames containing spaces, glob characters, or leading dashes are forwarded directly to `dotnet format --include`. A maliciously crafted filename (e.g., starting with `--`) staged in a feature branch could be interpreted as an option to dotnet format, potentially altering behavior. There is no `--` separator before the file list to disambiguate.
Comment thread
jamescrosswell marked this conversation as resolved.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hook blocks non-solution C# files

Medium Severity

pre-commit sends every staged *.cs path to dotnet format Sentry.slnx --include. Files outside Sentry.slnx, such as dev.cs, make dotnet format fail, so hook users cannot commit those valid repo files without bypassing the hook.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit d1f2687. Configure here.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed files skip formatting

Low Severity

--diff-filter=ACM omits staged renames, so a .cs file renamed with edits never reaches dotnet format. The hook can pass while committing unformatted renamed C# files, leaving CI to catch the formatting failure.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit d1f2687. Configure here.


if [ ${#INCLUDE_ARGS[@]} -eq 0 ]; then
echo "✅ No C# files staged."
exit 0
fi

FORMAT_OUTPUT=$(dotnet format Sentry.slnx --no-restore \
"${INCLUDE_ARGS[@]}" \
--exclude ./modules ./**/*OptionsSetup.cs ./test/Sentry.Tests/AttributeReaderTests.cs 2>&1) || {
echo ""
echo "❌ dotnet format failed:"
echo "$FORMAT_OUTPUT"
echo ""
exit 1
}

if ! git diff --quiet; then
echo ""
echo "❌ Code formatting issues found!"
echo ""
echo "Please stage the formatting fixes 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
25 changes: 25 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,31 @@ 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 check and fix code formatting before committing, you can set up a pre-commit hook:

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

Before each commit, the hook runs `dotnet format` against your staged `.cs` files and auto-fixes any formatting issues. If fixes were applied, the commit is blocked — just stage the fixes and try again:

```bash
git add -u
git commit
```

Note: the hook skips automatically if you have unstaged changes, to avoid touching work in progress.

To opt out at any time:

```bash
./dev.cs remove-hooks
```

**Note:** You can also 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 dev.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,20 @@ public Task<int> AiUpdateAsync(GlobalOptions options = default!)
return RunStepAsync("npx @sentry/dotagents install", "npx", "@sentry/dotagents install", options.DryRun);
}

[Command("setup-hooks", Description = "Configure git to use the repo's pre-commit hooks from .githooks/.")]
public Task<int> SetupHooksAsync(GlobalOptions options = default!)
{
Console.WriteLine("[dev] Configuring git hooks path to .githooks/");
return RunStepAsync("git config core.hooksPath", "git", "config core.hooksPath .githooks", options.DryRun);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Existing hook paths get lost

Low Severity

setup-hooks overwrites any existing local core.hooksPath, and remove-hooks only unsets it. Developers with custom hook paths lose that configuration when opting in and cannot restore it through the provided opt-out command.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit d1f2687. Configure here.

}

[Command("remove-hooks", Description = "Restore default git hooks behaviour (stops using .githooks/).")]
public Task<int> RemoveHooksAsync(GlobalOptions options = default!)
{
Console.WriteLine("[dev] Restoring default git hooks path");
return RunStepAsync("git config --unset core.hooksPath", "git", "config --unset core.hooksPath", options.DryRun);
}

[Command("nrest", Description = "Restore the default CI solution.")]
public Task<int> SolutionRestoreAsync(
[Argument("solution", Description = "Solution file to restore. Defaults to platform-specific CI solution if omitted.")] string? solution = null,
Expand Down
Loading