fix(sync): prevent circular error in pre-push hook (GH#532)
When bd sync pushes from the sync-branch worktree, the pre-push hook would detect uncommitted JSONL changes and suggest running bd sync - which is circular since that's what the user is already doing. Fix: Set BD_SYNC_IN_PROGRESS=1 environment variable when pushing from worktree, and update pre-push hook to skip checks when this var is set. Updated files: - internal/syncbranch/worktree.go: Set env var on push command - cmd/bd/templates/hooks/pre-push: Check for env var and exit early - examples/git-hooks/pre-push: Same check - .beads-hooks/pre-push: Same check
This commit is contained in:
@@ -25,6 +25,12 @@ if [ ! -d .beads ]; then
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Skip if bd sync is already in progress (GH#532: prevents circular error)
|
||||||
|
# bd sync sets this env var when pushing from worktree
|
||||||
|
if [ -n "$BD_SYNC_IN_PROGRESS" ]; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
# Optionally flush pending bd changes so they surface in JSONL
|
# Optionally flush pending bd changes so they surface in JSONL
|
||||||
# This prevents the race where a debounced flush lands after the check
|
# This prevents the race where a debounced flush lands after the check
|
||||||
if command -v bd >/dev/null 2>&1; then
|
if command -v bd >/dev/null 2>&1; then
|
||||||
|
|||||||
2
.beads/.gitignore
vendored
2
.beads/.gitignore
vendored
@@ -30,3 +30,5 @@ beads.right.meta.json
|
|||||||
!issues.jsonl
|
!issues.jsonl
|
||||||
!metadata.json
|
!metadata.json
|
||||||
!config.json
|
!config.json
|
||||||
|
deletions.jsonl
|
||||||
|
deletions.jsonl.migrated
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -28,6 +28,12 @@ if [ ! -d .beads ]; then
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Skip if bd sync is already in progress (GH#532: prevents circular error)
|
||||||
|
# bd sync sets this env var when pushing from worktree
|
||||||
|
if [ -n "$BD_SYNC_IN_PROGRESS" ]; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
# Check if sync-branch is configured in config.yaml or env var
|
# Check if sync-branch is configured in config.yaml or env var
|
||||||
# If so, .beads changes go to a separate branch via worktree, not the current branch
|
# If so, .beads changes go to a separate branch via worktree, not the current branch
|
||||||
SYNC_BRANCH="${BEADS_SYNC_BRANCH:-}"
|
SYNC_BRANCH="${BEADS_SYNC_BRANCH:-}"
|
||||||
|
|||||||
@@ -28,6 +28,12 @@ if [ ! -d .beads ]; then
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Skip if bd sync is already in progress (GH#532: prevents circular error)
|
||||||
|
# bd sync sets this env var when pushing from worktree
|
||||||
|
if [ -n "$BD_SYNC_IN_PROGRESS" ]; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
# Check if sync-branch is configured in config.yaml or env var
|
# Check if sync-branch is configured in config.yaml or env var
|
||||||
# If so, .beads changes go to a separate branch via worktree, not the current branch
|
# If so, .beads changes go to a separate branch via worktree, not the current branch
|
||||||
SYNC_BRANCH="${BEADS_SYNC_BRANCH:-}"
|
SYNC_BRANCH="${BEADS_SYNC_BRANCH:-}"
|
||||||
|
|||||||
@@ -728,6 +728,9 @@ func pushFromWorktree(ctx context.Context, worktreePath, branch string) error {
|
|||||||
for attempt := 0; attempt < maxRetries; attempt++ {
|
for attempt := 0; attempt < maxRetries; attempt++ {
|
||||||
// Push with explicit remote and branch, set upstream if not set
|
// Push with explicit remote and branch, set upstream if not set
|
||||||
cmd := exec.CommandContext(ctx, "git", "-C", worktreePath, "push", "--set-upstream", remote, branch)
|
cmd := exec.CommandContext(ctx, "git", "-C", worktreePath, "push", "--set-upstream", remote, branch)
|
||||||
|
// Set BD_SYNC_IN_PROGRESS so pre-push hook knows to skip checks (GH#532)
|
||||||
|
// This prevents circular error where hook suggests running bd sync
|
||||||
|
cmd.Env = append(os.Environ(), "BD_SYNC_IN_PROGRESS=1")
|
||||||
output, err := cmd.CombinedOutput()
|
output, err := cmd.CombinedOutput()
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user