Add git worktree remove/rename API - #49135
Merged
Merged
Conversation
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).
rtfeldman
force-pushed
the
AI-31/git-worktree-api
branch
from
February 13, 2026 21:16
0157491 to
c9c9663
Compare
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
marked this pull request as ready for review
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
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
remove_worktree()andrename_worktree()to theGitRepositorytrait withRealGitRepositoryimplementations that shell out togit worktree remove/move.Implement all 4 worktree methods (
worktrees,create_worktree,remove_worktree,rename_worktree) onFakeGitRepositorybacked byFakeGitRepositoryState, withsimulated_create_worktree_errorfor test-time fault injection.Add
set_create_worktree_error()helper onFakeFs.Add
parse_worktrees_from_strhelper and 7 new tests covering real git operations and fake worktree lifecycle.Closes AI-31
Release Notes: