diff --git a/crates/maestro-daemon/tests/worktree.rs b/crates/maestro-daemon/tests/worktree.rs index c7c8dbf..b9a72c2 100644 --- a/crates/maestro-daemon/tests/worktree.rs +++ b/crates/maestro-daemon/tests/worktree.rs @@ -405,8 +405,10 @@ fn run_git(dir: &std::path::Path, args: &[&str]) { ); } +/// 49ab7e9: a new-branch add onto a name that already exists suffixes the +/// branch (and so the directory) instead of failing, per docs/WORKTREES.md. #[test] -fn add_fails_when_branch_already_exists() { +fn add_new_suffixes_when_branch_already_exists() { let repo_dir = TempDir::new().unwrap(); let repo = repo_dir.path().to_path_buf(); init_repo(&repo); @@ -423,9 +425,9 @@ fn add_fails_when_branch_already_exists() { let wt_root = TempDir::new().unwrap(); let mgr = WorktreeManager::new(Some(wt_root.path().to_path_buf())); - let err = mgr.add_new(&repo, "feat/dup").unwrap_err(); - let msg = format!("{err}"); - assert!(msg.contains("git exited"), "{msg}"); + let path = mgr.add_new(&repo, "feat/dup").unwrap(); + assert!(path.ends_with("feat/dup-2"), "{}", path.display()); + assert!(path.is_dir()); } /// The project picker lists linked worktrees as pickable rows, so `base_repo` diff --git a/crates/maestro-e2e/tests/e2e.rs b/crates/maestro-e2e/tests/e2e.rs index 6fc5a15..675bb57 100644 --- a/crates/maestro-e2e/tests/e2e.rs +++ b/crates/maestro-e2e/tests/e2e.rs @@ -328,8 +328,11 @@ async fn spawn_new_branch_creates_worktree_and_runs_in_it() { client.kill_session(s.id).await.expect("kill"); } -/// #66: a second spawn onto a branch that already has a worktree is rejected -/// with a structured worktree error; the first worktree stays intact. +/// #66: a second spawn onto an *existing* branch that already has a worktree +/// is rejected with a structured worktree error; the first worktree stays +/// intact. (A second `create_branch: true` spawn is a different case: 49ab7e9 +/// suffixes the new branch name instead, see +/// `colliding_branch_name_gets_suffixed_too`.) #[tokio::test(flavor = "multi_thread")] async fn second_spawn_on_same_branch_is_rejected() { let (_daemon, client) = bring_up().await; @@ -342,7 +345,7 @@ async fn second_spawn_on_same_branch_is_rejected() { .await .expect("first spawn"); let dup = client - .spawn_session(&worktree_req(base.path(), "feature/dup", true)) + .spawn_session(&worktree_req(base.path(), "feature/dup", false)) .await; match dup { Err(maestro_e2e::ClientError::Api(maestro_protocol::ClientError::Api { info, .. })) => {