Skip to content

git_mf: Add --subs to merge submodules before the superproject - #142

Merged
Unique-Divine merged 7 commits into
mainfrom
ud/git-mf-submodules
Nov 15, 2026
Merged

Unique-Divine merged 7 commits into
mainfrom
ud/git-mf-submodules

Conversation

@Unique-Divine

@Unique-Divine Unique-Divine commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Part of boku#201. On homebox, git_mf ud/main in boku stopped with merge-conflict: dotfiles jiyuu. Each machine branch records its own machine's submodule heads, so merging one into the other always conflicts on the pointers.

Changes

git_mf TARGET --subs (help text in bin/git_mf):

  1. Refuses with exit 2 if the superproject has changes besides submodule pointers, before anything moves.
  2. Runs git_mf TARGET inside each initialized submodule, passing --dry-run, --agent, and merge flags through. The first submodule that exits non-zero stops the run, and the superproject is left as it was.
  3. Commits the submodules' moved pointers, then merges the superproject as usual. Because each pointer now contains the other branch's, git fast-forwards it instead of conflicting. I confirmed this with a prototype: Fast-forwarding submodule sub.

Usage on homebox: git_mf ud/main --subs in ~/boku.

Verification

bun test bin/git_mf.test.ts: 48 pass, including 4 new scenarios built from a real superproject and submodule pair:

  • --subs merges both levels and leaves a clean tree, with the pointer at the submodule head containing both branches.
  • Without the flag, the run still stops with merge-conflict: sub (exit 3).
  • Other uncommitted changes stop the run before the submodule moves.
  • A submodule content conflict stops the run with exit 3, and the superproject's HEAD is unchanged.

shellcheck -x adds no new warnings.

@Unique-Divine Unique-Divine added the A-tech-investment Area: Internal work that helps the team ship faster label Nov 15, 2026
Merging one machine branch into another in boku conflicted on the dotfiles and jiyuu pointers, because each machine records its own submodule heads. --subs runs git_mf inside each initialized submodule first, commits the moved pointers, then merges the superproject; git fast-forwards each pointer that already contains the other side's. Changes besides submodule pointers, or a submodule that needs judgment, stop the run before the superproject is touched. Refs Unique-Divine/boku#201.
@Unique-Divine Unique-Divine changed the title git_mf: Add --submodules to merge submodules before the superproject git_mf: Add --subs to merge submodules before the superproject Nov 15, 2026
Dry-run each submodule and predict the superproject merge outside submodule pointers before any submodule moves. Refuse staged changes, route the dirty refusal through --agent, read .gitmodules NUL-separated, pass --subs, --agent, and --json to child runs, and make --dry-run report the --subs plan without planning against stale pointers. Found by an independent Codex review.
The preflight now runs git_mf TARGET --dry-run --subs, so every repository gets the normal checks (branch, detached HEAD, divergence, fetch failures, merge-tree errors) before anything changes. In --subs plans, pointer-only conflicts count as a merge and unstaged pointers do not count as dirty, matching what a real run does. With --agent, a failed preflight continues so each level can hand its refusal to the agent. Found by an independent Codex review.
--subs refuses on TARGET itself or a detached HEAD, where committing pointers would cause divergence. A failed preflight always stops, naming the repository to fix with --agent. A pointer-only conflict counts as a fast-forward only when the submodule's origin/TARGET contains the incoming pointer. Found by an independent Codex review.
Validate each incoming pointer against the submodule's origin/TARGET whatever the first plan predicts, so a fast-forward plan cannot turn into a pointer conflict after the pointer commit. The branch rule applies only to repositories with submodules. Found by an independent Codex review.
…e targets like the planner

Found by an independent Codex review.
The planner does not model --ff-only, so a submodule needing a merge commit would pass the preflight and fail during apply. Found by an independent Codex review.
@Unique-Divine
Unique-Divine merged commit 61c97c5 into main Nov 15, 2026
10 checks passed
@Unique-Divine
Unique-Divine deleted the ud/git-mf-submodules branch November 15, 2026 22:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-tech-investment Area: Internal work that helps the team ship faster

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant