Wire up original_commit_hash in archive and restore flows

Richard Feldman created

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

Change summary

crates/agent_ui/src/thread_worktree_archive.rs | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)

Detailed changes

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