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
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
APP_ENV=staging
BACKEND_STAGING_URL=https://staging.ourpocket.com
BACKEND_PROD_URL=https://api.ourpocket.com
REDIS_URL=redis://redis:6379
REDIS_QUEUE_KEY=ourpocket:transactions
20 changes: 20 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash
set -euo pipefail

REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"
cd "$REPO_ROOT"

echo "[pre-commit] Running cargo fmt..."
cargo fmt --all

echo "[pre-commit] Running tests..."
if [ -x "./scripts/test.sh" ]; then
./scripts/test.sh
else
cargo test --workspace
fi

echo "[pre-commit] Staging formatted files..."
git add -u
Comment on lines +17 to +18
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

git add -u silently stages all untracked modifications, clobbering intentional partial staging.

After cargo fmt --all runs, git add -u restages every tracked modified file — not just the formatter's changes. If a developer has deliberately left some hunks/files unstaged (to be committed separately), those will be swept into the commit without their consent.

The safer pattern is to fail fast with --check and let the developer re-stage explicitly, rather than auto-staging on their behalf:

🔒 Proposed fix
-echo "[pre-commit] Running cargo fmt..."
-cargo fmt --all
+echo "[pre-commit] Checking cargo fmt..."
+if ! cargo fmt --all -- --check; then
+  echo "[pre-commit] Formatting issues found. Run 'cargo fmt --all' and re-stage your changes."
+  exit 1
+fi
 
 echo "[pre-commit] Running tests..."
 if [ -x "./scripts/test.sh" ]; then
   ./scripts/test.sh
 else
   cargo test --workspace
 fi
 
-echo "[pre-commit] Staging formatted files..."
-git add -u
-
 echo "[pre-commit] All checks passed."
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.githooks/pre-commit around lines 17 - 18, Replace the auto-staging step
that uses "git add -u" with a formatter check so we don't clobber a developer's
intentional partial staging: remove the "git add -u" invocation in the
pre-commit script and instead run "cargo fmt --all" in check mode (e.g., pass
the -- --check flag to cargo fmt) and fail the hook when formatting is required
so the developer can re-stage explicitly; update the pre-commit flow around the
existing cargo fmt invocation to exit non-zero on formatting issues and print
instructions to run cargo fmt manually.


echo "[pre-commit] All checks passed."
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
.env
Loading