use crate::common::CommandOutput;
use crate::common::TestEnvironment;
use crate::common::TestWorkDir;
fn create_test_environment() -> TestEnvironment {
let mut test_env = TestEnvironment::default();
test_env.add_env_var("JJ_RANDOMNESS_SEED", "0");
test_env.add_env_var("JJ_TIMESTAMP", "2001-01-01T00:00:00+00:00");
test_env.add_config("experimental.record-predecessors-in-commit = false");
test_env
}
#[test]
fn test_identical_commits() {
let test_env = create_test_environment();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
work_dir.run_jj(["new", "root()", "-m=test"]).success();
insta::assert_snapshot!(work_dir.run_jj(["new", "root()", "-m=test"]), @"
------- stderr -------
Internal error: Unexpected error from backend
Caused by: Newly-created commit e94ed463cbb0776612e308eba2ecaae74a7f8a73 already exists
[EOF]
[exit status: 255]
");
insta::assert_snapshot!(get_log_output(&work_dir), @"
@ e94ed463cbb0 test
◆ 000000000000
[EOF]
");
}
#[test]
fn test_identical_commits_concurrently() {
let test_env = create_test_environment();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
work_dir.run_jj(["new", "root()", "-m=test1"]).success();
work_dir.run_jj(["describe", "-m=test2"]).success();
work_dir
.run_jj(["describe", "-m=test2", "--at-op=@-"])
.success();
insta::assert_snapshot!(get_log_output(&work_dir), @"
@ c5abd2256ac0 test2
◆ 000000000000
[EOF]
------- stderr -------
Concurrent modification detected, resolving automatically.
[EOF]
");
}
#[test]
fn test_identical_commits_by_cycling_rewrite() {
let test_env = create_test_environment();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
work_dir.run_jj(["new", "root()", "-m=test1"]).success();
work_dir.run_jj(["describe", "-m=test2"]).success();
insta::assert_snapshot!(work_dir.run_jj(["describe", "-m=test1"]), @"
------- stderr -------
Internal error: Unexpected error from backend
Caused by: Newly-created commit 053222c21fa06b9492e22346f8f70e732231ad4f already exists
[EOF]
[exit status: 255]
");
insta::assert_snapshot!(work_dir.run_jj(["evolog"]), @"
@ oxmtprsl test.user@example.com 2001-01-01 11:00:00 c5abd225
│ (empty) test2
│ -- operation f0e7f7b1629b describe commit 053222c21fa06b9492e22346f8f70e732231ad4f
○ oxmtprsl/1 test.user@example.com 2001-01-01 11:00:00 053222c2 (hidden)
(empty) test1
-- operation 72d9ec4ca389 new empty commit
[EOF]
");
}
#[test]
fn test_identical_commits_by_convergent_rewrite() {
let test_env = create_test_environment();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
work_dir.run_jj(["new", "root()", "-m=test1"]).success();
work_dir.run_jj(["new", "root()", "-m=test2"]).success();
work_dir
.run_jj(["describe", "-m=test3", "subject(test1)"])
.success();
insta::assert_snapshot!(work_dir.run_jj(["describe", "-m=test3", "subject(test2)"]), @"
------- stderr -------
Internal error: Unexpected error from backend
Caused by: Newly-created commit 460733f1f6f9283d5a810b231dd3f846fd3a6f04 already exists
[EOF]
[exit status: 255]
");
insta::assert_snapshot!(work_dir.run_jj(["evolog"]), @"
@ oxmtprsl/1 test.user@example.com 2001-01-01 11:00:00 c5abd225 (divergent)
(empty) test2
-- operation 2c0ac8f6dfb7 new empty commit
[EOF]
");
}
#[test]
fn test_identical_commits_by_convergent_rewrite_one_operation() {
let test_env = create_test_environment();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
work_dir.run_jj(["new", "root()", "-m=test1"]).success();
work_dir.run_jj(["new", "root()", "-m=test2"]).success();
insta::assert_snapshot!(work_dir.run_jj(["describe", "-m=test3", "root()+"]), @"
------- stderr -------
Internal error: Unexpected error from backend
Caused by: Newly-created commit 460733f1f6f9283d5a810b231dd3f846fd3a6f04 already exists
[EOF]
[exit status: 255]
");
insta::assert_snapshot!(get_log_output(&work_dir), @"
@ c5abd2256ac0 test2
│ ○ 053222c21fa0 test1
├─╯
◆ 000000000000
[EOF]
");
insta::assert_snapshot!(work_dir.run_jj(["evolog"]), @"
@ oxmtprsl/0 test.user@example.com 2001-01-01 11:00:00 c5abd225 (divergent)
(empty) test2
-- operation 2c0ac8f6dfb7 new empty commit
[EOF]
");
}
#[test]
fn test_identical_commits_swap_by_reordering() {
let test_env = create_test_environment();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
work_dir.run_jj(["new", "root()", "-m=test"]).success();
work_dir.run_jj(["new", "-m=test"]).success();
insta::assert_snapshot!(get_log_output(&work_dir), @"
@ 5bae90c9b34d test
○ e94ed463cbb0 test
◆ 000000000000
[EOF]
");
insta::assert_snapshot!(work_dir.run_jj(["rebase", "-r=@", "-B=@-"]), @"
------- stderr -------
Internal error: Unexpected error from backend
Caused by: Newly-created commit e94ed463cbb0776612e308eba2ecaae74a7f8a73 already exists
[EOF]
[exit status: 255]
");
insta::assert_snapshot!(get_log_output(&work_dir), @"
@ 5bae90c9b34d test
○ e94ed463cbb0 test
◆ 000000000000
[EOF]
");
insta::assert_snapshot!(work_dir.run_jj(["evolog", "-r=@"]), @"
@ oxmtprsl/0 test.user@example.com 2001-01-01 11:00:00 5bae90c9 (divergent)
(empty) test
-- operation 51fb079a7e7c new empty commit
[EOF]
");
insta::assert_snapshot!(work_dir.run_jj(["evolog", "-r=@-"]), @"
○ oxmtprsl/1 test.user@example.com 2001-01-01 11:00:00 e94ed463 (divergent)
(empty) test
-- operation 03fecb732164 new empty commit
[EOF]
");
}
#[must_use]
fn get_log_output(work_dir: &TestWorkDir) -> CommandOutput {
let template = r#"commit_id.short() ++ " " ++ description"#;
work_dir.run_jj(["log", "-T", template])
}