Add allow_empty commits, detached worktree creation, and new git operations#53213
Merged
Add allow_empty commits, detached worktree creation, and new git operations#53213
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
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.
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.
13b51f6 to
8edcdbd
Compare
…s/zed into persist-worktree-1-git-api
Anthony-Eid
approved these changes
Apr 6, 2026
rtfeldman
added a commit
that referenced
this pull request
Apr 7, 2026
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 #53213. This is pure data model — nothing is wired up yet. Release Notes: - N/A --------- Co-authored-by: Anthony Eid <anthony@zed.dev>
MasoudAlali
pushed a commit
to MasoudAlali/zed-ide
that referenced
this pull request
Apr 7, 2026
…ations (zed-industries#53213) 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 Part 1 of 3 in the persist-worktree stack. These are nonbreaking API additions with no behavioral changes to existing code. Release Notes: - N/A --------- Co-authored-by: Anthony Eid <anthony@zed.dev>
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>
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.
Extend the git API with several new capabilities needed for worktree archival and restoration:
allow_emptyflag toCommitOptionsfor creating WIP marker commitscreate_worktreeto acceptOption<String>branch, enabling detached worktree creation whenNoneis passedhead_sha()to read the current HEAD commit hashupdate_ref()anddelete_ref()for managing git referencesstage_all_including_untracked()to stage everything before a WIP commitFakeGitRepositorywith functional commit history tracking, reset support, and ref managementCommitOptionsfield andcreate_worktreesignaturePart 1 of 3 in the persist-worktree stack. These are nonbreaking API additions with no behavioral changes to existing code.
Release Notes: