aws-samples / aws-samples/sample-autonomous-cloud-coding-agents

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

オープン
#197 コメント 0 件 リアクション 0 件 担当者 1 名 GitHub で見る

@ClintEastman02 がすでに取り組んでいます。

2026年5月29日 から。

enhancement tooling
主要言語
TypeScript
スター
146
フォーク
46
平均マージ
3日 10時間
マージ済み PR(30日)
24

説明

## Problem
Worktrees created from `origin/main` drift silently as other branches merge to main. By the time a PR is pushed, the branch may be multiple commits behind, causing:
- Unnecessary merge conflicts at PR time
- CI running against stale base (masking integration issues)
- Manual `git fetch && git rebase` before every push

Example: the `fix/194-ts-isolated-modules` worktree was 1 commit behind `origin/main` at push time because PR #171 (ESLint 10) merged after branch creation.

## Acceptance criteria
- [ ] Worktrees are created from the latest `origin/main` (enforce `git fetch origin main` before `git worktree add`)
- [ ] Active worktrees are periodically rebased or at minimum warned about staleness
- [ ] No data loss — only rebase clean worktrees (no uncommitted changes)

## Suggested implementation

### Option A: mise task `worktree:sync` (recommended)
Add a mise task that iterates active worktrees and rebases them on `origin/main`:

```bash
# mise.toml
[tasks."worktree:sync"]
description = "Fetch origin/main and rebase all active worktrees"
run = """
git fetch origin main
for wt in $(git worktree list --porcelain | grep '^worktree ' | grep -v '$(git rev-parse --show-toplevel)$' | sed 's/^worktree //'); do
branch=$(git -C "$wt" rev-parse --abbrev-ref HEAD 2>/dev/null)
if [ -z "$(git -C "$wt" status --porcelain)" ]; then
echo "Rebasing $branch in $wt..."
git -C "$wt" rebase origin/main || git -C "$wt" rebase --abort
else
echo "SKIP $branch (dirty working tree)"
fi
done
"""
```

### Option B (optional): SessionStart hook for staleness warning
A Claude Code hook or startup script that checks worktree age and warns:

```bash
# Check each worktree's distance from origin/main
for wt in $(git worktree list --porcelain | grep '^worktree ' | sed 's/^worktree //'); do
behind=$(git -C "$wt" rev-list --count HEAD..origin/main 2>/dev/null)
if [ "$behind" -gt 0 ]; then
echo "⚠ $wt is $behind commit(s) behind origin/main"
fi
done
```

### Option C (optional): pre-push rebase
Add to the pre-push hook: if the branch is behind `origin/main`, auto-rebase before pushing (abort if conflicts).

## Labels
`enhancement`, `developer-experience`

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。