From bddf1a4bf87652f8ee89444af98e184a543a113a Mon Sep 17 00:00:00 2001 From: gsxdsm Date: Tue, 17 Feb 2026 23:19:38 -0800 Subject: [PATCH] fix: Handle staged-new files correctly in discard changes --- apps/server/src/routes/worktree/routes/discard-changes.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/server/src/routes/worktree/routes/discard-changes.ts b/apps/server/src/routes/worktree/routes/discard-changes.ts index 7bf1a4ec..966351ee 100644 --- a/apps/server/src/routes/worktree/routes/discard-changes.ts +++ b/apps/server/src/routes/worktree/routes/discard-changes.ts @@ -122,12 +122,18 @@ export function createDiscardChangesHandler() { if (indexStatus === '?' && workTreeStatus === '?') { untrackedFiles.push(file.path); + } else if (indexStatus === 'A') { + // Staged-new file: must be reset (unstaged) then cleaned (deleted). + // Never pass to trackedModified — the file has no HEAD version to + // check out, so `git checkout --` would fail or do nothing. + stagedFiles.push(file.path); + untrackedFiles.push(file.path); } else { // Check if the file has staged changes (index status X) if (indexStatus !== ' ' && indexStatus !== '?') { stagedFiles.push(file.path); } - // Check for working tree changes (worktree status Y): handles MM, AM, MD, etc. + // Check for working tree changes (worktree status Y): handles MM, MD, etc. if (workTreeStatus !== ' ' && workTreeStatus !== '?') { trackedModified.push(file.path); }