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

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

Abierto
#197 0 comentarios 0 reacciones 1 asignado Reclamado por @ClintEastman02 Ver en GitHub
enhancement tooling
Lenguaje dominante
TypeScript
Estrellas
143
Forks
46
Merge medio
3 d 10 h
PR fusionados (30 d)
24

Descripción

## 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`

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.