Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions agent_cli/dev/worktree.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,13 +662,19 @@ def create_worktree(
# Check if branch exists remotely or locally
remote_exists, local_exists = check_branch_exists(branch_name, repo_root)

# Generate warning if --from was specified but will be ignored
# Generate warning when the branch already exists
warning: str | None = None
if from_ref_explicit and (local_exists or remote_exists):
warning = (
f"Branch '{branch_name}' already exists. "
f"Using existing branch instead of creating from '{from_ref}'."
)
if local_exists or remote_exists:
if from_ref_explicit:
warning = (
f"Branch '{branch_name}' already exists. "
f"Using existing branch instead of creating from '{from_ref}'."
)
else:
warning = (
f"Branch '{branch_name}' already exists. "
f"Using existing branch (use a different name to start fresh)."
)

try:
_add_worktree(
Expand Down
8 changes: 5 additions & 3 deletions tests/dev/test_worktree.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,8 @@ def test_warning_when_remote_branch_exists_and_from_specified(self) -> None:
assert result.warning is not None
assert "already exists" in result.warning

def test_no_warning_when_from_not_specified(self) -> None:
"""No warning when --from is not specified (uses default)."""
def test_warning_when_from_not_specified_but_branch_exists(self) -> None:
"""Warning shown when branch exists even without explicit --from."""
with (
patch("agent_cli.dev.worktree.get_main_repo_root", return_value=Path("/repo")),
patch(
Expand All @@ -523,7 +523,9 @@ def test_no_warning_when_from_not_specified(self) -> None:
)

assert result.success is True
assert result.warning is None # No warning since --from wasn't explicit
assert result.warning is not None
assert "already exists" in result.warning
assert "use a different name" in result.warning.lower()

def test_no_warning_when_branch_is_new(self) -> None:
"""No warning when branch doesn't exist (will be created from --from)."""
Expand Down