dotfiles
bugabingas dorkfiles
owned by bugabinga
pi/agent/prompts/ff.md
Raw
description: Sync current branch into trunk via rebase + fast-forward
argument-hint: "[trunk] [test-command]"
Sync current branch into trunk. Linear history only. No merge commits. Never force-push trunk.
Args: if $1 is branch/ref → trunk, ${@:2} → tests. Else infer trunk, $ARGUMENTS → tests.
-
Inspect
- Run:
git status --short --branch, git branch --show-current, git remote -v, git worktree list --porcelain, git branch -vv.
- Stop on: non-git, detached HEAD, merge/rebase in progress, dirty index/worktree, dirty trunk worktree.
- Record: branch, upstream, remote, trunk, HEAD.
-
Find trunk
- Prefer arg.
- Else infer: upstream/base metadata → remote HEAD →
main → master → trunk → develop.
- Ambiguous → ask.
- If trunk checked out in worktree, use that worktree for trunk ops.
-
Fetch/update trunk
git fetch --prune --tags <remote>.
- If trunk worktree:
git -C <wt> pull --ff-only.
- Else if local trunk exists:
git fetch <remote> <trunk>:<trunk> (no +).
- Else create from remote:
git branch --track <trunk> <remote>/<trunk>.
- Trunk divergence → stop.
-
If already on trunk
git pull --ff-only.
- Run tests if given/obvious.
- Push if ahead:
git push <remote> <trunk>.
- Report.
-
Rebase branch
- Check diff/log:
git log --oneline --left-right --cherry-pick <trunk>...HEAD, git diff --stat <trunk>...HEAD.
- If needed:
git rebase <trunk>.
- Conflict → stop; show status/files/next commands.
- Verify branch still has intended commits/diff.
-
Test
- Run supplied test cmd, else cheap obvious checks from project files.
- Failure → stop. No merge/push.
-
Fast-forward trunk
- Require:
git merge-base --is-ancestor <trunk> HEAD.
- If trunk worktree:
git -C <wt> merge --ff-only <branch-or-sha>.
- Else:
git update-ref refs/heads/<trunk> HEAD <old-trunk-sha>.
-
Push
git push <remote> <trunk>.
- Rejected → fetch, re-evaluate, rebase once if safe, retest critical checks, retry.
- Never force-push trunk.
Report: trunk/remote, branch old→new SHA, rebase yes/no, tests, pushed SHA, follow-up.
Markdown source
File outline
---
description: Sync current branch into trunk via rebase + fast-forward
argument-hint: "[trunk] [test-command]"
---
Sync current branch into trunk. Linear history only. No merge commits. Never force-push trunk.
Args: if `$1` is branch/ref → trunk, `${@:2}` → tests. Else infer trunk, `$ARGUMENTS` → tests.
1. Inspect
- Run: `git status --short --branch`, `git branch --show-current`, `git remote -v`, `git worktree list --porcelain`, `git branch -vv`.
- Stop on: non-git, detached HEAD, merge/rebase in progress, dirty index/worktree, dirty trunk worktree.
- Record: branch, upstream, remote, trunk, HEAD.
2. Find trunk
- Prefer arg.
- Else infer: upstream/base metadata → remote HEAD → `main` → `master` → `trunk` → `develop`.
- Ambiguous → ask.
- If trunk checked out in worktree, use that worktree for trunk ops.
3. Fetch/update trunk
- `git fetch --prune --tags <remote>`.
- If trunk worktree: `git -C <wt> pull --ff-only`.
- Else if local trunk exists: `git fetch <remote> <trunk>:<trunk>` (no `+`).
- Else create from remote: `git branch --track <trunk> <remote>/<trunk>`.
- Trunk divergence → stop.
4. If already on trunk
- `git pull --ff-only`.
- Run tests if given/obvious.
- Push if ahead: `git push <remote> <trunk>`.
- Report.
5. Rebase branch
- Check diff/log: `git log --oneline --left-right --cherry-pick <trunk>...HEAD`, `git diff --stat <trunk>...HEAD`.
- If needed: `git rebase <trunk>`.
- Conflict → stop; show status/files/next commands.
- Verify branch still has intended commits/diff.
6. Test
- Run supplied test cmd, else cheap obvious checks from project files.
- Failure → stop. No merge/push.
7. Fast-forward trunk
- Require: `git merge-base --is-ancestor <trunk> HEAD`.
- If trunk worktree: `git -C <wt> merge --ff-only <branch-or-sha>`.
- Else: `git update-ref refs/heads/<trunk> HEAD <old-trunk-sha>`.
8. Push
- `git push <remote> <trunk>`.
- Rejected → fetch, re-evaluate, rebase once if safe, retest critical checks, retry.
- Never force-push trunk.
Report: trunk/remote, branch old→new SHA, rebase yes/no, tests, pushed SHA, follow-up.