Skip to content

feat(dx): add worktree:sync mise task to rebase clean worktrees on origin/main#218

Open
ClintEastman02 wants to merge 5 commits into
aws-samples:mainfrom
ClintEastman02:fix/197-worktree-sync
Open

feat(dx): add worktree:sync mise task to rebase clean worktrees on origin/main#218
ClintEastman02 wants to merge 5 commits into
aws-samples:mainfrom
ClintEastman02:fix/197-worktree-sync

Conversation

@ClintEastman02
Copy link
Copy Markdown
Contributor

Summary

Adds a new mise task mise run worktree:sync that fetches origin/main and rebases every clean linked worktree onto it. Implements Option A from #197.

  • Iterates git worktree list --porcelain and rebases each linked worktree
  • Skips dirty worktrees (uncommitted changes) with a SKIP message
  • Skips main/master (rebase isn't the right tool for the primary branch)
  • On rebase conflict, runs git rebase --abort and exits non-zero so the operator surfaces the conflict explicitly rather than leaving a half-rebased state

Also updates AGENTS.md to point contributors at the new task in two places (the worktree common-mistake bullet and the Commands you can use list).

Closes #197

Test plan

Tested locally with four worktree states:

  • Clean worktree behind origin/main → rebased successfully
  • Clean worktree even with origin/main → no-op (rebase reports "up to date")
  • Dirty worktree (uncommitted changes) → SKIP message, not touched
  • Worktree with conflicting commit → FAIL reported, git rebase --abort runs, working tree restored to pre-rebase HEAD, task exits non-zero
  • main worktree → skipped silently
  • TOML parses cleanly (mise tasks --all lists //:worktree:sync)
  • gitleaks clean on the diff

…igin/main

Worktrees branched from origin/main drift silently as other PRs merge,
causing unnecessary conflicts at push time and CI runs against stale
bases. Issue aws-samples#197.

The new `mise run worktree:sync` task fetches origin/main and rebases
every clean linked worktree onto it. Dirty worktrees and main itself
are skipped; conflicting rebases are aborted and reported with a
non-zero exit so the operator can resolve them explicitly rather than
leaving a half-rebased state.

Closes aws-samples#197
@ClintEastman02 ClintEastman02 requested a review from a team as a code owner May 29, 2026 17:58
@scottschreckengaust
Copy link
Copy Markdown
Contributor

Works as designed. I noticed that the script could be enhanced with a "detect already-merged branches" check (e.g., git branch --merged origin/main would catch branches that already merged), but that's a feature enhancement, not a bug. As-is, it correctly reports "I can't rebase this, you need to look at it."

ClintEastman02 and others added 2 commits June 1, 2026 10:13
Address review feedback on PR aws-samples#218: detect worktrees whose HEAD is
already an ancestor of origin/main (i.e. the branch has merged) and
skip them with a MERGED message rather than attempting a no-op rebase.
The operator can then prune the worktree at their leisure.

Suggested by @scottschreckengaust.
@ClintEastman02
Copy link
Copy Markdown
Contributor Author

Good call — added the merged-branch detection in fe30fb7. Worktrees whose HEAD is already an ancestor of origin/main now get reported with a MERGED line and skipped (no-op rebase avoided), so the operator knows the worktree is ready to prune.

Test matrix (all four cases verified locally):

  • Conflicting commit on a stale base → FAIL + git rebase --abort, non-zero exit
  • Branch already merged into origin/mainMERGED, skipped
  • Stale-and-clean (unique commits behind main) → rebased
  • Stale-and-dirty (uncommitted changes) → SKIP
  • main worktree itself → skipped silently

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.

chore(dx): worktree hygiene automation — rebase on main drift

2 participants