|
1 | | -#!/bin/sh |
| 1 | +#!/usr/bin/env sh |
| 2 | +# bd-shim v1 |
| 3 | +# bd-hooks-version: 0.49.6 |
2 | 4 | # |
3 | | -# bd (beads) pre-commit hook (chained) |
| 5 | +# bd (beads) pre-commit hook - thin shim |
4 | 6 | # |
5 | | -# This hook chains bd functionality with your existing pre-commit hook. |
6 | | - |
7 | | -# Run existing hook first |
8 | | -if [ -x "/Users/Charles/Projects/taglib-wasm/.githooks/pre-commit.old" ]; then |
9 | | - "/Users/Charles/Projects/taglib-wasm/.githooks/pre-commit.old" "$@" |
10 | | - EXIT_CODE=$? |
11 | | - if [ $EXIT_CODE -ne 0 ]; then |
12 | | - exit $EXIT_CODE |
13 | | - fi |
14 | | -fi |
| 7 | +# This shim delegates to 'bd hook pre-commit' which contains |
| 8 | +# the actual hook logic. This pattern ensures hook behavior is always |
| 9 | +# in sync with the installed bd version - no manual updates needed. |
| 10 | +# |
| 11 | +# The 'bd hook' command (singular) supports: |
| 12 | +# - Per-worktree export state tracking |
| 13 | +# - Dolt branch-then-merge pattern for cell-level conflict resolution |
| 14 | +# - Hook chaining configuration |
15 | 15 |
|
16 | 16 | # Check if bd is available |
17 | 17 | if ! command -v bd >/dev/null 2>&1; then |
18 | | - echo "Warning: bd command not found, skipping pre-commit flush" >&2 |
19 | | - exit 0 |
20 | | -fi |
21 | | - |
22 | | -# Check if we're in a bd workspace |
23 | | -# For worktrees, .beads is in the main repository root, not the worktree |
24 | | -BEADS_DIR="" |
25 | | -if git rev-parse --git-dir >/dev/null 2>&1; then |
26 | | - # Check if we're in a worktree |
27 | | - if [ "$(git rev-parse --git-dir)" != "$(git rev-parse --git-common-dir)" ]; then |
28 | | - # Worktree: .beads is in main repo root |
29 | | - MAIN_REPO_ROOT="$(git rev-parse --git-common-dir)" |
30 | | - MAIN_REPO_ROOT="$(dirname "$MAIN_REPO_ROOT")" |
31 | | - if [ -d "$MAIN_REPO_ROOT/.beads" ]; then |
32 | | - BEADS_DIR="$MAIN_REPO_ROOT/.beads" |
33 | | - fi |
34 | | - else |
35 | | - # Regular repo: check current directory |
36 | | - if [ -d .beads ]; then |
37 | | - BEADS_DIR=".beads" |
38 | | - fi |
39 | | - fi |
40 | | -fi |
41 | | - |
42 | | -if [ -z "$BEADS_DIR" ]; then |
| 18 | + echo "Warning: bd command not found in PATH, skipping pre-commit hook" >&2 |
| 19 | + echo " Install bd: brew install beads" >&2 |
| 20 | + echo " Or add bd to your PATH" >&2 |
43 | 21 | exit 0 |
44 | 22 | fi |
45 | 23 |
|
46 | | -# Skip for Dolt backend (uses its own sync mechanism, not JSONL) |
47 | | -if [ -f "$BEADS_DIR/metadata.json" ]; then |
48 | | - if grep -q '"backend"[[:space:]]*:[[:space:]]*"dolt"' "$BEADS_DIR/metadata.json" 2>/dev/null; then |
49 | | - exit 0 |
50 | | - fi |
51 | | -fi |
52 | | - |
53 | | -# Flush pending changes to JSONL |
54 | | -if ! bd sync --flush-only >/dev/null 2>&1; then |
55 | | - echo "Error: Failed to flush bd changes to storage" >&2 |
56 | | - echo "Run 'bd sync --flush-only' manually to diagnose" >&2 |
57 | | - exit 1 |
58 | | -fi |
59 | | - |
60 | | -# If the JSONL file was modified, stage it |
61 | | -# For worktrees, the JSONL is in the main repo's working tree, not the worktree, |
62 | | -# so we can't use git add. Skip this step for worktrees. |
63 | | -if [ -f "$BEADS_DIR/issues.jsonl" ]; then |
64 | | - if [ "$(git rev-parse --git-dir)" = "$(git rev-parse --git-common-dir)" ]; then |
65 | | - # Regular repo: file is in the working tree, safe to add |
66 | | - git add "$BEADS_DIR/issues.jsonl" 2>/dev/null || true |
67 | | - fi |
68 | | - # For worktrees: .beads is in the main repo's working tree, not this worktree |
69 | | - # Git rejects adding files outside the worktree, so we skip it. |
70 | | - # The main repo will see the changes on the next pull/sync. |
71 | | -fi |
72 | | - |
73 | | -exit 0 |
| 24 | +exec bd hook pre-commit "$@" |
0 commit comments