Skip to content

A local-first personal finance app

[AI] Improve post-checkout hook to handle git worktree creation (#7393)

Matiss Janis Aboltins799db6c49617
diff --git a/.husky/post-checkout b/.husky/post-checkout
index b72113be3f..697964df72 100755
--- a/.husky/post-checkout
+++ b/.husky/post-checkout
@@ -1,11 +1,19 @@
#!/bin/sh
# Run yarn install when switching branches (if yarn.lock changed)
+# or when creating a new worktree (node_modules won't exist yet)
# $3 is 1 for branch checkout, 0 for file checkout
if [ "$3" != "1" ]; then
exit 0
fi
+# Worktree creation: node_modules doesn't exist yet, always install
+if [ ! -d "node_modules" ]; then
+ echo "New worktree detected — running yarn install..."
+ yarn install || exit 1
+ exit 0
+fi
+
# Check if yarn.lock changed between the old and new HEAD
if git diff --name-only "$1" "$2" | grep -q "^yarn.lock$"; then
echo "yarn.lock changed — running yarn install..."
diff --git a/upcoming-release-notes/7393.md b/upcoming-release-notes/7393.md
new file mode 100644
index 0000000000..da61a8d26e
--- /dev/null
+++ b/upcoming-release-notes/7393.md
@@ -0,0 +1,6 @@
+---
+category: Maintenance
+authors: [MatissJanis]
+---
+
+Improve post-checkout hook to automatically install dependencies for newly created git worktrees.