Add ArchivedGitWorktree data model and DB operations#53214
Merged
Conversation
…ations Extend the git API with several new capabilities needed for worktree archival and restoration: - Add allow_empty flag to CommitOptions for creating WIP marker commits - Change create_worktree to accept Option<String> branch, enabling detached worktree creation when None is passed - Add head_sha() to read the current HEAD commit hash - Add update_ref() and delete_ref() for managing git references - Add stage_all_including_untracked() to stage everything before a WIP commit - Implement all new operations in FakeGitRepository with functional commit history tracking, reset support, and ref management - Update existing call sites for the new CommitOptions field and create_worktree signature
7f05a6c to
33b4871
Compare
This argument already gets added when calling git_binary.run()
Now creating a worktree from a detached head also has remote support
This goes against what git does internally and could cause testing bugs in the future
GitStore::stage_all already does everything this method does and updates pending_ops as well. So I'm removing this method to avoid a potential foot gun in our codebase
- resolve_commit on Repository entity: wraps revparse_batch to check if a commit SHA exists in the repo. Used during restore to verify original_commit_hash is present before attempting recovery. - repair_worktrees on GitRepository trait + RealGitRepository (runs git worktree repair) and FakeGitRepository (no-op). Used during restore when a worktree directory exists on disk but may not be in git's worktree metadata. - repair_worktrees wrapper on Repository entity.
33b4871 to
c2284f4
Compare
bd78423 to
3061d32
Compare
- resolve_commit on Repository entity: wraps revparse_batch to check if a commit SHA exists in the repo. Used during restore to verify original_commit_hash is present before attempting recovery. - repair_worktrees on GitRepository trait + RealGitRepository (runs git worktree repair) and FakeGitRepository (no-op). Used during restore when a worktree directory exists on disk but may not be in git's worktree metadata. - repair_worktrees wrapper on Repository entity.
c2284f4 to
94d3f4f
Compare
13b51f6 to
8edcdbd
Compare
…s/zed into persist-worktree-1-git-api
Add the persistence layer for tracking archived git worktrees: - ArchivedGitWorktree struct with staged_commit_hash and unstaged_commit_hash fields to precisely identify WIP commits - DB migrations for archived_git_worktrees and thread_archived_worktrees (join table) tables - CRUD operations: create, link to thread, query by thread, delete - Column impl for deserializing ArchivedGitWorktree from DB rows - Tests for create/retrieve with distinct SHAs, delete cascading through join table, multi-thread linking, and multiple worktrees per thread
- New field on ArchivedGitWorktree struct storing the HEAD SHA from before WIP commits were created during archival. Used as a pre-restore sanity check, fallback reset target, and post-restore verification. - DB migration adding original_commit_hash column, backfilled from the legacy commit_hash column for existing rows. - Updated create_archived_worktree signature, SQL INSERT, and bindings on both ThreadMetadataDb and ThreadMetadataStore. - Updated SELECT query and Column impl to read the new field. - Updated all 4 archived worktree tests.
94d3f4f to
e2f2e38
Compare
rtfeldman
commented
Apr 7, 2026
rtfeldman
commented
Apr 7, 2026
Remove the old commit_hash and restored columns that were never shipped, and fold the staged_commit_hash, unstaged_commit_hash, and original_commit_hash columns directly into the CREATE TABLE statement instead of adding them via ALTER TABLE migrations. Also fix a bug in the INSERT where unstaged_commit_hash was bound twice (once where commit_hash used to go).
Anthony-Eid
approved these changes
Apr 7, 2026
MasoudAlali
pushed a commit
to MasoudAlali/zed-ide
that referenced
this pull request
Apr 7, 2026
…53214) Add the persistence layer for tracking archived git worktrees: - `ArchivedGitWorktree` struct with `staged_commit_hash` and `unstaged_commit_hash` fields to precisely identify WIP commits - DB migrations for `archived_git_worktrees` and `thread_archived_worktrees` (join table) tables - CRUD operations: create, link to thread, query by thread, delete, mark as restored - `Column` impl for deserializing `ArchivedGitWorktree` from DB rows - Tests for two-SHA round-trip, create/retrieve, delete, restore flag, multi-thread linking, and multiple worktrees per thread Part 2 of 3 in the persist-worktree stack. Stacked on zed-industries#53213. This is pure data model — nothing is wired up yet. Release Notes: - N/A --------- Co-authored-by: Anthony Eid <anthony@zed.dev>
rtfeldman
added a commit
that referenced
this pull request
Apr 8, 2026
…ive (#53215) Connect the git API and archived worktree data model to the sidebar's archive/unarchive flow: - Add `thread_worktree_archive` module: orchestrates the full archive cycle (WIP commits, DB records, git refs, worktree deletion) and restore cycle (detached worktree creation, reset to recover staged/unstaged state, branch restoration) - Integrate into sidebar: `archive_thread` now persists worktree state before cleanup; `activate_archived_thread` restores worktrees via git with targeted path replacement for multi-root threads - Add pending worktree restore UI state with spinner and cancel button - Show toast on restore failure instead of silent log - Switch to surviving workspace when archiving active thread whose workspace will be deleted - Deserialize persisted `project_group_keys` on window restore - Guard `cleanup_empty_workspaces` against dropped entities - Await rollback DB operations instead of fire-and-forget Part 3 of 3 in the persist-worktree stack. Stacked on #53214. This wires up parts 1 and 2. Release Notes: - Added worktree state preservation when archiving agent threads, automatically restoring staged and unstaged changes when the thread is unarchived --------- Co-authored-by: Anthony Eid <anthony@zed.dev>
rtfeldman
added a commit
that referenced
this pull request
Apr 10, 2026
…ive (#53215) Connect the git API and archived worktree data model to the sidebar's archive/unarchive flow: - Add `thread_worktree_archive` module: orchestrates the full archive cycle (WIP commits, DB records, git refs, worktree deletion) and restore cycle (detached worktree creation, reset to recover staged/unstaged state, branch restoration) - Integrate into sidebar: `archive_thread` now persists worktree state before cleanup; `activate_archived_thread` restores worktrees via git with targeted path replacement for multi-root threads - Add pending worktree restore UI state with spinner and cancel button - Show toast on restore failure instead of silent log - Switch to surviving workspace when archiving active thread whose workspace will be deleted - Deserialize persisted `project_group_keys` on window restore - Guard `cleanup_empty_workspaces` against dropped entities - Await rollback DB operations instead of fire-and-forget Part 3 of 3 in the persist-worktree stack. Stacked on #53214. This wires up parts 1 and 2. Release Notes: - Added worktree state preservation when archiving agent threads, automatically restoring staged and unstaged changes when the thread is unarchived --------- Co-authored-by: Anthony Eid <anthony@zed.dev>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add the persistence layer for tracking archived git worktrees:
ArchivedGitWorktreestruct withstaged_commit_hashandunstaged_commit_hashfields to precisely identify WIP commitsarchived_git_worktreesandthread_archived_worktrees(join table) tablesColumnimpl for deserializingArchivedGitWorktreefrom DB rowsPart 2 of 3 in the persist-worktree stack. Stacked on #53213. This is pure data model — nothing is wired up yet.
Release Notes: