Skip to content

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

Open
ClintEastman02 wants to merge 2 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 2 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."

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