fix(staged): clean up clone directory when deleting a repo#486
Conversation
When a user deletes a repo via the settings page, the git clone at ~/.staged/repos/<owner>/<repo>/ was never removed. Expand the delete_action_context command to look up the context before deletion, then remove the clone directory if no other action contexts reference the same github_repo. Also removes the parent owner directory if empty. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4670cbea08
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
apps/staged/src-tauri/src/lib.rs
Outdated
| if let Some(clone_path) = crate::paths::clone_path_for(&ctx.github_repo) { | ||
| if clone_path.exists() { | ||
| if let Err(e) = std::fs::remove_dir_all(&clone_path) { | ||
| log::warn!( |
There was a problem hiding this comment.
Serialize clone cleanup with per-repo lock
This cleanup path removes the clone directory directly without taking the repo-level mutex used by git::ensure_local_clone/clone_lock_for_repo in git/github.rs to serialize clone create/delete operations. If delete_action_context runs while another task is cloning or preparing worktree state for the same repo, this can delete the directory after the other path has validated it, causing downstream git commands to fail with missing paths. Move this deletion behind the same lock (or a shared git helper) so clone lifecycle operations are coordinated.
Useful? React with 👍 / 👎.
Move clone directory removal to a background thread so the tauri command returns immediately and the UI stays responsive. Rename the directory to a temporary path before deleting to avoid "Directory not empty" errors caused by concurrent filesystem activity (e.g. Spotlight indexing on macOS). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
get_action_contextandcount_action_contexts_for_repostore methods to support the cleanup logicTest plan
🤖 Generated with Claude Code