Add optional pre-commit hook for code formatting #5178
1 issue
code-review: Found 1 issue (1 high)
High
Stashed unstaged changes are lost if `dotnet format` fails due to `set -e` - `.githooks/pre-commit:2-13`
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.
Also found at:
.githooks/pre-commit:12-13.githooks/pre-commit:22-24
Duration: 46.0s · Tokens: 62.4k in / 2.7k out · Cost: $0.58 (+merge: $0.00)
Annotations
Check failure on line 13 in .githooks/pre-commit
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
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.
Check failure on line 24 in .githooks/pre-commit
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.