beads/internal/syncbranch
John Zila f336e669e9
fix(sync): use sync-branch worktree for --full --no-pull (#1183)
* fix(sync): use sync-branch worktree for --full --no-pull (#1173)

Bug 1: PullFromSyncBranch was copying uncommitted worktree changes to
main repo when remoteAhead==0. This corrupted the 3-way merge because
local changes appeared as remote changes. Fixed by copying only the
committed state from HEAD instead of the working directory.

Bug 2: doExportOnlySync was checking main repo for changes via
gitHasBeadsChanges, but when sync-branch is configured, changes go to
the worktree, not main. Fixed by detecting sync-branch config and using
CommitToSyncBranch which operates on the worktree.

Fixes #1173

* refactor(sync): consolidate sync-branch detection and commit/push logic

Extract repeated patterns into reusable helpers:

- SyncBranchContext struct: holds branch name and repo root
- getSyncBranchContext(): detects sync-branch config from store
- commitAndPushBeads(): handles both sync-branch and regular git workflows

This eliminates duplicated sync-branch detection code (was in 3 places)
and the duplicated commit/push conditional logic (was in 2 places).

Net reduction of ~20 lines while improving maintainability.

* fix: remove unused bool return from commitAndPushBeads
2026-01-20 14:06:22 -08:00
..
integrity.go fix(sync): atomic export and force-push detection (bd-3bhl, bd-4hh5) 2026-01-04 23:14:11 -08:00
integrity_test.go Add sync branch integrity guards for force-push detection (bd-hlsw.4) 2025-12-30 17:07:25 -08:00
syncbranch.go fix(sync): persist sync branch to yaml and database (GH#909) (#910) 2026-01-05 19:11:55 -08:00
syncbranch_test.go fix: make tests resilient to project .beads/redirect 2026-01-10 22:38:04 -08:00
worktree.go fix(sync): use sync-branch worktree for --full --no-pull (#1183) 2026-01-20 14:06:22 -08:00
worktree_divergence_test.go fix: use content-level merge for divergence recovery (bd-kpy) 2025-12-24 22:41:40 -08:00
worktree_helpers_test.go bd sync: 2025-12-23 23:38:57 2025-12-24 00:06:41 -08:00
worktree_path_test.go fix: edge case in normalizeBeadsRelPath for similar prefixes 2025-12-29 15:51:17 -08:00
worktree_sync_test.go refactor: Remove deprecated fetchAndRebaseInWorktree (bd-kkka) 2025-12-28 16:40:26 -08:00