#[path = "common/mod.rs"]
mod common;
use common::TestRepo;
use tij::jj::JjExecutor;
#[test]
fn test_squash_into_merges_changes() {
skip_if_no_jj!();
let repo = TestRepo::new();
repo.write_file("file1.txt", "parent content");
repo.jj(&["describe", "-m", "parent"]);
repo.jj(&["new", "-m", "child"]);
repo.write_file("file2.txt", "child content");
let child_id = repo.current_change_id();
let parent_id = repo
.jj(&["log", "-r", "@-", "--no-graph", "-T", "change_id.short(8)"])
.trim()
.to_string();
repo.jj(&["squash", "--from", &child_id, "--into", &parent_id, "-u"]);
let diff = repo.jj(&["diff", "-r", &parent_id, "--summary"]);
assert!(
diff.contains("file2.txt"),
"parent should contain file2.txt after squash"
);
}
#[test]
fn test_squash_default_into_parent() {
skip_if_no_jj!();
let repo = TestRepo::new();
repo.write_file("main.rs", "fn main() {}");
repo.jj(&["describe", "-m", "Initial"]);
repo.jj(&["new", "-m", "Add feature"]);
repo.write_file("main.rs", "fn main() { feature(); }");
repo.write_file("feature.rs", "fn feature() {}");
let executor = JjExecutor::with_repo_path(repo.path());
executor.squash().expect("squash should succeed");
let parent_diff = repo.jj(&["diff", "-r", "@-", "--summary"]);
assert!(
parent_diff.contains("feature.rs") || parent_diff.contains("main.rs"),
"Parent should contain the squashed changes"
);
}
#[test]
fn test_absorb_moves_changes_to_ancestor() {
skip_if_no_jj!();
let repo = TestRepo::new();
repo.write_file("code.rs", "fn main() {}");
repo.jj(&["describe", "-m", "initial"]);
repo.jj(&["new", "-m", "wip"]);
repo.write_file("code.rs", "fn main() { println!(\"hello\"); }");
let executor = JjExecutor::with_repo_path(repo.path());
let result = executor.absorb();
assert!(result.is_ok(), "absorb should complete without error");
}