Repository navigation
fix(push): reuse an existing --branch destination - #1827
Conversation
The description includes a representative real-CLI verification record, so there is no missing-testing finding. No PR code was executed. |
SaulMoro
left a comment
There was a problem hiding this comment.
This was generated by AI during triage.
Reviewed at 8dfe3cc6, with the CLI built at this head and at main (107afae0) and run in verify worlds. The case in the body works: pushing twice to release/knowledge leaves both skills on the branch. But reusing any existing local branch, without checking what that branch is, opens up three paths main refused.
[P1 blocking] --branch main now pushes straight to the default branch. checkoutExplicitBranch finds main among the local branches, checks it out, commits, and pushes it. On main the same command fails with "a branch named 'main' already exists", so nothing lands without a PR. #663 settled this: --branch on push, and no --direct. Refuse the default branch (and any branch the team repo protects by convention) as a destination.
[P1 blocking] In self mode, --branch <member's own branch> publishes that branch's unpushed commits. The team checkout shares refs with the member's repo. Repro: init --self; the member has feature/mine with an unpushed commit; teamai push --all --branch feature/mine. The run exits 1, but origin/feature/mine now holds the member's commit and teamai's. On main it fails before pushing anything. Reuse a local branch only when every commit beyond origin/<name> (or the default branch, when origin has none) is one teamai wrote; otherwise refuse and name the branch.
[P1 blocking] A destination that already has a file the push writes can't take the next push. The payload is written on the default branch before the checkout. If teamai.yaml (or a skill file) differs between main and the destination, git checkout <name> aborts with "untracked working tree files would be overwritten". So a second edit to the same skill fails, which is the common way to reuse a branch. The automated review found the same thing. Both new team-ref cases write distinct files (a.txt, b.txt), so neither hits it. Switch branches first, then apply the payload, and add a row that edits the same file twice.
[P2 non-blocking]
- The local-branch path never looks at origin. After a colleague pushes to the destination, every later
--branchpush is rejected non-fast-forward until the member deletes the local branch by hand. Nothing is lost, but the error doesn't point there. - With a reused local branch, the no-change cleanup can force-delete a destination that still holds a commit that never reached origin: a commit succeeded, its push failed, and the retry stages nothing new. I couldn't reach this through the CLI, but the code path is there (the automated review rates it P1).
- The
git.test.tscases assert which git calls ran. The real-git rows inteam-ref.test.tsare what proves this; extend those.
Not from this PR, for a separate issue: after any failed push the team checkout stays on the unpushed branch, and teamai pull then fails with "couldn't find remote ref". This also happens on main. The pending-PR reuse path also force-pushes over a colleague's commit on the destination, with a lease. That too is main's behaviour.
8dfe3cc to
28965e0
Compare
|
All three earlier findings remain unresolved in the current diff:
The description contains a representative real-CLI verification record, so there is no missing-testing finding. Its older recorded commit is not blocking under the review rules. No PR code was executed. |
28965e0 to
8dd7e37
Compare
Earlier findings: unpublished-commit cleanup and remote advancement are resolved. Successive file replacement is fixed for copied resources and config-only pushes, but remains broken for the mixed config/resource case above. The description includes a representative real-CLI verification record, so there is no missing-testing finding. No PR code was executed. |
8dd7e37 to
45ed604
Compare
All earlier findings are resolved, including the mixed config/resource checkout collision. The description includes a representative real-CLI verification record, so there is no missing-testing finding. No PR code was run, built, or installed. |
SaulMoro
left a comment
There was a problem hiding this comment.
This was generated by AI during triage.
Re-reviewed 45ed604b with the CLI built at this head and run in verify worlds. Two of the earlier findings are fixed. A second push that edits the same file now succeeds, for both teamai.yaml and a skill file. A retry with nothing new now publishes the commit an earlier push couldn't, instead of deleting the branch. Two blockers from the last round are still open, and the new carry/restore adds a third.
[P1 blocking] --branch main still pushes straight to the default branch. Reproduced: origin's main gained the skill, with no PR. Main refuses this. Refuse the team repo's default branch as a destination (per #663: --branch, no --direct).
[P1 blocking] Self mode, --branch <member's own branch> still publishes the member's unpushed commit. Reproduced with the member on main and feature/mine holding an unpushed commit. The member's files are untouched; the push runs in a throwaway worktree. But origin/feature/mine now carries their commit. With the member checked out on feature/mine, the push fails with a worktree collision instead of a clear refusal. Reuse a local branch only when every commit beyond origin/<name> (or the default branch) is one teamai wrote; otherwise refuse and name the branch.
[P1 blocking] carryWorkingTree/restoreWorkingTree can lose the team checkout's uncommitted edits. The edits only exist in the teamai-push-carry-* backup between the hard reset and the restore, and three paths drop it:
carryWorkingTreecatches any error afterreset --hard(for example a failedclean) and removes the backup before rethrowing. The reset has already discarded the edits.restoreWorkingTreeremoves the backup infinally, even when a copy fails partway.- A process killed during the destination fetch leaves the edits only in the temp backup. Nothing prints its path, and a retry doesn't recover it. Reproduced with a pending
teamai.yamledit.
Keep the backup whenever the restore didn't complete, and print its path. Better still, don't move the edits out of git at all: git stash push --include-untracked, then stash pop, keeps them recoverable through git stash list even after a crash.
[P2 non-blocking] A staged rename comes back as a duplicate: only file.path is carried, and the hard reset recreates the old name. This is from the automated review.
Not from this PR: a second --branch push for resources already pushed goes through the pending-record reuse path. That path force-pushes with a lease it has just refreshed, so it overwrites a colleague's commit on the destination and reports ✔ Pushed branch. Main does the same. But the body says a second push "reuses the destination", so either narrow that claim or leave a note that this path is separate.
45ed604 to
d3774cb
Compare
All earlier findings are resolved in the current diff. The description includes a representative real-CLI verification record, so there is no missing-testing finding. No PR code was run, built, or installed. |
Thanks.
|
d3774cb to
a6c1d08
Compare
|
No new findings in the current diff. All earlier findings are resolved, including recreated rename sources and dangling symlinks. The description includes a representative real-CLI verification record, so there is no missing-testing finding. Its older recorded commit is not blocking under the review rules. Reviewed only the specified diff; no PR code was run, built, or installed. |
a6c1d08 to
926fc9e
Compare
|
Addressed at 926fc9e:
Tests at this head: 212 across the five push suites, including refusals for the default branch and the self-mode checkout; typecheck and lint pass. |
|
No new findings in the specified diff. All earlier findings are resolved, including recreated rename sources, dangling symlinks, and backup retention after restoration failures. The PR description includes a representative real-CLI verification record, so there is no missing-testing finding. Its older recorded commit is not blocking under the trusted review rules. No PR code was run, built, or installed. |
SaulMoro
left a comment
There was a problem hiding this comment.
This was generated by AI during triage.
926fc9e1. The default-branch refusal is right. So is the reason for keeping the file-copy carry over a stash: a pop would conflict on exactly the payload this moves. With the carry directory now named in debug.log before the reset, I'm fine with the crash path.
One blocker left. [P1 blocking] The self-mode check only compares --branch with the branch checked out right now. In the case I reproduced last round, the member is on main and feature/mine holds an unpushed commit. teamai push --all --branch feature/mine passes this check, checkoutExplicitBranch reuses feature/mine in the throwaway worktree, and origin/feature/mine ends up with the member's commit. The member's checkout is only one way to hold their work; in self mode every local branch is theirs.
The refusal belongs where the branch is reused, not where it's named. In self mode, when a local <name> exists, refuse if it has any commit that's not on origin (git rev-list --count <name> --not --remotes=origin > 0). Name the branch and how many commits it holds. A <name> with no local branch, or one that matches origin, can go ahead as it does now. A row in the self-mode push tests with the member on main and an unpushed commit on the named branch would pin it.
926fc9e to
d40bde3
Compare
|
No new findings in the specified diff. All earlier findings are resolved, including mixed config/resource checkout collisions, unpublished commits, remote advancement, rename handling, dangling symlinks, and backup retention after restoration failures. The PR description includes a representative real-CLI verification record, so there is no missing-testing finding. Its older recorded commit is not blocking under the trusted review rules. Reviewed only the specified diff against the base-version review criteria. No PR code was run, built, or installed. |
SaulMoro
left a comment
There was a problem hiding this comment.
This was generated by AI during triage.
Approving d40bde31. The self-mode check now runs on the named branch itself: an existing local <name> with any commit not on origin is refused, and an unreadable count is refused too. That covers the member-on-main case from the earlier rounds. With the default-branch refusal and the carry fixes, every blocking point from the earlier rounds is resolved.
- [P3 nit] The new self-mode test mocks
git.raw. A real-git row inteam-ref.test.tswould prove therev-listcount against an actual unpushed commit. There's also a stray whitespace-only line after that test. - One side effect worth knowing: in self mode, a destination left behind by an earlier push that committed but never reached origin is now refused too. It's still the safe side, and the message tells the member what to do.
I'll merge once CI is green.
An explicit `teamai push --branch <name>` passed the name to pushRepoBranch, whose non-reuse path ran `git checkout -b`. A branch an earlier push left locally made that fail with "a branch named ... already exists"; when only origin had the branch, the new commit was based on the default branch and the push was rejected non-fast-forward. Prepare the named destination before callers copy the payload, so the checkout cannot collide with a file the destination already holds. Pending config or env edits are carried aside and restored: a replacement at a renamed source, a dangling symlink, and a failed restore's backup are all preserved, and the backup path is logged before the reset so a killed process leaves a trace. Fetch origin, fast-forward a local branch with no unpushed commit, rebase one that has them, and create a missing branch from origin. On a retry whose tree holds nothing new, publish the unpushed commit instead of deleting the destination. Refuse a destination that is the default branch. In self mode, refuse a local destination branch holding any commit not on origin: every local branch there is the member's, so reusing it would publish their work. Tests: unit cases for both destinations and both refusals, real-git cases for a replaced file, a pending edit, staged renames (including a recreated source), a dangling symlink, an unpushed retry, an origin advance, and a self-mode refusal against a real unpushed commit, plus a real-CLI before/after on e30376d and this head. Co-Authored-By: Claude Code <[email protected]>
d40bde3 to
791cfad
Compare
|
Addressed the P3 note at 791cfad:
All five push suites pass (213 tests), plus typecheck, lint and build. The earlier approval was at d40bde3; this commit adds the real-git row and the extraction only. |
SaulMoro
left a comment
There was a problem hiding this comment.
This was generated by AI during triage.
Approving 791cfadb. explicitBranchRefusal is a straight extraction of the two checks, with the same messages and order. The new real-git row covers the member on main with an unpushed commit on feature/mine, the same branch outside self mode, and the default branch. I'll merge once CI is green.
|
No new findings in the specified diff. All earlier findings are resolved. The PR description includes a representative real-CLI verification record, so there is no missing-testing finding. Its older recorded commit is not blocking under the trusted review rules. Reviewed against the base-version Code Review Rules. No PR code was run, built, or installed. |
Summary
teamai push --branch <name>could only be used once per destination. The explicit name reachedpushRepoBranch's non-reuse path, which always rangit checkout -b. A branch an earlier push left locally made the next run fail with git'sa branch named '<name>' already exists; when only origin had the branch, the new commit was based on the default branch and the push was rejected non-fast-forward.The destination is now prepared before callers copy the payload into the working tree, so the checkout can never collide with a file the branch already holds. Any pending config or env edit already in the working tree is carried aside and restored after the switch:
--branchcannot publish the member's work directly.Generated
teamai/push/...branches and pending-PR reuse groups keep their old path.Type of Change
Test Plan
npx vitest run src/__tests__/git.test.ts— 76 pass. Two new unit cases: a local destination is checked out instead ofcheckout -b; a destination only on origin is fetched and created fromorigin/<name>.npx vitest run src/__tests__/team-ref.test.ts— 61 pass. Real-git cases push twice torelease/sharedwith a replaced file, with a pending edit in the working tree, with staged renames (including a recreated source path), with a dangling symlink, with a commit whose push failed (pre-receive hook), with origin advanced between pushes, and refuse a self-mode destination holding a real unpushed commit.npx vitest run src/__tests__/push-pending-pr.test.ts src/__tests__/push-team-config.test.ts src/__tests__/push-env.test.ts— pass; 213 tests across the five push files. New unit cases refuse--branch mainand, in self mode, a local destination branch with unpushed commits while the member is onmain. Four rollback tests inpush-env.test.tsused an existing localteamai/takenbranch to make branch creation fail; they now use an invalid branch name for the same injection, since an existing destination is supported after this fix.npm run typecheckpasses.npm run lintpasses, including the documentation checks.Real CLI after
npm run build, in a temporary HOME with a user-scope config, a local team repo, and--provider git(so PR creation fails after the branch is pushed; the branch content is the assertion):alphawith bodyv1.teamai.yamlwith a member note.alpha'sSKILL.mdto bodyv2, add skillbeta, edit the clone'steamai.yaml(the payload carried across the branch switch), and run the same command again.origin/main(e30376d): the second push fails witha branch named 'release/knowledge' already exists, and the branch holds only thev1alpha skill.45ed604; later commits only harden refusals, staged renames, symlinks, failed-restore backups, and the self-mode count): the second push succeeds and the branch holds the member's alphav2, beta, and the teamai.yaml edit:Notes for Reviewers
explicitBranchis set only when--branchnames the destination of a group with no pending PR record; a reuse group continues to use its recorded branch.pushItemcopies resources, which is what lets a second push replace a file the first push committed. Pending config/env edits in the tree are copied aside before the switch and restored after it, so the checkout neither loses nor collides with them.lstatso a dangling symlink is backed up rather than treated as absent. A failed restore keeps the backup directory and names it instead of deleting the only remaining copy; the backup path is also logged before the reset, so a killed process leaves a trace indebug.log.--branch mainis refused before any payload is copied. In self mode the named local branch is checked even when the member is on another branch: any commit it holds beyond origin refuses the push, naming the branch and count. A real-git row pins therev-listcount against an actual unpushed commit, and the stray whitespace line from review is gone.push-env.test.tsrollback tests were updated only in their failure injection (invalid destination instead of a pre-existing valid one); their assertions are unchanged.🤖 Generated with Claude Code