Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*.sln text=auto eol=crlf
*.slnx text=auto eol=lf
*.sh eol=lf
.githooks/* eol=lf
*.ps1 eol=lf
CHANGELOG.md merge=union

Expand Down
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
Comment thread
cursor[bot] marked this conversation as resolved.
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)
Comment thread
jamescrosswell marked this conversation as resolved.
Comment thread
jamescrosswell marked this conversation as resolved.
Comment thread
jamescrosswell marked this conversation as resolved.

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);
Comment thread
jamescrosswell marked this conversation as resolved.
}

[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