Skip to content

submodule: associations follow checkout, inherit on create, merge on fold#1180

Draft
ed-irl wants to merge 4 commits into
ed-irl/submodule-statusfrom
ed-irl/submodule-checkout
Draft

submodule: associations follow checkout, inherit on create, merge on fold#1180
ed-irl wants to merge 4 commits into
ed-irl/submodule-statusfrom
ed-irl/submodule-checkout

Conversation

@ed-irl

@ed-irl ed-irl commented May 19, 2026

Copy link
Copy Markdown
Collaborator

Make tracked submodule branch associations move with branch operations transactionally, with HEAD rollback on conflict.

  • branch checkout (and friends): after switching branches, switch each tracked submodule to the branch recorded for the target. The checkout handler snapshots HEAD first and rolls parent + already-switched submodules back to their original HEADs if the apply fails. Wiring is optional — a nil Submodule applier disables auto-checkout.
  • branch create: a fresh child inherits its parent's recorded submodule associations as a baseline (RecordWithInheritance), then overlays the current worktree state so an explicitly-moved submodule wins.
  • branch fold: merge the folded child's submodule records into the surviving base (MergeAssociationsForFold). Disjoint and identical records carry over silently; conflicting per-submodule records resolve via the new repeatable '--module-branch=PATH=BRANCH' flag, an interactive prompt, or fail with a FoldConflictError listing all conflicts.
  • branch onto: apply the target's submodule associations after BranchOnto runs (it bypasses the checkout handler), snapshotting parent HEAD for rollback on failure.

Adds checkout.GitWorktree.SnapshotHead/RestoreHead, a checkout SubmoduleApplier interface, and unit + test-script coverage for inheritance, checkout apply, and fold merge.

Part of #1246

@ed-irl ed-irl force-pushed the ed-irl/submodule-status branch from 32667fc to 0ee783f Compare June 2, 2026 18:57
@ed-irl ed-irl force-pushed the ed-irl/submodule-checkout branch 2 times, most recently from c35f125 to a53813b Compare June 2, 2026 22:29
@ed-irl ed-irl force-pushed the ed-irl/submodule-status branch 2 times, most recently from 6d52edc to 0e22ba0 Compare June 8, 2026 10:18
@ed-irl ed-irl force-pushed the ed-irl/submodule-checkout branch from a53813b to 056942f Compare June 8, 2026 10:18
@ed-irl ed-irl force-pushed the ed-irl/submodule-status branch from 0e22ba0 to ff86ca6 Compare June 12, 2026 20:05
@ed-irl ed-irl force-pushed the ed-irl/submodule-checkout branch from 829f703 to f6111a2 Compare June 12, 2026 20:05
@ed-irl ed-irl force-pushed the ed-irl/submodule-status branch from ff86ca6 to e33206f Compare June 13, 2026 13:38
@ed-irl ed-irl force-pushed the ed-irl/submodule-checkout branch from f6111a2 to 11fbf07 Compare June 13, 2026 13:38
@ed-irl ed-irl force-pushed the ed-irl/submodule-status branch from e33206f to 236db03 Compare June 15, 2026 09:52
@ed-irl ed-irl force-pushed the ed-irl/submodule-checkout branch from 11fbf07 to faefa69 Compare June 15, 2026 09:52
@ed-irl ed-irl force-pushed the ed-irl/submodule-status branch from 8389d82 to f843ca7 Compare June 19, 2026 00:59
@ed-irl ed-irl changed the title submodule: auto-checkout, branch-create inheritance, branch-fold merge feat: worktree management commands, per-worktree trunks, and worktree-aware filtering Jun 19, 2026
@ed-irl ed-irl force-pushed the ed-irl/submodule-checkout branch from 1568077 to 074df48 Compare June 19, 2026 00:59
@ed-irl ed-irl changed the title feat: worktree management commands, per-worktree trunks, and worktree-aware filtering submodule: associations follow checkout, inherit on create, merge on fold Jun 19, 2026
ed-irl and others added 3 commits June 23, 2026 13:44
Hook the submodule.Applier into the checkout flow so tracked submodules
follow the parent's recorded sub-branch when the user runs
gs bco / gs down / gs up / gs trunk / gs branch onto.

Highlights:

- checkout.Handler: snapshot parent HEAD before checkout; apply
  recorded submodule associations after; restore parent on submodule
  failure.
- branch_onto.go: applies the same snapshot/apply/rollback pattern
  directly (does not route through checkout.Handler because its
  VerifyRestacked path is not appropriate post-BranchOnto).
- branch_create.go: now records inherited submodule associations from
  the parent branch and overlays the current sub state.
- branch_fold.go: merges submodule associations from the folded branch
  into the base. Same path/same value: kept. Disjoint: combined. Both
  set but differ: pre-resolved via --module-branch=PATH=BRANCH;
  otherwise prompted (interactive) or returned as FoldConflictError.
- internal/handler/submodule: add Applier.MergeAssociationsForFold and
  Tracker.RecordWithInheritance.
- internal/handler/submodule: rename SubmoduleContext→Context and
  OpenSubmoduleContext→OpenContext to satisfy revive.
@ed-irl ed-irl force-pushed the ed-irl/submodule-status branch from f843ca7 to a3150c5 Compare June 24, 2026 01:31
@ed-irl ed-irl force-pushed the ed-irl/submodule-checkout branch from 074df48 to 50250cd Compare June 24, 2026 01:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant