Repository navigation
fix(git): sweep untracked leftovers in resetToCleanMaster - #1253
Conversation
resetToCleanMaster counts untracked files as dirty (status.not_added), but git reset --hard HEAD leaves them in place. An untracked leftover therefore survives the team repo's self-heal and breaks the steps it precedes: git checkout <default> rejects with "untracked working tree files would be overwritten by checkout" when the leftover sits at a path the default branch tracks, and the error propagates to push as "Pull failed", wedging the clone until the user runs the manual "reset --hard && git clean -fd" that push.ts's rollback message already recommends. Mirror the idiom every other clean-the-team-repo site already uses (pushRepoBranch, push.ts's failed-push rollback): clean -fd after the reset, still without -x so ignored files stay. Callers keep their isDedicatedRepoRoot guards, and push.ts's unsafe-dirty gate still refuses unrelated user changes before the reset runs. Co-Authored-By: Claude Code <[email protected]>
|
No findings in the specified diff. The PR description documents sufficient testing: mocked unit tests, a real-Git regression test, and a representative real-CLI run with provider |
SaulMoro
left a comment
There was a problem hiding this comment.
This was generated by AI during triage.
The PR adds git clean -fd after reset --hard HEAD in resetToCleanMaster, so an untracked leftover no longer blocks the switch back to the default branch. The earlier bot review reported no findings. I checked both callers. pushCore (src/push.ts:1162) refuses any untracked path except the ones it has already captured and restores afterwards (src/push.ts:1146-1168), so the sweep can only remove paths TeamAI puts back. The other caller (src/team-push.ts:1156) has no such gate. It is not reached in production, though: its only caller (src/pull.ts:3191) always passes selfConfig for non-HTTP repos, which takes the reports-branch path. Without -x, ignored files stay. Nested repos and linked worktrees inside the clone also stay, and the side-branch worktrees live next to the clone, not inside it (src/types.ts:2886-2894).
Local checks, run on the merge of 064a6bd into origin/main 0da2be76 (clean merge):
npx tsc --noEmit: OK.npm run lint: exit 0.npm run build: OK.npx vitest runon the touched and neighbouring tests (git,team-ref,push*,team-push*): 326 passed. Fullnpx vitest run: 11469 passed, 1 failed (hooks-reconcile-scope.test.tsENOTDIR). That failure also happens on anorigin/mainworktree, so it comes from the worktree environment, not from this PR.- Red/green: the new
team-reftest fails onorigin/main'sgit.tswith "untracked working tree files would be overwritten by checkout" and passes with the PR. - Real CLI (
node dist/index.js push --all, providergit, agent Claude, project scope, throwaway HOME). The clone was stuck on a stale push branch, upstreammaintrackedenv/backend/env.yaml, and the member's edit sat untracked at that path. Onorigin/mainthe push printedPull failed: ... would be overwritten by checkout. With the PR it printedUp to date, pushed the branch carrying the member's env edit, and left HEAD onmain. Two safety runs: with an unrelated untrackednotes/mine.md, push still refused before resetting and kept the file. With an ignored file (.git/info/exclude), push succeeded and kept the file.
Findings
- None.
Not covered
- Providers
gitlab/githuband agents other than Claude were not run. The change sits below provider and agent code. - Windows was not tested.
Verdict: Approve.
…eToTeam (#1293) reportUsageToTeam now requires selfConfig and always writes through the teamai-reports branch. The legacy branch that reset the team-repo clone had no caller, and since #1253 it could delete untracked files in the clone. An HTTP repo returns false before any report I/O. The updateReports callback keeps returning the files on every attempt, so a retry still pushes a commit left unpushed (#1291). Closes #1259 Co-authored-by: Saul Moro <[email protected]>
resetToCleanMaster counts untracked files as dirty (status.not_added), but git reset --hard HEAD leaves them in place. An untracked leftover therefore survives the team repo's self-heal and breaks the steps it precedes: git checkout <default> rejects with "untracked working tree files would be overwritten by checkout" when the leftover sits at a path the default branch tracks, and the error propagates to push as "Pull failed", wedging the clone until the user runs the manual "reset --hard && git clean -fd" that push.ts's rollback message already recommends. Mirror the idiom every other clean-the-team-repo site already uses (pushRepoBranch, push.ts's failed-push rollback): clean -fd after the reset, still without -x so ignored files stay. Callers keep their isDedicatedRepoRoot guards, and push.ts's unsafe-dirty gate still refuses unrelated user changes before the reset runs. Co-authored-by: Claude Code <[email protected]>
…eToTeam (Tencent#1293) reportUsageToTeam now requires selfConfig and always writes through the teamai-reports branch. The legacy branch that reset the team-repo clone had no caller, and since Tencent#1253 it could delete untracked files in the clone. An HTTP repo returns false before any report I/O. The updateReports callback keeps returning the files on every attempt, so a retry still pushes a commit left unpushed (Tencent#1291). Closes Tencent#1259 Co-authored-by: Saul Moro <[email protected]>
Problem
resetToCleanMaster(src/utils/git.ts) counts untracked files as dirty (status.not_addedfeedsisDirty, and the debug line even prints "N untracked"), butgit reset --hard HEADleaves untracked files untouched — so the team repo's designated self-heal never actually sweeps them.pushRepoBranch's own comments ("a skipped switch self-heals via resetToCleanMaster on the next run") promise recovery the function cannot deliver for untracked leftovers.An untracked leftover then breaks the steps the reset precedes:
switchToDefaultBranch→git checkout <default>rejects witherror: The following untracked working tree files would be overwritten by checkoutwhen the leftover sits at a path the default branch tracks (e.g. a teammate's merged PR added that path after a crashed push left the clone on a stale push branch). The throw propagates:pushreportsPull failed: ..., setsteamRepoStale, and aborts. Nothing ever clears the file — every retry hits the same wall until the user manually runs thegit reset --hard && git clean -fdthatpush.ts's own rollback warning already recommends.pullRepo's ff-only pull hits the same "would be overwritten by merge" error and detours through its destructivefetch+reset --hard origin/<branch>recovery, clobbering the file mid-flow. The env snapshot-restore inpushCoreexists precisely to survive resets like that ([bug] push refuses the env files env add leaves in a standalone clone #881); the pull should not need it.Every other clean-the-team-repo site already pairs the reset with the sweep:
pushRepoBranch(twice),push.ts's failed-push rollback, andpullRepo's recovery even computes its dirty count excludingnot_addedbecause it knowsreset --hardcannot sweep them.resetToCleanMaster— whose documented contract is "Reset the team repo to a clean default-branch state" — was the one site missing it.Fix
Mirror the established idiom: when the repo is dirty, run
git.clean('f', ['-d'])right aftergit reset --hard HEAD. Without-x, ignored files stay. Both callers keep theirisDedicatedRepoRootguards, andpush.ts's unsafe-dirty gate still refuses unrelated user changes beforeresetToCleanMasterruns — the sweep only reaches teamai-owned paths (env edits, whichpushCorere-writes from its snapshot) and crash residue. The two skill-data passages that say TeamAI "refuses to reset a team-repo clone with unrelated modified, staged, untracked, or conflicted files" stay true.Testing
resetToCleanMastercases ingit.test.tsnow assert the clean call, plus a new case for anot_added-only dirty state; the clean-repo case asserts no clean.team-ref.test.ts— a crashed push left the clone on a stale branch whose tree lacksvotes/stray.yaml, a later crashed run left that path behind untracked, and upstream tracks it.resetToCleanMastermust resolve, land onmain, and leave upstream's content. Fails onmainwithThe following untracked working tree files would be overwritten by checkout.npx vitest run→ 11461 passed, 1 failed (hooks-reconcile-scope.test.ts, the known ENOTDIR artifact of running inside a git worktree —.gitis a file there; passes in a plain checkout).npx tsc --noEmitandnpm run lintclean.E2E with the real CLI (
dist/index.js, providergit, agent Claude)Setup: team repo with projects/roles manifests; a teammate's merged PR adds
env/backend/env.yamltomain; the member's clone is stuck on a staleteamai/push/...branch cut from pre-envmainwhile localmainis up to date;env addleft its edit behind untracked at that path; a local skill/rule/agent await push.Baseline (upstream
main, fa6a361):This PR:
The pushed branch carries the member's env edit (
API_URL: https://mine.example.com,TOKEN: s3cr3t) — verified withgit show <branch>:env/backend/env.yaml— so the captured env edit survived the sweep exactly as the #881 snapshot-restore intends, and this time the pull itself was a clean fast-forward instead of the destructive reset-recovery detour.🤖 Generated with Claude Code