diff --git a/.beads-hooks/post-checkout b/.beads-hooks/post-checkout index 71fe7edd..8a9a4d70 100755 --- a/.beads-hooks/post-checkout +++ b/.beads-hooks/post-checkout @@ -29,6 +29,38 @@ if [ ! -d .beads ]; then exit 0 fi +# Detect git worktree: compare --git-dir and --git-common-dir +GIT_DIR=$(git rev-parse --git-dir 2>/dev/null) +GIT_COMMON_DIR=$(git rev-parse --git-common-dir 2>/dev/null) +if [ -n "$GIT_DIR" ] && [ -n "$GIT_COMMON_DIR" ]; then + GIT_DIR_ABS=$(cd "$GIT_DIR" 2>/dev/null && pwd || echo "$GIT_DIR") + GIT_COMMON_DIR_ABS=$(cd "$GIT_COMMON_DIR" 2>/dev/null && pwd || echo "$GIT_COMMON_DIR") + + if [ "$GIT_DIR_ABS" != "$GIT_COMMON_DIR_ABS" ]; then + # We're in a git worktree + cat >&2 <<'EOF' + +╔══════════════════════════════════════════════════════════════════════════╗ +║ Welcome to beads in git worktree! ║ +╠══════════════════════════════════════════════════════════════════════════╣ +║ Note: Daemon mode is not recommended with git worktrees. ║ +║ Worktrees share the same database, and the daemon may commit changes ║ +║ to the wrong branch. ║ +║ ║ +║ RECOMMENDED: Disable daemon for this session: ║ +║ export BEADS_NO_DAEMON=1 ║ +║ ║ +║ For more information: ║ +║ - Run: bd doctor ║ +║ - Read: docs/GIT_INTEGRATION.md (lines 10-53) ║ +║ ║ +║ Issue tracking: bd-dc9 ║ +╚══════════════════════════════════════════════════════════════════════════╝ + +EOF + fi +fi + # Check if any JSONL file exists in .beads/ if ! ls .beads/*.jsonl >/dev/null 2>&1; then exit 0 diff --git a/cmd/bd/templates/hooks/post-checkout b/cmd/bd/templates/hooks/post-checkout index 719b56cf..d7471e69 100755 --- a/cmd/bd/templates/hooks/post-checkout +++ b/cmd/bd/templates/hooks/post-checkout @@ -35,6 +35,38 @@ if [ ! -d .beads ]; then exit 0 fi +# Detect git worktree: compare --git-dir and --git-common-dir +GIT_DIR=$(git rev-parse --git-dir 2>/dev/null) +GIT_COMMON_DIR=$(git rev-parse --git-common-dir 2>/dev/null) +if [ -n "$GIT_DIR" ] && [ -n "$GIT_COMMON_DIR" ]; then + GIT_DIR_ABS=$(cd "$GIT_DIR" 2>/dev/null && pwd || echo "$GIT_DIR") + GIT_COMMON_DIR_ABS=$(cd "$GIT_COMMON_DIR" 2>/dev/null && pwd || echo "$GIT_COMMON_DIR") + + if [ "$GIT_DIR_ABS" != "$GIT_COMMON_DIR_ABS" ]; then + # We're in a git worktree + cat >&2 <<'EOF' + +╔══════════════════════════════════════════════════════════════════════════╗ +║ Welcome to beads in git worktree! ║ +╠══════════════════════════════════════════════════════════════════════════╣ +║ Note: Daemon mode is not recommended with git worktrees. ║ +║ Worktrees share the same database, and the daemon may commit changes ║ +║ to the wrong branch. ║ +║ ║ +║ RECOMMENDED: Disable daemon for this session: ║ +║ export BEADS_NO_DAEMON=1 ║ +║ ║ +║ For more information: ║ +║ - Run: bd doctor ║ +║ - Read: docs/GIT_INTEGRATION.md (lines 10-53) ║ +║ ║ +║ Issue tracking: bd-dc9 ║ +╚══════════════════════════════════════════════════════════════════════════╝ + +EOF + fi +fi + # Check if any JSONL file exists in .beads/ if ! ls .beads/*.jsonl >/dev/null 2>&1; then exit 0 diff --git a/examples/git-hooks/post-checkout b/examples/git-hooks/post-checkout index db73a21c..b24d8b99 100755 --- a/examples/git-hooks/post-checkout +++ b/examples/git-hooks/post-checkout @@ -35,6 +35,38 @@ if [ ! -d .beads ]; then exit 0 fi +# Detect git worktree: compare --git-dir and --git-common-dir +GIT_DIR=$(git rev-parse --git-dir 2>/dev/null) +GIT_COMMON_DIR=$(git rev-parse --git-common-dir 2>/dev/null) +if [ -n "$GIT_DIR" ] && [ -n "$GIT_COMMON_DIR" ]; then + GIT_DIR_ABS=$(cd "$GIT_DIR" 2>/dev/null && pwd || echo "$GIT_DIR") + GIT_COMMON_DIR_ABS=$(cd "$GIT_COMMON_DIR" 2>/dev/null && pwd || echo "$GIT_COMMON_DIR") + + if [ "$GIT_DIR_ABS" != "$GIT_COMMON_DIR_ABS" ]; then + # We're in a git worktree + cat >&2 <<'EOF' + +╔══════════════════════════════════════════════════════════════════════════╗ +║ Welcome to beads in git worktree! ║ +╠══════════════════════════════════════════════════════════════════════════╣ +║ Note: Daemon mode is not recommended with git worktrees. ║ +║ Worktrees share the same database, and the daemon may commit changes ║ +║ to the wrong branch. ║ +║ ║ +║ RECOMMENDED: Disable daemon for this session: ║ +║ export BEADS_NO_DAEMON=1 ║ +║ ║ +║ For more information: ║ +║ - Run: bd doctor ║ +║ - Read: docs/GIT_INTEGRATION.md (lines 10-53) ║ +║ ║ +║ Issue tracking: bd-dc9 ║ +╚══════════════════════════════════════════════════════════════════════════╝ + +EOF + fi +fi + # Check if any JSONL file exists in .beads/ if ! ls .beads/*.jsonl >/dev/null 2>&1; then exit 0