Skip to content

Commit 67e11be

Browse files
authored
Refactor error handling in worktree deletion process (#12)
- Introduced a constant `EXIT_ERROR` for consistent error exit codes. - Updated the confirmation prompt for deleting worktrees with uncommitted changes to use an error message instead of a confirmation dialog. - Clarified comments regarding base branch determination logic. These changes improve the robustness and clarity of the worktree management functionality.
1 parent 02d430c commit 67e11be

3 files changed

Lines changed: 322 additions & 6 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"):

0 commit comments

Comments
 (0)