use crate::core::repo;
use crate::core::test_helpers::TestRepo;
#[test]
fn unmerge_removes_branch_from_integration() {
let test_repo = TestRepo::new_with_remote();
test_repo.commit("A1", "a1.txt");
test_repo.commit("A2", "a2.txt");
let a2_oid = test_repo.head_oid();
test_repo
.in_dir(|| crate::branch::new::run(Some("feature-a".to_string()), Some(a2_oid.to_string())))
.unwrap();
assert_eq!(test_repo.head_commit().parent_count(), 2);
test_repo
.in_dir(|| super::unmerge::run(Some("feature-a".to_string())))
.unwrap();
assert!(test_repo.branch_exists("feature-a"));
let info = repo::gather_repo_info(&test_repo.repo, false, 1).unwrap();
let branch_names: Vec<&str> = info.branches.iter().map(|b| b.name.as_str()).collect();
assert!(
!branch_names.contains(&"feature-a"),
"feature-a should not be in integration branches after unmerge, got: {:?}",
branch_names
);
}
#[test]
fn unmerge_conflict_aborts() {
let test_repo = TestRepo::new_with_remote();
let a_oid = test_repo.commit("from-a", "shared.txt");
test_repo
.in_dir(|| crate::branch::new::run(Some("feature-a".to_string()), Some(a_oid.to_string())))
.unwrap();
test_repo.write_file("shared.txt", "from-b");
test_repo.stage_files(&["shared.txt"]);
test_repo.commit_staged("Commit B");
let result = test_repo.in_dir(|| super::unmerge::run(Some("feature-a".to_string())));
assert!(
result.is_err(),
"unmerge should fail when the rebase conflicts"
);
assert!(
!crate::git::rebase_is_in_progress(test_repo.repo.path()),
"rebase should be aborted, not left paused"
);
assert!(
!test_repo
.repo
.path()
.join("loom")
.join("state.json")
.exists(),
"no loom state should be written for a non-resumable command"
);
}
#[test]
fn unmerge_non_woven_branch_errors() {
let test_repo = TestRepo::new_with_remote();
test_repo.commit("A1", "a1.txt");
let base_oid = test_repo.find_remote_branch_target("origin/main");
test_repo.create_branch_at("feature-a", &base_oid.to_string());
let result = test_repo.in_dir(|| super::unmerge::run(Some("feature-a".to_string())));
assert!(result.is_err());
}