Skip to content

Add git worktree remove/rename API - #49135

Merged
rtfeldman merged 4 commits into
mainfrom
AI-31/git-worktree-api
Feb 17, 2026
Merged

Add git worktree remove/rename API#49135
rtfeldman merged 4 commits into
mainfrom
AI-31/git-worktree-api

Conversation

@rtfeldman

Copy link
Copy Markdown
Contributor

Add remove_worktree() and rename_worktree() to the GitRepository trait with RealGitRepository implementations that shell out to git worktree remove/move.

Implement all 4 worktree methods (worktrees, create_worktree, remove_worktree, rename_worktree) on FakeGitRepository backed by FakeGitRepositoryState, with simulated_create_worktree_error for test-time fault injection.

Add set_create_worktree_error() helper on FakeFs.

Add parse_worktrees_from_str helper and 7 new tests covering real git operations and fake worktree lifecycle.

Closes AI-31

Release Notes:

  • N/A

@rtfeldman rtfeldman self-assigned this Feb 13, 2026
@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Feb 13, 2026
@zed-community-bot zed-community-bot Bot added the staff Pull requests authored by a current member of Zed staff label Feb 13, 2026
Add remove_worktree() and rename_worktree() to the GitRepository trait with
RealGitRepository implementations that shell out to git worktree remove/move.

Implement all 4 worktree methods (worktrees, create_worktree, remove_worktree,
rename_worktree) on FakeGitRepository backed by FakeGitRepositoryState, with
simulated_create_worktree_error for test-time fault injection.

Add set_create_worktree_error() helper on FakeFs.

Tests: test_parse_worktrees_from_str, test_create_and_list_worktrees,
test_remove_worktree, test_remove_worktree_force, test_rename_worktree,
test_create_worktree (real git), test_fake_worktree_lifecycle (fake).
1. Fix create_worktree to always pass -b <name> (uses HEAD when
   from_commit is None), so the worktree lands on the intended branch.
2. Rewrite parse_worktrees_from_str to parse key/value lines by prefix
   instead of assuming exactly 3 lines per entry. Extra porcelain lines
   like locked, prunable, detached, and bare are now safely ignored.
3. Trim each line before parsing so leading/trailing whitespace doesn't
   corrupt paths or refs.
4. FakeGitRepository::remove_worktree now removes the directory from
   FakeFs before updating internal state.
5. FakeGitRepository::rename_worktree now moves the directory in FakeFs
   before updating internal state; state is not mutated on failure.
6. FakeGitRepository::create_worktree checks the simulated error first,
   creates the directory second, then updates state—preventing state/fs
   inconsistency if directory creation fails.
7. Fix incorrect error message: 'git worktree list failed' →
   'git worktree add failed'.

Tests: added parsing cases for extra porcelain lines and leading
whitespace; extended fake worktree lifecycle test to assert directory
existence after create, rename, and remove.
…arsing

- Add -- terminator before user-supplied paths in create/remove/rename
  worktree git commands to prevent option injection from paths starting
  with -
- Normalize \r\n to \n in parse_worktrees_from_str for Windows compat
- Reorder fake repo remove/rename_worktree to validate state before
  mutating filesystem, preventing directory deletion when path isn't a
  tracked worktree
- Add duplicate branch check and refs update in fake create_worktree
- Add test for Windows-style line endings in worktree parsing
…match

- Replace PathBuf::from(...) with Path::new(...) in fake worktree test
  comparisons to avoid clippy::cmp_owned errors
- Canonicalize both sides of path assertions in real worktree tests to
  handle Windows \\?\ extended-length path prefix from canonicalize()
@rtfeldman
rtfeldman marked this pull request as ready for review February 17, 2026 17:09
@rtfeldman
rtfeldman merged commit 91b3191 into main Feb 17, 2026
69 of 75 checks passed
@rtfeldman
rtfeldman deleted the AI-31/git-worktree-api branch February 17, 2026 17:09
rtfeldman added a commit that referenced this pull request Feb 17, 2026
Add `remove_worktree()` and `rename_worktree()` to the `GitRepository`
trait with `RealGitRepository` implementations that shell out to `git
worktree remove/move`.

Implement all 4 worktree methods (`worktrees`, `create_worktree`,
`remove_worktree`, `rename_worktree`) on `FakeGitRepository` backed by
`FakeGitRepositoryState`, with `simulated_create_worktree_error` for
test-time fault injection.

Add `set_create_worktree_error()` helper on `FakeFs`.

Add `parse_worktrees_from_str` helper and 7 new tests covering real git
operations and fake worktree lifecycle.

Closes AI-31

Release Notes:

- N/A
jonx pushed a commit to jonx/zed-aros that referenced this pull request Jul 17, 2026
Add `remove_worktree()` and `rename_worktree()` to the `GitRepository`
trait with `RealGitRepository` implementations that shell out to `git
worktree remove/move`.

Implement all 4 worktree methods (`worktrees`, `create_worktree`,
`remove_worktree`, `rename_worktree`) on `FakeGitRepository` backed by
`FakeGitRepositoryState`, with `simulated_create_worktree_error` for
test-time fault injection.

Add `set_create_worktree_error()` helper on `FakeFs`.

Add `parse_worktrees_from_str` helper and 7 new tests covering real git
operations and fake worktree lifecycle.

Closes AI-31

Release Notes:

- N/A
jolutz pushed a commit to jolutz/zed that referenced this pull request Aug 8, 2026
Add `remove_worktree()` and `rename_worktree()` to the `GitRepository`
trait with `RealGitRepository` implementations that shell out to `git
worktree remove/move`.

Implement all 4 worktree methods (`worktrees`, `create_worktree`,
`remove_worktree`, `rename_worktree`) on `FakeGitRepository` backed by
`FakeGitRepositoryState`, with `simulated_create_worktree_error` for
test-time fault injection.

Add `set_create_worktree_error()` helper on `FakeFs`.

Add `parse_worktrees_from_str` helper and 7 new tests covering real git
operations and fake worktree lifecycle.

Closes AI-31

Release Notes:

- N/A
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.

1 participant