Skip to content
30 changes: 28 additions & 2 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,8 +1,34 @@
#!/usr/bin/env bash
set -e

# Only auto-format desktop TS code if relevant files are modified
if git diff --cached --name-only | grep -q "^ui/desktop/"; then
if git diff --cached --no-renames --name-only | grep -q "^ui/desktop/"; then
if [ -d "ui/desktop" ]; then
cd ui/desktop && pnpm exec lint-staged
(cd ui/desktop && pnpm exec lint-staged)
else
echo "Warning: ui/desktop directory does not exist, skipping lint-staged"
fi
fi

# Run goose2 checks if any staged files are under ui/goose2/
if git diff --cached --no-renames --name-only | grep -q '^ui/goose2/'; then
if [ -d "ui/goose2" ]; then
Comment thread
matt2e marked this conversation as resolved.
REPO_ROOT="$(pwd)"
echo "Running goose2 pre-commit checks..."

# Auto-format only staged files and re-stage them
STAGED_FILES=$(git diff --cached --no-renames --diff-filter=ACMR --name-only | grep '^ui/goose2/' | sed 's|^ui/goose2/||' || true)
if [ -n "$STAGED_FILES" ]; then
cd ui/goose2
echo "$STAGED_FILES" | xargs npx biome format --write
echo "$STAGED_FILES" | xargs npx biome check --fix
cd "$REPO_ROOT"
git diff --cached --no-renames --diff-filter=ACMR --name-only | grep '^ui/goose2/' | xargs git add
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve partial staging when re-adding goose2 files

Re-staging with git add on all goose2 paths will stage the entire file contents, not just the hunks the user originally staged. If a developer has partially staged a file under ui/goose2/ (common during split commits), this line will silently pull unstaged WIP edits into the commit after formatting/checks run, which can ship unintended code. This should use a stash/restore flow (like lint-staged) or another approach that keeps partial index state intact.

Useful? React with 👍 / 👎.

fi

# Run checks (biome check + file sizes + i18n + typecheck)
just goose2 check
else
echo "Warning: ui/goose2 directory does not exist, skipping goose2 checks"
fi
fi
71 changes: 71 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env bash
# Run goose2 pre-push checks if any commits being pushed include goose2 changes.

# --- Helper functions ---

# Check if any ref being pushed includes changes under a given path prefix.
# Reads git's pre-push stdin (local_ref local_oid remote_ref remote_oid).
push_touches() {
local prefix="$1"
local z40="0000000000000000000000000000000000000000"

while read local_ref local_oid remote_ref remote_oid; do
[ "$local_oid" = "$z40" ] && continue # deleting ref

if [ "$remote_oid" = "$z40" ]; then
# New branch — compare against the merge base with the default branch
range="$(git merge-base HEAD main 2>/dev/null || echo "$local_oid")...$local_oid"
Comment thread
matt2e marked this conversation as resolved.
else
range="$remote_oid...$local_oid"
fi

if git diff --no-renames --name-only "$range" -- 2>/dev/null | grep -q "^${prefix}"; then
return 0
fi
done

return 1
}

# Run commands in parallel, exit 1 if any fail.
# Usage: run_parallel "label1" "cmd1" "label2" "cmd2" ...
run_parallel() {
local -a labels=() pids=()
while [[ $# -ge 2 ]]; do
Comment thread
matt2e marked this conversation as resolved.
labels+=("$1"); shift
( eval "$1" ) & pids+=($!); shift
done

local -a failed=()
for i in "${!pids[@]}"; do
wait "${pids[$i]}" || failed+=("${labels[$i]}")
done

if [[ ${#failed[@]} -gt 0 ]]; then
echo "Failed: ${failed[*]}"
return 1
fi
}

# --- Hook body ---

push_touches "ui/goose2/" || exit 0

echo "Detected ui/goose2/ changes — running pre-push checks..."

run_parallel \
"fmt-check" "just goose2 fmt-check" \
"clippy" "just goose2 clippy" \
"check" "just goose2 check" \
"test" "just goose2 test" \
"build" "just goose2 build" \
"tauri-check" "just goose2 tauri-check"

exit_code=$?

if [ $exit_code -eq 0 ]; then
echo "All goose2 pre-push checks passed."
else
echo "goose2 pre-push checks failed."
exit 1
fi
7 changes: 4 additions & 3 deletions ui/goose2/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ default:

# ── Dev Environment ──────────────────────────────────────────

# Install dependencies and build workspace packages
# Install dependencies, build workspace packages, and activate git hooks
setup:
git config core.hooksPath .husky
cd ../ && pnpm install
cd ../sdk && pnpm build
cargo build --manifest-path ../../Cargo.toml -p goose-cli --bin goose
Expand All @@ -33,7 +34,7 @@ fmt-check:

# Run clippy on Tauri backend
clippy:
cd src-tauri && cargo clippy -- -D warnings
cd src-tauri && TAURI_CONFIG='{"bundle":{"externalBin":[]}}' cargo clippy -- -D warnings

# Build the frontend
build:
Expand All @@ -45,7 +46,7 @@ tauri-fmt-check:

# Check Tauri Rust types
tauri-check:
cd src-tauri && cargo check
cd src-tauri && TAURI_CONFIG='{"bundle":{"externalBin":[]}}' cargo check

# Full CI gate
ci: check clippy test build tauri-check
Expand Down
Loading