Skip to content

Comments

fix(workspaces): allow removing projects when repo folder was deleted on disk#1

Closed
bilalbayram wants to merge 1 commit intofeat/settings-shortcuts-searchfrom
fix-deleted-repo-project-removal
Closed

fix(workspaces): allow removing projects when repo folder was deleted on disk#1
bilalbayram wants to merge 1 commit intofeat/settings-shortcuts-searchfrom
fix-deleted-repo-project-removal

Conversation

@bilalbayram
Copy link
Owner

Summary

Fix workspace/worktree removal when repositories are deleted directly from disk (outside the app), so stale entries can still be removed from Projects.

User-visible Problem

If a parent repository folder is deleted from the filesystem and the user then tries to remove that project in CodexMonitor, removal can fail with errors like:

  • Failed to remove one or more worktrees; parent workspace was not removed.
  • Failed to run git: No such file or directory (os error 2)

This leaves stale project/worktree entries in the app.

Root Cause

remove_workspace_core and remove_worktree_core attempted git worktree commands unconditionally when the child worktree path existed.

Those commands run with current_dir set to the parent repo path. When the parent directory has already been deleted, process spawn fails at the OS level (os error 2) before git can return a normal semantic worktree error.

Because that OS error does not match is_missing_worktree_error, the removal flow treated it as a hard failure (or accumulated child failures), and parent workspace deletion could be blocked.

What Changed

  1. remove_workspace_core now checks whether the parent repo path exists as a directory.
  2. If the parent repo path is missing:
  • Skip git worktree remove calls.
  • Remove child worktree directories directly via filesystem cleanup.
  • Skip git worktree prune.
  1. remove_worktree_core now applies the same missing-parent-path behavior for single worktree removal.
  2. Existing behavior is preserved when the parent repo path exists: git-based removal/prune still runs as before.

Why This Is Safe

  • No contract/API changes in Tauri or daemon RPC surfaces.
  • No changes to workspace/worktree IDs, persistence schema, or payload shapes.
  • Logic only diverges in a failure-path condition (missing parent repo directory).
  • Normal in-repo removal path remains unchanged.

Regression Tests Added

Added tests in src-tauri/src/workspaces/tests.rs:

  • remove_workspace_succeeds_when_parent_repo_folder_is_missing
  • remove_worktree_succeeds_when_parent_repo_folder_is_missing

Both tests assert:

  • Removal succeeds when parent repo path is absent.
  • Filesystem worktree folder is cleaned up.
  • In-memory workspace map is updated correctly.
  • Git command path is not invoked in this missing-parent scenario.

Validation

Executed:

  • cargo test --manifest-path src-tauri/Cargo.toml remove_workspace_succeeds_when_parent_repo_folder_is_missing
  • cargo test --manifest-path src-tauri/Cargo.toml remove_worktree_succeeds_when_parent_repo_folder_is_missing
  • cargo check --manifest-path src-tauri/Cargo.toml
  • npm run typecheck

All passed.

Files Changed

  • src-tauri/src/shared/workspaces_core/crud_persistence.rs
  • src-tauri/src/shared/workspaces_core/worktree.rs
  • src-tauri/src/workspaces/tests.rs

When a main workspace directory is deleted outside CodexMonitor, removal still attempted `git worktree remove` using the missing parent repo as current_dir. That produced `Failed to run git: No such file or directory (os error 2)`, caused child failures to accumulate, and blocked parent workspace removal.

This patch updates shared workspaces core removal paths to treat missing parent repo folders as a filesystem-only cleanup flow:

- In `remove_workspace_core`, skip git worktree remove/prune when parent path is not an existing directory, and remove child worktree folders directly.

- In `remove_worktree_core`, skip git worktree remove/prune when parent path is missing and remove the worktree folder directly.

- Added regression tests covering both parent-project removal and single-worktree removal when the parent repo folder no longer exists; tests assert the operation succeeds and git is not invoked.

Validation run:

- cargo test --manifest-path src-tauri/Cargo.toml remove_workspace_succeeds_when_parent_repo_folder_is_missing

- cargo test --manifest-path src-tauri/Cargo.toml remove_worktree_succeeds_when_parent_repo_folder_is_missing

- cargo check --manifest-path src-tauri/Cargo.toml

- npm run typecheck
@bilalbayram
Copy link
Owner Author

Superseded by upstream PR: Dimillian#421

@bilalbayram bilalbayram deleted the fix-deleted-repo-project-removal branch February 12, 2026 14:03
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