Add optional pre-commit hook for code formatting #5178
2 issues
code-review: Found 2 issues (2 high)
High
Hook runs `dotnet format` in write mode despite claiming check-only behavior - `.githooks/pre-commit:25-26`
The PR description and hook comment state this is a check-only verification (matching CI's --verify-no-changes), but the actual command omits --verify-no-changes and runs dotnet format in its default write mode, which modifies files in the working tree. After the failed commit, the working tree contains auto-applied formatting changes the user never asked for. This contradicts the documented design and produces side effects on the developer's working tree on every formatting failure.
Recovery instructions risk staging unrelated unstaged changes - `.githooks/pre-commit:44-45`
After a formatting failure, the trap restores the user's previously stashed unstaged changes back into the working tree. The error message then instructs the user to run git add -u && git commit, which would stage ALL modified tracked files — including unstaged changes that were never meant to be part of this commit. This silently expands the scope of the user's commit beyond what they originally staged.
Duration: 43.2s · Tokens: 62.1k in / 2.6k out · Cost: $0.43 (+merge: $0.00)
Annotations
Check failure on line 26 in .githooks/pre-commit
sentry-warden / warden: code-review
Hook runs `dotnet format` in write mode despite claiming check-only behavior
The PR description and hook comment state this is a check-only verification (matching CI's `--verify-no-changes`), but the actual command omits `--verify-no-changes` and runs `dotnet format` in its default write mode, which modifies files in the working tree. After the failed commit, the working tree contains auto-applied formatting changes the user never asked for. This contradicts the documented design and produces side effects on the developer's working tree on every formatting failure.
Check failure on line 45 in .githooks/pre-commit
sentry-warden / warden: code-review
Recovery instructions risk staging unrelated unstaged changes
After a formatting failure, the trap restores the user's previously stashed unstaged changes back into the working tree. The error message then instructs the user to run `git add -u && git commit`, which would stage ALL modified tracked files — including unstaged changes that were never meant to be part of this commit. This silently expands the scope of the user's commit beyond what they originally staged.