Skip to content

fix(staged): clean up clone directory when deleting a repo#486

Merged
matt2e merged 2 commits intomainfrom
delete-repo
Mar 26, 2026
Merged

fix(staged): clean up clone directory when deleting a repo#486
matt2e merged 2 commits intomainfrom
delete-repo

Conversation

@matt2e
Copy link
Contributor

@matt2e matt2e commented Mar 26, 2026

Summary

  • When deleting an action context, clean up the associated git clone directory if no other action contexts reference the same repo
  • Added get_action_context and count_action_contexts_for_repo store methods to support the cleanup logic
  • Also removes the parent owner directory if it becomes empty after cleanup

Test plan

  • Delete a repo that has a single action context and verify the clone directory is removed
  • Delete a repo that has multiple action contexts and verify the clone directory is preserved until the last one is deleted
  • Verify no errors when the clone directory doesn't exist

🤖 Generated with Claude Code

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>
@matt2e matt2e requested review from baxen and wesbillman as code owners March 26, 2026 04:48
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +1071 to +1074
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!(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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>
@matt2e matt2e merged commit ab892d6 into main Mar 26, 2026
4 checks passed
@matt2e matt2e deleted the delete-repo branch March 26, 2026 05:35
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.

2 participants