pi-ext
bugabingas pi extensions
owned by bugabinga
description: Sync current git/jj branch into trunk via rebase + fast-forward
argument-hint: "[trunk] [test-command]"
Sync current git/jj branch into trunk via rebase + fast-forward
Sync current branch/bookmark into trunk.
Linear history only.
No merge commits.
Never force-push trunk.
Args:
if $1 is branch/ref/bookmark → trunk, ${@:2} → tests.
Else infer trunk, $ARGUMENTS → tests.
If jj root succeeds, use jj:
- Inspect:
jj status, jj bookmark list, jj git remote list, jj log -r '<trunk>..@'.
- Stop on conflicts, dirty unrelated working-copy change, ambiguous
trunk/bookmark, or non-git-backed jj repo when push is needed.
- Fetch/update:
jj git fetch --remote <remote>.
- Rebase current stack if needed:
jj rebase -b @ -o <trunk>.
- Test as below.
- Fast-forward trunk bookmark:
jj bookmark move <trunk> --to @ (never --allow-backwards).
- Push:
jj git push --remote <remote> --bookmark <trunk>.
On reject:
fetch, re-evaluate, rebase once if safe, retest, retry.
- Report:
trunk/remote, change old→new, rebase yes/no, tests, pushed change, follow-up.
Otherwise use git:
-
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 git/jj branch into trunk via rebase + fast-forward
argument-hint: "[trunk] [test-command]"
---
# Sync current git/jj branch into trunk via rebase + fast-forward
Sync current branch/bookmark into trunk.
Linear history only.
No merge commits.
Never force-push trunk.
Args:
if `$1` is branch/ref/bookmark → trunk, `${@:2}` → tests.
Else infer trunk, `$ARGUMENTS` → tests.
If `jj root` succeeds, use jj:
1. Inspect:
`jj status`, `jj bookmark list`, `jj git remote list`, `jj log -r
'<trunk>..@'`.
2. Stop on conflicts, dirty unrelated working-copy change, ambiguous
trunk/bookmark, or non-git-backed jj repo when push is needed.
3. Fetch/update:
`jj git fetch --remote <remote>`.
4. Rebase current stack if needed:
`jj rebase -b @ -o <trunk>`.
5. Test as below.
6. Fast-forward trunk bookmark:
`jj bookmark move <trunk> --to @` (never `--allow-backwards`).
7. Push:
`jj git push --remote <remote> --bookmark <trunk>`.
On reject:
fetch, re-evaluate, rebase once if safe, retest, retry.
8. Report:
trunk/remote, change old→new, rebase yes/no, tests, pushed change, follow-up.
Otherwise use git:
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.