Skip to content

feat(desktop): extend discard all to delete untracked/new files#1174

Merged
Kitenite merged 1 commit intomainfrom
kitenite/discard-should-delete-created-file-as-well
Feb 3, 2026
Merged

feat(desktop): extend discard all to delete untracked/new files#1174
Kitenite merged 1 commit intomainfrom
kitenite/discard-should-delete-created-file-as-well

Conversation

@Kitenite
Copy link
Copy Markdown
Collaborator

@Kitenite Kitenite commented Feb 3, 2026

Summary

  • Discard All Unstaged now also deletes untracked files after reverting tracked file modifications
  • Discard All Staged now also deletes staged new files (files with status "added") after unstaging
  • Updated dialog text to reflect the new behavior

Previously, "Discard All" only ran git checkout -- . which left untracked files untouched. This extends the functionality to provide a cleaner "discard everything" experience.

Test plan

  • Create a new file (untracked), then click "Discard all unstaged" → file should be deleted
  • Stage a new file, then click "Discard all staged" → file should be deleted
  • Modify an existing file, then "Discard all unstaged" → changes should be reverted
  • Stage modifications to an existing file, then "Discard all staged" → changes should be reverted

Summary by CodeRabbit

  • Bug Fixes

    • Discarding unstaged changes now also deletes untracked files that were captured before discard.
    • Discarding staged changes now removes newly staged files after un-staging.
  • Documentation

    • Confirmation dialogs updated to clearly state that untracked files (unstaged) or newly staged files (staged) will be deleted.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 3, 2026

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

Extends discard mutations to detect and remove untracked and staged-new files: adds Git-status parsing helpers and secure file deletion in backend mutations, and updates UI dialog text to reflect deletion behavior.

Changes

Cohort / File(s) Summary
Staging router (Git helpers & discard logic)
apps/desktop/src/lib/trpc/routers/changes/staging.ts
Adds imports for simple-git, parseGitStatus, assertRegisteredWorktree; introduces helpers to list untracked and staged-new files and deleteFiles using secureFs; captures these lists before discard operations and deletes matching files after discards in discardAllUnstaged and discardAllStaged.
UI descriptions
apps/desktop/src/renderer/screens/main/components/WorkspaceView/RightSidebar/ChangesView/ChangesView.tsx
Updates AlertDialogDescription copy to state that untracked files will be deleted when discarding unstaged changes, and that staged new files will be deleted when discarding staged changes.

Sequence Diagram

sequenceDiagram
    actor User
    participant UI as ChangesView (UI)
    participant Router as staging.ts (TRPC)
    participant Git as Git Utilities (simple-git)
    participant FS as File System (secureFs)

    User->>UI: Click "Discard All Unstaged" or "Discard All Staged"
    UI->>Router: discardAllUnstaged()/discardAllStaged()
    Router->>Git: parseGitStatus() -> get list of target files
    Git-->>Router: [untracked / staged-new file paths]
    Router->>Router: perform git discard/un-stage operations
    Router->>FS: deleteFiles([target paths])
    FS-->>Router: deletion results
    Router-->>UI: success/failure
    UI-->>User: show result
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Poem

🐰 Hop-hop, I parsed the tree and found,

Untracked sprouts that must be unbound.
Discard and tidy, then prune with care,
The worktree breathes cleaner air! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main change: extending discard functionality to delete untracked and new files.
Description check ✅ Passed The description is mostly complete with summary, test plan, and context. However, it lacks some template sections like Type of Change, Related Issues, and Screenshots.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch kitenite/discard-should-delete-created-file-as-well

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Previously, "Discard All" only reverted modifications to tracked files
and left untracked files untouched (standard git behavior). This extends
the functionality to also delete untracked files, providing a cleaner
"discard everything" experience.

Changes:
- discardAllUnstaged now deletes untracked files after reverting tracked
- discardAllStaged now deletes staged new files after unstaging
- Updated dialog text to reflect the new behavior
@Kitenite Kitenite force-pushed the kitenite/discard-should-delete-created-file-as-well branch from 6564a4f to aaaba7c Compare February 3, 2026 22:02
@Kitenite Kitenite merged commit 74c2b55 into main Feb 3, 2026
3 of 5 checks passed
@Kitenite Kitenite deleted the kitenite/discard-should-delete-created-file-as-well branch February 3, 2026 22:03
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 3, 2026

🧹 Preview Cleanup Complete

The following preview resources have been cleaned up:

  • ⚠️ Neon database branch
  • ⚠️ Electric Fly.io app

Thank you for your contribution! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant