()
| 1514 | |
| 1515 | #[tokio::test] |
| 1516 | async fn test_task_builder_from_worktree() { |
| 1517 | use crate::test_utils::{ExistingGitRepository, TestGitRepository}; |
| 1518 | |
| 1519 | // Create main repo with a commit on main |
| 1520 | let main_repo = TestGitRepository::new().unwrap(); |
| 1521 | main_repo.init_with_main_branch().unwrap(); |
| 1522 | main_repo |
| 1523 | .create_file("main-file.txt", "main content") |
| 1524 | .unwrap(); |
| 1525 | main_repo.stage_all().unwrap(); |
| 1526 | main_repo.commit("Add main-file.txt").unwrap(); |
| 1527 | |
| 1528 | // Create a worktree on branch-a |
| 1529 | let worktree_tmp = tempfile::TempDir::new().unwrap(); |
| 1530 | let worktree_dir = worktree_tmp.path().join("worktree"); |
| 1531 | main_repo |
| 1532 | .run_git_command(&[ |
| 1533 | "worktree", |
| 1534 | "add", |
| 1535 | worktree_dir.to_str().unwrap(), |
| 1536 | "-b", |
| 1537 | "branch-a", |
| 1538 | ]) |
| 1539 | .unwrap(); |
| 1540 | |
| 1541 | // In the worktree, create a file and commit |
| 1542 | let worktree_repo = ExistingGitRepository::new(&worktree_dir).unwrap(); |
| 1543 | worktree_repo.configure_test_user().unwrap(); |
| 1544 | std::fs::write(worktree_dir.join("branch-a-file.txt"), "branch-a content").unwrap(); |
| 1545 | worktree_repo.stage_all().unwrap(); |
| 1546 | let branch_a_commit = worktree_repo.commit("Add branch-a-file.txt").unwrap(); |
| 1547 | |
| 1548 | let ctx = AppContext::builder().build(); |
| 1549 | |
| 1550 | let canonical_main = main_repo.path().canonicalize().unwrap(); |
| 1551 | |
| 1552 | let task = TaskBuilder::new() |
| 1553 | .repo_root(canonical_main.clone()) |
| 1554 | .name("worktree-test".to_string()) |
| 1555 | .prompt(Some("Test from worktree".to_string())) |
| 1556 | .repo_copy_source(Some(worktree_dir.clone())) |
| 1557 | .build(&ctx) |
| 1558 | .await |
| 1559 | .unwrap(); |
| 1560 | |
| 1561 | // repo_root should point to the main repo |
| 1562 | assert_eq!(task.repo_root, canonical_main); |
| 1563 | |
| 1564 | // source_branch should be branch-a |
| 1565 | assert_eq!(task.source_branch, Some("branch-a".to_string())); |
| 1566 | |
| 1567 | // source_commit should match branch-a's HEAD, not main's |
| 1568 | assert_eq!(task.source_commit, branch_a_commit); |
| 1569 | |
| 1570 | // The copied repo should contain both files |
| 1571 | let task_dir = ctx.tsk_env().task_dir(&task.id); |
| 1572 | let copied_repo = task_dir.join("repo"); |
| 1573 | assert!( |
nothing calls this directly
no test coverage detected