diff --git a/agent_cli/dev/worktree.py b/agent_cli/dev/worktree.py index 306c6216..5fec964c 100644 --- a/agent_cli/dev/worktree.py +++ b/agent_cli/dev/worktree.py @@ -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( diff --git a/tests/dev/test_worktree.py b/tests/dev/test_worktree.py index bcdd9fe7..ab9dcdf1 100644 --- a/tests/dev/test_worktree.py +++ b/tests/dev/test_worktree.py @@ -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( @@ -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)."""