Skip to content

Add allow_empty commits, detached worktree creation, and new git operations#53213

Merged
rtfeldman merged 14 commits intomainfrom
persist-worktree-1-git-api
Apr 6, 2026
Merged

Add allow_empty commits, detached worktree creation, and new git operations#53213
rtfeldman merged 14 commits intomainfrom
persist-worktree-1-git-api

Conversation

@rtfeldman
Copy link
Copy Markdown
Contributor

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

…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
@rtfeldman rtfeldman self-assigned this Apr 6, 2026
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Apr 6, 2026
@zed-community-bot zed-community-bot bot added the staff Pull requests authored by a current member of Zed staff label Apr 6, 2026
Anthony-Eid and others added 8 commits April 6, 2026 14:52
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.
@rtfeldman rtfeldman force-pushed the persist-worktree-1-git-api branch from bd78423 to 3061d32 Compare April 6, 2026 20:34
Anthony-Eid and others added 2 commits April 6, 2026 16:44
- 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.
@rtfeldman rtfeldman force-pushed the persist-worktree-1-git-api branch from 13b51f6 to 8edcdbd Compare April 6, 2026 20:52
@rtfeldman rtfeldman marked this pull request as ready for review April 6, 2026 20:53
@rtfeldman rtfeldman enabled auto-merge (squash) April 6, 2026 21:12
@rtfeldman rtfeldman merged commit fb2bff8 into main Apr 6, 2026
30 checks passed
@rtfeldman rtfeldman deleted the persist-worktree-1-git-api branch April 6, 2026 21:32
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement staff Pull requests authored by a current member of Zed staff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants