Skip to content

Commit 1e083f9

Browse files
committed
update
1 parent 78bcc88 commit 1e083f9

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

tools/wt-worktree/tests/test_worktree.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,28 @@ def test_delete_worktree_keep_branch(manager, git_repo, no_prompt):
103103
assert git.branch_exists("feature/feat", git_repo)
104104

105105

106+
def test_create_worktree_with_existing_branch(manager, git_repo, no_prompt):
107+
"""Test creating worktree when branch exists but has no worktree."""
108+
# First create a worktree and delete it but keep the branch
109+
manager.create_worktree("feat")
110+
assert git.branch_exists("feature/feat", git_repo)
111+
112+
# Delete worktree but keep the branch
113+
deleted = manager.delete_worktree("feat", force=True, keep_branch=True)
114+
assert deleted is True
115+
assert git.branch_exists("feature/feat", git_repo)
116+
117+
# Now create worktree again - should use existing branch
118+
wt_path = manager.create_worktree("feat")
119+
assert wt_path.exists()
120+
assert git.branch_exists("feature/feat", git_repo)
121+
122+
# Verify worktree is properly associated with the branch
123+
wt = manager.find_worktree_by_name("feat")
124+
assert wt is not None
125+
assert wt["branch"] == "feature/feat"
126+
127+
106128
def test_delete_nonexistent_worktree(manager):
107129
"""Test deleting non-existent worktree."""
108130
with pytest.raises(git.GitError, match="not found"):

tools/wt-worktree/wt/worktree.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ def create_worktree(self, name: str, base: Optional[str] = None,
160160
f"Please remove it or choose a different name."
161161
)
162162

163-
# Determine base branch (only used when creating a new branch)
164-
if base is None and not use_existing_branch:
163+
# Determine base branch
164+
if base is None:
165165
base = self.config.get("default_base")
166166

167167
# Create worktree

0 commit comments

Comments
 (0)