Skip to content

fix(pre-commit): show dotnet format output on failure

d1f2687
Select commit
Loading
Failed to load commit list.
Open

Add optional pre-commit hook for code formatting #5178

fix(pre-commit): show dotnet format output on failure
d1f2687
Select commit
Loading
Failed to load commit list.
@sentry/warden / warden completed May 6, 2026 in 36s

3 issues

Medium

Staged filenames passed unquoted to dotnet format via --include - `.githooks/pre-commit:12-15`

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.

Low

remove-hooks fails if core.hooksPath was never set - `dev.cs:117`

git config --unset core.hooksPath exits with code 5 when the key does not exist, which RunStepAsync will surface as a non-zero failure. A developer who runs remove-hooks without first running setup-hooks (or after the config has already been cleared) will see a confusing failure even though the desired end-state is achieved. Consider using git config --unset --local core.hooksPath || true-style handling, or checking existence first.

`set -e` is effectively disabled for the dotnet format invocation - `.githooks/pre-commit:15`

The script uses set -e at the top, but the dotnet format ... || { ... } construct disables errexit for that command, and the surrounding $(...) capture also suppresses errors from the pipeline inside the process substitution. If git diff --cached or grep fails, the trailing || true masks it, which could lead to silently running dotnet format with zero include args (handled) but also masks genuine git failures. Low-severity hardening concern.

4 skills analyzed
Skill Findings Duration Cost
code-review 1 30.2s $0.36
find-bugs 2 24.7s $0.32
gha-security-review 0 22.1s $0.13
security-review 0 16.6s $0.14

Duration: 1m 34s · Tokens: 267.3k in / 2.7k out · Cost: $0.95 (+merge: $0.00, +dedup: $0.01)