MCPcopy Create free account
hub / github.com/dtormoen/tsk-tsk / test_uncommitted_submodule_changes_are_committed

Function test_uncommitted_submodule_changes_are_committed

src/git.rs:2590–2751  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2588 /// to do it automatically.
2589 #[tokio::test]
2590 async fn test_uncommitted_submodule_changes_are_committed() {
2591 let ctx = AppContext::builder().build();
2592
2593 // Create RepoB (will become a submodule)
2594 let repo_b = TestGitRepository::new().unwrap();
2595 repo_b.init_with_main_branch().unwrap();
2596
2597 // Create RepoA (superproject) with RepoB as submodule
2598 let repo_a = TestGitRepository::new().unwrap();
2599 repo_a.init_with_main_branch().unwrap();
2600
2601 // Add RepoB as submodule
2602 repo_a.add_submodule(&repo_b, "RepoB").unwrap();
2603 repo_a.stage_all().unwrap();
2604 repo_a.commit("Add RepoB submodule").unwrap();
2605
2606 // Capture source_commit before copying
2607 let source_commit = repo_a.get_current_commit().unwrap();
2608
2609 // Step 1: Copy the repo (simulates `tsk shell` starting)
2610 let manager = RepoManager::new(&ctx);
2611 let task_id = "uncommittedsub";
2612 let branch_name = "tsk/test/uncommitted-submodule/uncommittedsub";
2613 let copied_path = manager
2614 .copy_repo(
2615 task_id,
2616 repo_a.path(),
2617 None,
2618 branch_name,
2619 CopyMode::WorkingTree,
2620 )
2621 .await
2622 .expect("Copy should succeed")
2623 .repo_path;
2624
2625 // Step 2: Modify both READMEs WITHOUT committing (simulates user editing files)
2626 // This is the key difference - no manual commits in either repo
2627 std::fs::write(copied_path.join("README.md"), "# RepoA\nmodified").unwrap();
2628 std::fs::write(
2629 copied_path.join("RepoB/README.md"),
2630 "# RepoB\nmodified by agent",
2631 )
2632 .unwrap();
2633
2634 // Verify submodule has uncommitted changes before commit_changes()
2635 let copied_submodule_path = copied_path.join("RepoB");
2636 let status_before = std::process::Command::new("git")
2637 .current_dir(&copied_submodule_path)
2638 .args(["status", "--porcelain"])
2639 .output()
2640 .expect("git status should work");
2641 let status_before_str = String::from_utf8_lossy(&status_before.stdout);
2642 assert!(
2643 !status_before_str.is_empty(),
2644 "Submodule should have uncommitted changes before commit_changes()"
2645 );
2646
2647 // Configure git user for both superproject and submodule (needed for auto-commit)

Callers

nothing calls this directly

Calls 12

init_with_main_branchMethod · 0.80
add_submoduleMethod · 0.80
stage_allMethod · 0.80
commitMethod · 0.80
get_current_commitMethod · 0.80
copy_repoMethod · 0.80
pathMethod · 0.80
configure_test_userMethod · 0.80
commit_changesMethod · 0.80
fetch_changesMethod · 0.80
branchesMethod · 0.80
buildMethod · 0.45

Tested by

no test coverage detected