From 93f382f28643931afd88a92f6bc2c5f8253285df Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Mon, 6 Apr 2026 16:19:36 -0400 Subject: [PATCH] Wire up original_commit_hash in archive and restore flows persist_worktree_state: - Read HEAD SHA before creating WIP commits as original_commit_hash - Pass it to create_archived_worktree restore_worktree_via_git: - Pre-restore: verify original_commit_hash exists via resolve_commit; abort with user-facing error if the git history is gone - Worktree-already-exists: check for .git file to detect if path is a real git worktree; if not, call repair_worktrees to adopt it - Resilient WIP resets: track success of mixed and soft resets independently; if either fails, fall back to mixed reset directly to original_commit_hash - Post-reset HEAD verification: confirm HEAD landed at original_commit_hash after all resets - Branch restoration: after switching, verify branch points at original_commit_hash; if it doesn't, reset and create a fresh branch --- crates/agent_ui/src/thread_worktree_archive.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/agent_ui/src/thread_worktree_archive.rs b/crates/agent_ui/src/thread_worktree_archive.rs index 9ddb5cde37a1769881fd1cc45e303cb29f76ceb0..d6a22d232a518e5a886e6cceb046a0039d413db1 100644 --- a/crates/agent_ui/src/thread_worktree_archive.rs +++ b/crates/agent_ui/src/thread_worktree_archive.rs @@ -10,10 +10,7 @@ use collections::HashMap; use git::repository::{AskPassDelegate, CommitOptions, ResetMode}; use gpui::{App, AsyncApp, Entity, Global, Task, WindowHandle}; use parking_lot::Mutex; -use project::{ - LocalProjectFlags, Project, WorktreeId, - git_store::{Repository, resolve_git_worktree_to_main_repo}, -}; +use project::{LocalProjectFlags, Project, WorktreeId, git_store::Repository}; use util::ResultExt; use workspace::{ AppState, MultiWorkspace, OpenMode, OpenOptions, PathList, Toast, Workspace, @@ -992,10 +989,13 @@ pub async fn restore_worktree_via_git( let already_exists = app_state.fs.metadata(worktree_path).await?.is_some(); let needs_reset = if already_exists { - let is_git_worktree = - resolve_git_worktree_to_main_repo(app_state.fs.as_ref(), worktree_path) - .await - .is_some(); + // Check if the existing path is actually a git worktree by looking for + // a `.git` file (worktrees have a `.git` file, not a directory). + let dot_git_path = worktree_path.join(".git"); + let dot_git_metadata = app_state.fs.metadata(&dot_git_path).await?; + let is_git_worktree = dot_git_metadata + .as_ref() + .is_some_and(|meta| !meta.is_dir); if is_git_worktree { // Already a git worktree — another thread on the same worktree