use std::path::PathBuf;
use testutils::TestResult;
use crate::common::CommandOutput;
use crate::common::TestEnvironment;
use crate::common::TestWorkDir;
#[test]
fn test_squash() {
let test_env = TestEnvironment::default();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
work_dir
.run_jj(["bookmark", "create", "-r@", "a"])
.success();
work_dir.write_file("file1", "a\n");
work_dir.run_jj(["new"]).success();
work_dir
.run_jj(["bookmark", "create", "-r@", "b"])
.success();
work_dir.write_file("file1", "b\n");
work_dir.run_jj(["new"]).success();
work_dir
.run_jj(["bookmark", "create", "-r@", "c"])
.success();
work_dir.write_file("file1", "c\n");
insta::assert_snapshot!(get_log_output(&work_dir), @"
@ 22be6c4e01da c
â—‹ 75591b1896b4 b
â—‹ e6086990958c a
â—† 000000000000 (empty)
[EOF]
");
let setup_opid = work_dir.current_operation_id();
let output = work_dir.run_jj(["squash"]);
insta::assert_snapshot!(output, @"
------- stderr -------
Working copy (@) now at: vruxwmqv 2cf02eb8 (empty) (no description set)
Parent commit (@-) : kkmpptxz 9422c8d6 b c | (no description set)
[EOF]
");
insta::assert_snapshot!(get_log_output(&work_dir), @"
@ 2cf02eb82d82 (empty)
â—‹ 9422c8d6f294 b c
â—‹ e6086990958c a
â—† 000000000000 (empty)
[EOF]
");
let output = work_dir.run_jj(["file", "show", "file1"]);
insta::assert_snapshot!(output, @"
c
[EOF]
");
work_dir.run_jj(["op", "restore", &setup_opid]).success();
let output = work_dir.run_jj(["squash", "-r", "b"]);
insta::assert_snapshot!(output, @"
------- stderr -------
Rebased 1 descendant commits
Working copy (@) now at: mzvwutvl 441a7a3a c | (no description set)
Parent commit (@-) : qpvuntsm 105931bf a b | (no description set)
[EOF]
");
insta::assert_snapshot!(get_log_output(&work_dir), @"
@ 441a7a3a17b0 c
â—‹ 105931bfedad a b
â—† 000000000000 (empty)
[EOF]
");
let output = work_dir.run_jj(["file", "show", "file1", "-r", "b"]);
insta::assert_snapshot!(output, @"
b
[EOF]
");
let output = work_dir.run_jj(["file", "show", "file1"]);
insta::assert_snapshot!(output, @"
c
[EOF]
");
work_dir.run_jj(["op", "restore", &setup_opid]).success();
work_dir.run_jj(["edit", "b"]).success();
work_dir.run_jj(["new"]).success();
work_dir
.run_jj(["bookmark", "create", "-r@", "d"])
.success();
work_dir.write_file("file2", "d\n");
work_dir.run_jj(["new", "c", "d"]).success();
work_dir
.run_jj(["bookmark", "create", "-r@", "e"])
.success();
insta::assert_snapshot!(get_log_output(&work_dir), @"
@ e05d4caaf6ce e (empty)
├─╮
│ ○ 9bb7863cfc78 d
○ │ 22be6c4e01da c
├─╯
â—‹ 75591b1896b4 b
â—‹ e6086990958c a
â—† 000000000000 (empty)
[EOF]
");
let output = work_dir.run_jj(["squash"]);
insta::assert_snapshot!(output, @"
------- stderr -------
Error: Cannot squash merge commits without a specified destination
Hint: Use `--into` to specify which parent to squash into
[EOF]
[exit status: 1]
");
work_dir.run_jj(["new", "e"]).success();
work_dir.write_file("file1", "e\n");
let output = work_dir.run_jj(["squash"]);
insta::assert_snapshot!(output, @"
------- stderr -------
Working copy (@) now at: xlzxqlsl 91a81249 (empty) (no description set)
Parent commit (@-) : nmzmmopx 9155baf5 e | (no description set)
[EOF]
");
insta::assert_snapshot!(get_log_output(&work_dir), @"
@ 91a81249954f (empty)
â—‹ 9155baf5ced1 e
├─╮
│ ○ 9bb7863cfc78 d
○ │ 22be6c4e01da c
├─╯
â—‹ 75591b1896b4 b
â—‹ e6086990958c a
â—† 000000000000 (empty)
[EOF]
");
let output = work_dir.run_jj(["file", "show", "file1", "-r", "e"]);
insta::assert_snapshot!(output, @"
e
[EOF]
");
}
#[test]
fn test_squash_partial() -> TestResult {
let mut test_env = TestEnvironment::default();
let edit_script = test_env.set_up_fake_diff_editor();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
work_dir
.run_jj(["bookmark", "create", "-r@", "a"])
.success();
work_dir.write_file("file1", "a\n");
work_dir.write_file("file2", "a\n");
work_dir.run_jj(["new"]).success();
work_dir
.run_jj(["bookmark", "create", "-r@", "b"])
.success();
work_dir.write_file("file1", "b\n");
work_dir.write_file("file2", "b\n");
work_dir.run_jj(["new"]).success();
work_dir
.run_jj(["bookmark", "create", "-r@", "c"])
.success();
work_dir.write_file("file1", "c\n");
work_dir.write_file("file2", "c\n");
insta::assert_snapshot!(get_log_output(&work_dir), @"
@ 87059ac9657b c
â—‹ f2c9709f39e9 b
â—‹ 64ea60be8d77 a
â—† 000000000000 (empty)
[EOF]
");
let start_op_id = work_dir.current_operation_id();
std::fs::write(&edit_script, "dump JJ-INSTRUCTIONS instrs")?;
let output = work_dir.run_jj(["squash", "-r", "b", "-i"]);
insta::assert_snapshot!(output, @"
------- stderr -------
Rebased 1 descendant commits
Working copy (@) now at: mzvwutvl 34484d82 c | (no description set)
Parent commit (@-) : qpvuntsm 3141e675 a b | (no description set)
[EOF]
");
let instrs = std::fs::read_to_string(test_env.env_root().join("instrs"))?;
insta::assert_snapshot!(
instrs, @"
You are moving changes from: kkmpptxz f2c9709f b | (no description set)
into commit: qpvuntsm 64ea60be a | (no description set)
The left side of the diff shows the contents of the parent commit. The
right side initially shows the contents of the commit you're moving
changes from.
Adjust the right side until the diff shows the changes you want to move
to the destination. If you don't make any changes, then all the changes
from the source will be moved into the destination.
");
insta::assert_snapshot!(get_log_output(&work_dir), @"
@ 34484d825f47 c
â—‹ 3141e67514f6 a b
â—† 000000000000 (empty)
[EOF]
");
let output = work_dir.run_jj(["file", "show", "file1", "-r", "a"]);
insta::assert_snapshot!(output, @"
b
[EOF]
");
work_dir.run_jj(["op", "restore", &start_op_id]).success();
std::fs::write(&edit_script, "reset file1")?;
let output = work_dir.run_jj(["squash", "-r", "b", "-i"]);
insta::assert_snapshot!(output, @"
------- stderr -------
Rebased 2 descendant commits
Working copy (@) now at: mzvwutvl 37e1a0ef c | (no description set)
Parent commit (@-) : kkmpptxz b41e789d b | (no description set)
[EOF]
");
insta::assert_snapshot!(get_log_output(&work_dir), @"
@ 37e1a0ef57ff c
â—‹ b41e789df71c b
â—‹ 3af17565155e a
â—† 000000000000 (empty)
[EOF]
");
let output = work_dir.run_jj(["file", "show", "file1", "-r", "a"]);
insta::assert_snapshot!(output, @"
a
[EOF]
");
let output = work_dir.run_jj(["file", "show", "file2", "-r", "a"]);
insta::assert_snapshot!(output, @"
b
[EOF]
");
let output = work_dir.run_jj(["file", "show", "file1", "-r", "b"]);
insta::assert_snapshot!(output, @"
b
[EOF]
");
let output = work_dir.run_jj(["file", "show", "file2", "-r", "b"]);
insta::assert_snapshot!(output, @"
b
[EOF]
");
work_dir.run_jj(["op", "restore", &start_op_id]).success();
std::fs::write(&edit_script, "")?;
let output = work_dir.run_jj(["squash", "-r", "b", "file2"]);
insta::assert_snapshot!(output, @"
------- stderr -------
Rebased 2 descendant commits
Working copy (@) now at: mzvwutvl 72ff256c c | (no description set)
Parent commit (@-) : kkmpptxz dd056a92 b | (no description set)
[EOF]
");
insta::assert_snapshot!(get_log_output(&work_dir), @"
@ 72ff256cd290 c
â—‹ dd056a925eb3 b
â—‹ cf083f1d9ccf a
â—† 000000000000 (empty)
[EOF]
");
let output = work_dir.run_jj(["file", "show", "file1", "-r", "a"]);
insta::assert_snapshot!(output, @"
a
[EOF]
");
let output = work_dir.run_jj(["file", "show", "file2", "-r", "a"]);
insta::assert_snapshot!(output, @"
b
[EOF]
");
let output = work_dir.run_jj(["file", "show", "file1", "-r", "b"]);
insta::assert_snapshot!(output, @"
b
[EOF]
");
let output = work_dir.run_jj(["file", "show", "file2", "-r", "b"]);
insta::assert_snapshot!(output, @"
b
[EOF]
");
work_dir.run_jj(["op", "restore", &start_op_id]).success();
let output = work_dir.run_jj(["squash", "-r", "b", "nonexistent"]);
insta::assert_snapshot!(output, @"
------- stderr -------
Warning: No matching entries for paths: nonexistent
Nothing changed.
[EOF]
");
work_dir.run_jj(["op", "restore", &start_op_id]).success();
let output = work_dir.run_jj(["squash", "b"]);
insta::assert_snapshot!(output, @r#"
------- stderr -------
Warning: No matching entries for paths: b
Warning: The argument "b" is being interpreted as a fileset expression. To specify a revset, pass -r "b" instead.
Nothing changed.
[EOF]
"#);
work_dir.run_jj(["op", "restore", &start_op_id]).success();
let output = work_dir.run_jj(["squash", ".tmp"]);
insta::assert_snapshot!(output, @"
------- stderr -------
Warning: No matching entries for paths: .tmp
Nothing changed.
[EOF]
");
work_dir.run_jj(["op", "restore", &start_op_id]).success();
work_dir.write_file("file3", "foo\n");
std::fs::write(&edit_script, "reset file1")?;
let output = work_dir.run_jj(["squash", "-i", "file1", "file3"]);
insta::assert_snapshot!(output, @"
------- stderr -------
Rebased 1 descendant commits
Working copy (@) now at: mzvwutvl 3615d80e c | (no description set)
Parent commit (@-) : kkmpptxz 037106c4 b | (no description set)
[EOF]
");
let output = work_dir.run_jj(["log", "-s"]);
insta::assert_snapshot!(output, @"
@ mzvwutvl test.user@example.com 2001-02-03 08:05:38 c 3615d80e
│ (no description set)
│ M file1
│ M file2
â—‹ kkmpptxz test.user@example.com 2001-02-03 08:05:38 b 037106c4
│ (no description set)
│ M file1
│ M file2
│ A file3
â—‹ qpvuntsm test.user@example.com 2001-02-03 08:05:09 a 64ea60be
│ (no description set)
│ A file1
│ A file2
â—† zzzzzzzz root() 00000000
[EOF]
");
work_dir.run_jj(["op", "restore", &start_op_id]).success();
std::fs::write(&edit_script, "reset file1\0reset file2")?;
let output = work_dir.run_jj(["squash", "-r", "b", "-i"]);
insta::assert_snapshot!(output, @"
------- stderr -------
Error: No changes selected
[EOF]
[exit status: 1]
");
insta::assert_snapshot!(get_log_output(&work_dir), @"
@ 87059ac9657b c
â—‹ f2c9709f39e9 b
â—‹ 64ea60be8d77 a
â—† 000000000000 (empty)
[EOF]
");
Ok(())
}
#[test]
fn test_squash_keep_emptied() {
let test_env = TestEnvironment::default();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
work_dir
.run_jj(["bookmark", "create", "-r@", "a"])
.success();
work_dir.write_file("file1", "a\n");
work_dir.run_jj(["new"]).success();
work_dir
.run_jj(["bookmark", "create", "-r@", "b"])
.success();
work_dir.write_file("file1", "b\n");
work_dir.run_jj(["new"]).success();
work_dir
.run_jj(["bookmark", "create", "-r@", "c"])
.success();
work_dir.write_file("file1", "c\n");
insta::assert_snapshot!(get_log_output(&work_dir), @"
@ 22be6c4e01da c
â—‹ 75591b1896b4 b
â—‹ e6086990958c a
â—† 000000000000 (empty)
[EOF]
");
let output = work_dir.run_jj(["squash", "-r", "b", "--keep-emptied"]);
insta::assert_snapshot!(output, @"
------- stderr -------
Rebased 2 descendant commits
Working copy (@) now at: mzvwutvl 093590e0 c | (no description set)
Parent commit (@-) : kkmpptxz 357946cf b | (empty) (no description set)
[EOF]
");
insta::assert_snapshot!(get_log_output(&work_dir), @"
@ 093590e044bd c
â—‹ 357946cf85df b (empty)
â—‹ 2269fb3b12f5 a
â—† 000000000000 (empty)
[EOF]
");
let output = work_dir.run_jj(["file", "show", "file1", "-r", "a"]);
insta::assert_snapshot!(output, @"
b
[EOF]
");
}
#[test]
fn test_squash_from_to() {
let test_env = TestEnvironment::default();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
work_dir
.run_jj(["bookmark", "create", "-r@", "a"])
.success();
work_dir.write_file("file1", "a\n");
work_dir.write_file("file2", "a\n");
work_dir.write_file("file3", "a\n");
work_dir.run_jj(["new"]).success();
work_dir
.run_jj(["bookmark", "create", "-r@", "b"])
.success();
work_dir.write_file("file3", "b\n");
work_dir.run_jj(["new"]).success();
work_dir
.run_jj(["bookmark", "create", "-r@", "c"])
.success();
work_dir.write_file("file1", "c\n");
work_dir.run_jj(["edit", "a"]).success();
work_dir.run_jj(["new"]).success();
work_dir
.run_jj(["bookmark", "create", "-r@", "d"])
.success();
work_dir.write_file("file3", "d\n");
work_dir.run_jj(["new"]).success();
work_dir
.run_jj(["bookmark", "create", "-r@", "e"])
.success();
work_dir.write_file("file2", "e\n");
work_dir.run_jj(["new"]).success();
work_dir
.run_jj(["bookmark", "create", "-r@", "f"])
.success();
work_dir.write_file("file2", "f\n");
insta::assert_snapshot!(get_log_output(&work_dir), @"
@ 0fac1124d1ad f
â—‹ 4ebe104a0e4e e
â—‹ dc71a460d5d6 d
│ ○ ee0b260ffc44 c
│ ○ e31bf988d7c9 b
├─╯
â—‹ e3e04beaf7d3 a
â—† 000000000000 (empty)
[EOF]
");
let setup_opid = work_dir.current_operation_id();
let output = work_dir.run_jj(["squash", "--into", "@"]);
insta::assert_snapshot!(output, @"
------- stderr -------
Nothing changed.
[EOF]
");
let output = work_dir.run_jj(["squash", "--from", "c"]);
insta::assert_snapshot!(output, @"
------- stderr -------
Working copy (@) now at: kmkuslsw 941ab024 f | (no description set)
Parent commit (@-) : znkkpsqq 4ebe104a e | (no description set)
Added 0 files, modified 1 files, removed 0 files
[EOF]
");
insta::assert_snapshot!(get_log_output(&work_dir), @"
@ 941ab024b3f8 f
â—‹ 4ebe104a0e4e e
â—‹ dc71a460d5d6 d
│ ○ e31bf988d7c9 b c
├─╯
â—‹ e3e04beaf7d3 a
â—† 000000000000 (empty)
[EOF]
");
let output = work_dir.run_jj(["file", "show", "file1"]);
insta::assert_snapshot!(output, @"
c
[EOF]
");
let output = work_dir.run_jj(["file", "show", "file2"]);
insta::assert_snapshot!(output, @"
f
[EOF]
");
work_dir.run_jj(["op", "restore", &setup_opid]).success();
let output = work_dir.run_jj(["squash", "--from", "@--"]);
insta::assert_snapshot!(output, @"
------- stderr -------
Working copy (@) now at: kmkuslsw c102d2c4 f | (no description set)
Parent commit (@-) : znkkpsqq beb7c033 e | (no description set)
[EOF]
");
insta::assert_snapshot!(get_log_output(&work_dir), @"
@ c102d2c4e165 f
â—‹ beb7c0338f7c e
│ ○ ee0b260ffc44 c
│ ○ e31bf988d7c9 b
├─╯
â—‹ e3e04beaf7d3 a d
â—† 000000000000 (empty)
[EOF]
");
let output = work_dir.run_jj(["file", "show", "file2"]);
insta::assert_snapshot!(output, @"
f
[EOF]
");
work_dir.run_jj(["op", "restore", &setup_opid]).success();
let output = work_dir.run_jj(["squash", "--from", "e", "--into", "d"]);
insta::assert_snapshot!(output, @"
------- stderr -------
Rebased 1 descendant commits
Working copy (@) now at: kmkuslsw 1bc21d4e f | (no description set)
Parent commit (@-) : vruxwmqv 8b6b080a d e | (no description set)
[EOF]
");
insta::assert_snapshot!(get_log_output(&work_dir), @"
@ 1bc21d4e92d6 f
â—‹ 8b6b080ab587 d e
│ ○ ee0b260ffc44 c
│ ○ e31bf988d7c9 b
├─╯
â—‹ e3e04beaf7d3 a
â—† 000000000000 (empty)
[EOF]
");
let output = work_dir.run_jj(["file", "show", "file2", "-r", "d"]);
insta::assert_snapshot!(output, @"
e
[EOF]
");
work_dir.run_jj(["op", "restore", &setup_opid]).success();
let output = work_dir.run_jj(["squash", "--from", "e::f", "--into", "d"]);
insta::assert_snapshot!(output, @"
------- stderr -------
Working copy (@) now at: pkstwlsy 76baa567 (empty) (no description set)
Parent commit (@-) : vruxwmqv 415e4069 d e f | (no description set)
[EOF]
");
insta::assert_snapshot!(get_log_output(&work_dir), @"
@ 76baa567ed0a (empty)
â—‹ 415e40694e88 d e f
│ ○ ee0b260ffc44 c
│ ○ e31bf988d7c9 b
├─╯
â—‹ e3e04beaf7d3 a
â—† 000000000000 (empty)
[EOF]
");
let output = work_dir.run_jj(["file", "show", "file2", "-r", "d"]);
insta::assert_snapshot!(output, @"
f
[EOF]
");
}
#[test]
fn test_squash_from_to_partial() -> TestResult {
let mut test_env = TestEnvironment::default();
let edit_script = test_env.set_up_fake_diff_editor();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
work_dir
.run_jj(["bookmark", "create", "-r@", "a"])
.success();
work_dir.write_file("file1", "a\n");
work_dir.write_file("file2", "a\n");
work_dir.write_file("file3", "a\n");
work_dir.run_jj(["new"]).success();
work_dir
.run_jj(["bookmark", "create", "-r@", "b"])
.success();
work_dir.write_file("file3", "b\n");
work_dir.run_jj(["new"]).success();
work_dir
.run_jj(["bookmark", "create", "-r@", "c"])
.success();
work_dir.write_file("file1", "c\n");
work_dir.write_file("file2", "c\n");
work_dir.run_jj(["edit", "a"]).success();
work_dir.run_jj(["new"]).success();
work_dir
.run_jj(["bookmark", "create", "-r@", "d"])
.success();
work_dir.write_file("file3", "d\n");
insta::assert_snapshot!(get_log_output(&work_dir), @"
@ dc71a460d5d6 d
│ ○ 499d601f6046 c
│ ○ e31bf988d7c9 b
├─╯
â—‹ e3e04beaf7d3 a
â—† 000000000000 (empty)
[EOF]
");
let setup_opid = work_dir.current_operation_id();
let output = work_dir.run_jj(["squash", "-i", "--from", "c"]);
insta::assert_snapshot!(output, @"
------- stderr -------
Working copy (@) now at: vruxwmqv 85589465 d | (no description set)
Parent commit (@-) : qpvuntsm e3e04bea a | (no description set)
Added 0 files, modified 2 files, removed 0 files
[EOF]
");
insta::assert_snapshot!(get_log_output(&work_dir), @"
@ 85589465a5f7 d
│ ○ e31bf988d7c9 b c
├─╯
â—‹ e3e04beaf7d3 a
â—† 000000000000 (empty)
[EOF]
");
let output = work_dir.run_jj(["file", "show", "file1"]);
insta::assert_snapshot!(output, @"
c
[EOF]
");
let output = work_dir.run_jj(["file", "show", "file2"]);
insta::assert_snapshot!(output, @"
c
[EOF]
");
let output = work_dir.run_jj(["file", "show", "file3"]);
insta::assert_snapshot!(output, @"
d
[EOF]
");
work_dir.run_jj(["op", "restore", &setup_opid]).success();
std::fs::write(&edit_script, "reset file2")?;
let output = work_dir.run_jj(["squash", "-i", "--from", "c"]);
insta::assert_snapshot!(output, @"
------- stderr -------
Working copy (@) now at: vruxwmqv 62bd5cd9 d | (no description set)
Parent commit (@-) : qpvuntsm e3e04bea a | (no description set)
Added 0 files, modified 1 files, removed 0 files
[EOF]
");
insta::assert_snapshot!(get_log_output(&work_dir), @"
@ 62bd5cd9f413 d
│ ○ 2748f30463ed c
│ ○ e31bf988d7c9 b
├─╯
â—‹ e3e04beaf7d3 a
â—† 000000000000 (empty)
[EOF]
");
let output = work_dir.run_jj(["file", "show", "file1"]);
insta::assert_snapshot!(output, @"
c
[EOF]
");
let output = work_dir.run_jj(["file", "show", "file2"]);
insta::assert_snapshot!(output, @"
a
[EOF]
");
let output = work_dir.run_jj(["file", "show", "file3"]);
insta::assert_snapshot!(output, @"
d
[EOF]
");
work_dir.run_jj(["op", "restore", &setup_opid]).success();
std::fs::write(&edit_script, "")?;
let output = work_dir.run_jj(["squash", "--from", "c", "file1"]);
insta::assert_snapshot!(output, @"
------- stderr -------
Working copy (@) now at: vruxwmqv 76bf6139 d | (no description set)
Parent commit (@-) : qpvuntsm e3e04bea a | (no description set)
Added 0 files, modified 1 files, removed 0 files
[EOF]
");
insta::assert_snapshot!(get_log_output(&work_dir), @"
@ 76bf613928cf d
│ ○ 9d4418d4828e c
│ ○ e31bf988d7c9 b
├─╯
â—‹ e3e04beaf7d3 a
â—† 000000000000 (empty)
[EOF]
");
let output = work_dir.run_jj(["file", "show", "file1"]);
insta::assert_snapshot!(output, @"
c
[EOF]
");
let output = work_dir.run_jj(["file", "show", "file2"]);
insta::assert_snapshot!(output, @"
a
[EOF]
");
let output = work_dir.run_jj(["file", "show", "file3"]);
insta::assert_snapshot!(output, @"
d
[EOF]
");
work_dir.run_jj(["op", "restore", &setup_opid]).success();
std::fs::write(&edit_script, "")?;
let output = work_dir.run_jj(["squash", "--from", "c", "--into", "b", "file1"]);
insta::assert_snapshot!(output, @"
------- stderr -------
Rebased 1 descendant commits
[EOF]
");
insta::assert_snapshot!(get_log_output(&work_dir), @"
@ dc71a460d5d6 d
│ ○ f964ce4bca71 c
│ ○ e12c895adba6 b
├─╯
â—‹ e3e04beaf7d3 a
â—† 000000000000 (empty)
[EOF]
");
let output = work_dir.run_jj(["file", "show", "file1", "-r", "b"]);
insta::assert_snapshot!(output, @"
c
[EOF]
");
let output = work_dir.run_jj(["file", "show", "file2", "-r", "b"]);
insta::assert_snapshot!(output, @"
a
[EOF]
");
work_dir.run_jj(["op", "restore", &setup_opid]).success();
let output = work_dir.run_jj(["squash", "--from", "c", "nonexistent"]);
insta::assert_snapshot!(output, @"
------- stderr -------
Warning: No matching entries for paths: nonexistent
Nothing changed.
[EOF]
");
Ok(())
}
#[test]
fn test_squash_from_multiple() {
let test_env = TestEnvironment::default();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
work_dir
.run_jj(["bookmark", "create", "-r@", "a"])
.success();
work_dir.write_file("file", "a\n");
work_dir.run_jj(["new"]).success();
work_dir
.run_jj(["bookmark", "create", "-r@", "b"])
.success();
work_dir.write_file("file", "b\n");
work_dir.run_jj(["new", "@-"]).success();
work_dir
.run_jj(["bookmark", "create", "-r@", "c"])
.success();
work_dir.write_file("file", "c\n");
work_dir.run_jj(["new", "@-"]).success();
work_dir
.run_jj(["bookmark", "create", "-r@", "d"])
.success();
work_dir.write_file("file", "d\n");
work_dir.run_jj(["new", "visible_heads()"]).success();
work_dir
.run_jj(["bookmark", "create", "-r@", "e"])
.success();
work_dir.write_file("file", "e\n");
work_dir.run_jj(["new"]).success();
work_dir
.run_jj(["bookmark", "create", "-r@", "f"])
.success();
work_dir.write_file("file", "f\n");
insta::assert_snapshot!(get_log_output(&work_dir), @"
@ 65e53f39b4d6 f
â—‹ 7dc592781647 e
├─┬─╮
│ │ ○ fed4d1a2e491 b
│ ○ │ d7e94ec7e73e c
│ ├─╯
○ │ 8acbb71558d5 d
├─╯
â—‹ e88768e65e67 a
â—† 000000000000 (empty)
[EOF]
");
let setup_opid = work_dir.current_operation_id();
let output = work_dir.run_jj(["squash", "--from=b", "--from=c", "--into=d"]);
insta::assert_snapshot!(output, @"
------- stderr -------
Rebased 2 descendant commits
Working copy (@) now at: kpqxywon f584da5f f | (no description set)
Parent commit (@-) : yostqsxw 6fbe5593 e | (no description set)
New conflicts appeared in 1 commits:
yqosqzyt 3592e886 d | (conflict) (no description set)
Hint: To resolve the conflicts, start by creating a commit on top of
the conflicted commit:
jj new yqosqzyt
Then use `jj resolve`, or edit the conflict markers in the file directly.
Once the conflicts are resolved, you can inspect the result with `jj diff`.
Then run `jj squash` to move the resolution into the conflicted commit.
[EOF]
");
insta::assert_snapshot!(get_log_output(&work_dir), @"
@ f584da5f6b0d f
â—‹ 6fbe5593f24a e
├─╮
× │ 3592e886b254 d
├─╯
â—‹ e88768e65e67 a b c
â—† 000000000000 (empty)
[EOF]
");
let output = work_dir.run_jj(["file", "show", "-r=d", "file"]);
insta::assert_snapshot!(output, @r"
<<<<<<< conflict 1 of 1
%%%%%%% diff from: qpvuntsm e88768e6 (parents of squashed revision)
\\\\\\\ to: yqosqzyt 8acbb715 (squash destination)
-a
+d
%%%%%%% diff from: qpvuntsm e88768e6 (parents of squashed revision)
\\\\\\\ to: kkmpptxz fed4d1a2 (squashed revision)
-a
+b
+++++++ mzvwutvl d7e94ec7 (squashed revision)
c
>>>>>>> conflict 1 of 1 ends
[EOF]
");
work_dir.run_jj(["op", "restore", &setup_opid]).success();
let output = work_dir.run_jj(["squash", "--from=b|c|f", "--into=e"]);
insta::assert_snapshot!(output, @"
------- stderr -------
Rebased 1 descendant commits
Working copy (@) now at: xznxytkn ec32238b (empty) (no description set)
Parent commit (@-) : yostqsxw 5298eef6 e f | (no description set)
[EOF]
");
insta::assert_snapshot!(get_log_output(&work_dir), @"
@ ec32238b2be5 (empty)
â—‹ 5298eef6bca5 e f
├─╮
○ │ 8acbb71558d5 d
├─╯
â—‹ e88768e65e67 a b c
â—† 000000000000 (empty)
[EOF]
");
let output = work_dir.run_jj(["file", "show", "-r=e", "file"]);
insta::assert_snapshot!(output, @"
f
[EOF]
");
let output = work_dir.run_jj(["squash", "--from=none()"]);
insta::assert_snapshot!(output, @"
------- stderr -------
Nothing changed.
[EOF]
");
}
#[test]
fn test_squash_from_multiple_partial() {
let test_env = TestEnvironment::default();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
work_dir
.run_jj(["bookmark", "create", "-r@", "a"])
.success();
work_dir.write_file("file1", "a\n");
work_dir.write_file("file2", "a\n");
work_dir.run_jj(["new"]).success();
work_dir
.run_jj(["bookmark", "create", "-r@", "b"])
.success();
work_dir.write_file("file1", "b\n");
work_dir.write_file("file2", "b\n");
work_dir.run_jj(["new", "@-"]).success();
work_dir
.run_jj(["bookmark", "create", "-r@", "c"])
.success();
work_dir.write_file("file1", "c\n");
work_dir.write_file("file2", "c\n");
work_dir.run_jj(["new", "@-"]).success();
work_dir
.run_jj(["bookmark", "create", "-r@", "d"])
.success();
work_dir.write_file("file1", "d\n");
work_dir.write_file("file2", "d\n");
work_dir.run_jj(["new", "visible_heads()"]).success();
work_dir
.run_jj(["bookmark", "create", "-r@", "e"])
.success();
work_dir.write_file("file1", "e\n");
work_dir.write_file("file2", "e\n");
work_dir.run_jj(["new"]).success();
work_dir
.run_jj(["bookmark", "create", "-r@", "f"])
.success();
work_dir.write_file("file1", "f\n");
work_dir.write_file("file2", "f\n");
insta::assert_snapshot!(get_log_output(&work_dir), @"
@ 4558bd852475 f
â—‹ e2db96b2e57a e
├─┬─╮
│ │ ○ f2c9709f39e9 b
│ ○ │ aa908686a197 c
│ ├─╯
○ │ f6812ff8db35 d
├─╯
â—‹ 64ea60be8d77 a
â—† 000000000000 (empty)
[EOF]
");
let setup_opid = work_dir.current_operation_id();
let output = work_dir.run_jj(["squash", "--from=b|c", "--into=d", "file1"]);
insta::assert_snapshot!(output, @"
------- stderr -------
Rebased 2 descendant commits
Working copy (@) now at: kpqxywon 9113246b f | (no description set)
Parent commit (@-) : yostqsxw f069c595 e | (no description set)
New conflicts appeared in 1 commits:
yqosqzyt 35455ce2 d | (conflict) (no description set)
Hint: To resolve the conflicts, start by creating a commit on top of
the conflicted commit:
jj new yqosqzyt
Then use `jj resolve`, or edit the conflict markers in the file directly.
Once the conflicts are resolved, you can inspect the result with `jj diff`.
Then run `jj squash` to move the resolution into the conflicted commit.
[EOF]
");
insta::assert_snapshot!(get_log_output(&work_dir), @"
@ 9113246bdbc0 f
â—‹ f069c5953603 e
├─┬─╮
│ │ ○ e9db15b956c4 b
│ ○ │ 83cbe51db94d c
│ ├─╯
× │ 35455ce2c7a8 d
├─╯
â—‹ 64ea60be8d77 a
â—† 000000000000 (empty)
[EOF]
");
let output = work_dir.run_jj(["file", "show", "-r=b", "file1"]);
insta::assert_snapshot!(output, @"
a
[EOF]
");
let output = work_dir.run_jj(["file", "show", "-r=c", "file1"]);
insta::assert_snapshot!(output, @"
a
[EOF]
");
let output = work_dir.run_jj(["file", "show", "-r=d", "file1"]);
insta::assert_snapshot!(output, @r"
<<<<<<< conflict 1 of 1
%%%%%%% diff from: qpvuntsm 64ea60be (parents of squashed revision)
\\\\\\\ to: yqosqzyt f6812ff8 (squash destination)
-a
+d
%%%%%%% diff from: qpvuntsm 64ea60be (parents of squashed revision)
\\\\\\\ to: selected changes for squash (from kkmpptxz f2c9709f)
-a
+b
+++++++ selected changes for squash (from mzvwutvl aa908686)
c
>>>>>>> conflict 1 of 1 ends
[EOF]
");
let output = work_dir.run_jj(["file", "show", "-r=d", "file2"]);
insta::assert_snapshot!(output, @"
d
[EOF]
");
work_dir.run_jj(["op", "restore", &setup_opid]).success();
let output = work_dir.run_jj(["squash", "--from=b|c|f", "--into=e", "file1"]);
insta::assert_snapshot!(output, @"
------- stderr -------
Rebased 1 descendant commits
Working copy (@) now at: kpqxywon b5a40c15 f | (no description set)
Parent commit (@-) : yostqsxw 5dea187c e | (no description set)
[EOF]
");
insta::assert_snapshot!(get_log_output(&work_dir), @"
@ b5a40c154611 f
â—‹ 5dea187c414d e
├─┬─╮
│ │ ○ 8b9afc05ca07 b
│ ○ │ 5630471a8fd5 c
│ ├─╯
○ │ f6812ff8db35 d
├─╯
â—‹ 64ea60be8d77 a
â—† 000000000000 (empty)
[EOF]
");
let output = work_dir.run_jj(["file", "show", "-r=b", "file1"]);
insta::assert_snapshot!(output, @"
a
[EOF]
");
let output = work_dir.run_jj(["file", "show", "-r=c", "file1"]);
insta::assert_snapshot!(output, @"
a
[EOF]
");
let output = work_dir.run_jj(["file", "show", "-r=f", "file1"]);
insta::assert_snapshot!(output, @"
f
[EOF]
");
let output = work_dir.run_jj(["file", "show", "-r=e", "file1"]);
insta::assert_snapshot!(output, @"
f
[EOF]
");
let output = work_dir.run_jj(["file", "show", "-r=d", "file2"]);
insta::assert_snapshot!(output, @"
d
[EOF]
");
}
#[test]
fn test_squash_from_multiple_partial_no_op() {
let test_env = TestEnvironment::default();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
work_dir.run_jj(["describe", "-m=a"]).success();
work_dir.write_file("a", "a\n");
work_dir.run_jj(["new", "-m=b"]).success();
work_dir.write_file("b", "b\n");
work_dir.run_jj(["new", "@-", "-m=c"]).success();
work_dir.write_file("c", "c\n");
work_dir.run_jj(["new", "@-", "-m=d"]).success();
work_dir.write_file("d", "d\n");
insta::assert_snapshot!(get_log_output(&work_dir), @"
@ fdb92bc249a0 d
│ ○ 0dc8cb72859d c
├─╯
│ ○ b1a17f79a1a5 b
├─╯
â—‹ 93d495c46d89 a
â—† 000000000000 (empty)
[EOF]
");
let setup_opid = work_dir.current_operation_id();
let output = work_dir.run_jj(["squash", "--from=@-+ ~ @", "--into=@", "-m=d", "b"]);
insta::assert_snapshot!(output, @"
------- stderr -------
Working copy (@) now at: mzvwutvl 6dfc239e d
Parent commit (@-) : qpvuntsm 93d495c4 a
Added 1 files, modified 0 files, removed 0 files
[EOF]
");
insta::assert_snapshot!(get_log_output(&work_dir), @"
@ 6dfc239e2ba3 d
│ ○ 0dc8cb72859d c
├─╯
â—‹ 93d495c46d89 a
â—† 000000000000 (empty)
[EOF]
");
let output = work_dir.run_jj([
"evolog",
"-T",
r#"separate(" ", commit.commit_id().short(), commit.description())"#,
]);
insta::assert_snapshot!(output, @"
@ 6dfc239e2ba3 d
├─╮
│ ○ b1a17f79a1a5 b
│ ○ d8b7d57239ca b
â—‹ fdb92bc249a0 d
â—‹ af709ccc1ca9 d
[EOF]
");
work_dir.run_jj(["op", "restore", &setup_opid]).success();
let output = work_dir.run_jj(["squash", "--from=@-+ ~ @", "--into=@", "-m=d", "a"]);
insta::assert_snapshot!(output, @"
------- stderr -------
Nothing changed.
[EOF]
");
insta::assert_snapshot!(get_log_output(&work_dir), @"
@ fdb92bc249a0 d
│ ○ 0dc8cb72859d c
├─╯
│ ○ b1a17f79a1a5 b
├─╯
â—‹ 93d495c46d89 a
â—† 000000000000 (empty)
[EOF]
");
}
#[must_use]
fn get_log_output(work_dir: &TestWorkDir) -> CommandOutput {
let template = r#"separate(
" ",
commit_id.short(),
bookmarks,
description,
if(empty, "(empty)")
)"#;
work_dir.run_jj(["log", "-T", template])
}
#[test]
fn test_squash_description() -> TestResult {
let mut test_env = TestEnvironment::default();
let edit_script = test_env.set_up_fake_editor();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
std::fs::write(&edit_script, r#"fail"#)?;
work_dir.write_file("file1", "a\n");
work_dir.write_file("file2", "a\n");
work_dir.run_jj(["new"]).success();
work_dir.write_file("file1", "b\n");
work_dir.write_file("file2", "b\n");
work_dir.run_jj(["debug", "snapshot"]).success();
let setup_opid1 = work_dir.current_operation_id();
work_dir.run_jj(["squash"]).success();
insta::assert_snapshot!(get_description(&work_dir, "@-"), @"");
work_dir.run_jj(["op", "restore", &setup_opid1]).success();
work_dir.run_jj(["describe", "-m", "source"]).success();
work_dir.run_jj(["squash"]).success();
insta::assert_snapshot!(get_description(&work_dir, "@-"), @"
source
[EOF]
");
work_dir.run_jj(["op", "restore", &setup_opid1]).success();
work_dir
.run_jj(["describe", "@-", "-m", "destination"])
.success();
let setup_opid2 = work_dir.current_operation_id();
work_dir.run_jj(["squash"]).success();
insta::assert_snapshot!(get_description(&work_dir, "@-"), @"
destination
[EOF]
");
work_dir.run_jj(["op", "restore", &setup_opid2]).success();
work_dir.run_jj(["squash", "-m", "custom"]).success();
insta::assert_snapshot!(get_description(&work_dir, "@-"), @"
custom
[EOF]
");
work_dir.run_jj(["op", "restore", &setup_opid2]).success();
work_dir.run_jj(["describe", "-m", "source"]).success();
let setup_opid3 = work_dir.current_operation_id();
std::fs::write(&edit_script, "dump editor0")?;
work_dir.run_jj(["squash"]).success();
insta::assert_snapshot!(get_description(&work_dir, "@-"), @"
destination
source
[EOF]
");
let editor0 = std::fs::read_to_string(test_env.env_root().join("editor0"))?;
insta::assert_snapshot!(
editor0, @r#"
JJ: Enter a description for the combined commit.
JJ: Description from the destination commit:
destination
JJ: Description from source commit:
source
JJ: Change ID: qpvuntsm
JJ: This commit contains the following changes:
JJ: A file1
JJ: A file2
JJ:
JJ: Lines starting with "JJ:" (like this one) will be removed.
"#);
work_dir.run_jj(["op", "restore", &setup_opid3]).success();
work_dir.run_jj(["squash", "-m", "custom"]).success();
insta::assert_snapshot!(get_description(&work_dir, "@-"), @"
custom
[EOF]
");
work_dir.run_jj(["op", "restore", &setup_opid3]).success();
work_dir
.run_jj([
"squash",
"--config",
r#"templates.commit_trailers='"CC: " ++ committer.email()'"#,
"-m",
"custom",
])
.success();
insta::assert_snapshot!(get_description(&work_dir, "@-"), @"
custom
CC: test.user@example.com
[EOF]
");
work_dir.run_jj(["op", "restore", &setup_opid3]).success();
work_dir.run_jj(["squash", "file1"]).success();
insta::assert_snapshot!(get_description(&work_dir, "@-"), @"
destination
[EOF]
");
insta::assert_snapshot!(get_description(&work_dir, "@"), @"
source
[EOF]
");
work_dir.run_jj(["op", "restore", &setup_opid3]).success();
work_dir
.run_jj(["describe", "-m", "source\n\nfoo: bar"])
.success();
std::fs::write(&edit_script, "dump editor0")?;
work_dir
.run_jj([
"squash",
"--config",
r#"templates.commit_trailers='"CC: alice@example.com\nfoo: bar"'"#,
])
.success();
let editor0 = std::fs::read_to_string(test_env.env_root().join("editor0"))?;
insta::assert_snapshot!(
editor0, @r#"
JJ: Enter a description for the combined commit.
JJ: Description from the destination commit:
destination
JJ: Description from source commit:
source
foo: bar
JJ: Trailers not found in the squashed commits:
CC: alice@example.com
JJ: Change ID: qpvuntsm
JJ: This commit contains the following changes:
JJ: A file1
JJ: A file2
JJ:
JJ: Lines starting with "JJ:" (like this one) will be removed.
"#);
work_dir.run_jj(["op", "restore", &setup_opid3]).success();
work_dir
.run_jj(["describe", "-m", "source\n\nfoo: bar\nbaz: quux"])
.success();
std::fs::write(&edit_script, "dump editor0").unwrap();
work_dir
.run_jj([
"squash",
"--config",
r#"templates.commit_trailers='"baz: quux\nfoo: bar"'"#,
])
.success();
insta::assert_snapshot!(
std::fs::read_to_string(test_env.env_root().join("editor0")).unwrap(), @r#"
JJ: Enter a description for the combined commit.
JJ: Description from the destination commit:
destination
JJ: Description from source commit:
source
foo: bar
baz: quux
JJ: Change ID: qpvuntsm
JJ: This commit contains the following changes:
JJ: A file1
JJ: A file2
JJ:
JJ: Lines starting with "JJ:" (like this one) will be removed.
"#);
work_dir.run_jj(["op", "restore", &setup_opid3]).success();
work_dir.run_jj(["describe", "-m", ""]).success();
insta::assert_snapshot!(get_log_output_with_description(&work_dir), @"
@ 452e4831d64b
â—‹ e650dfcd7312 destination
â—† 000000000000
[EOF]
");
work_dir
.run_jj([
"squash",
"--config",
r#"templates.commit_trailers='"CC: alice@example.com"'"#,
])
.success();
insta::assert_snapshot!(get_description(&work_dir, "@-"), @"
destination
CC: alice@example.com
[EOF]
");
work_dir.run_jj(["op", "restore", &setup_opid3]).success();
work_dir
.run_jj(["describe", "-r", "@-", "-m", ""])
.success();
insta::assert_snapshot!(get_log_output_with_description(&work_dir), @"
@ 78e7f58582e8 source
â—‹ a01e1865957e
â—† 000000000000
[EOF]
");
work_dir
.run_jj([
"squash",
"--config",
r#"templates.commit_trailers='"CC: alice@example.com"'"#,
])
.success();
insta::assert_snapshot!(get_description(&work_dir, "@-"), @"
source
CC: alice@example.com
[EOF]
");
work_dir.run_jj(["op", "restore", &setup_opid3]).success();
work_dir
.run_jj(["describe", "-r", "..", "-m", ""])
.success();
insta::assert_snapshot!(get_log_output_with_description(&work_dir), @"
@ 8a34624ec18b
â—‹ 2560c9e5ef72
â—† 000000000000
[EOF]
");
work_dir
.run_jj([
"squash",
"--config",
r#"templates.commit_trailers='"CC: bob@example.com"'"#,
])
.success();
insta::assert_snapshot!(get_description(&work_dir, "@-"), @"");
work_dir.run_jj(["op", "restore", &setup_opid3]).success();
work_dir
.run_jj(["describe", "-r", "@-", "-m", ""])
.success();
insta::assert_snapshot!(get_log_output_with_description(&work_dir), @"
@ 405f52356ed5 source
â—‹ ecf32ca3d742
â—† 000000000000
[EOF]
");
work_dir
.run_jj([
"squash",
"--use-destination-message",
"--config",
r#"templates.commit_trailers='"CC: bob@example.com"'"#,
])
.success();
insta::assert_snapshot!(get_description(&work_dir, "@-"), @"");
work_dir.run_jj(["op", "restore", &setup_opid3]).success();
insta::assert_snapshot!(get_log_output_with_description(&work_dir), @"
@ 2a79b102bf46 source
â—‹ e650dfcd7312 destination
â—† 000000000000
[EOF]
");
work_dir
.run_jj([
"squash",
"--message",
"",
"--config",
r#"templates.commit_trailers='"CC: bob@example.com"'"#,
])
.success();
insta::assert_snapshot!(get_description(&work_dir, "@-"), @"");
work_dir.run_jj(["op", "restore", &setup_opid3]).success();
work_dir.write_file("data.txt", b"\xff\n");
insta::assert_snapshot!(get_log_output_with_description(&work_dir), @"
@ 9eec7f21360c source
â—‹ e650dfcd7312 destination
â—† 000000000000
[EOF]
");
let output = work_dir.run_jj([
"squash",
"--config",
r#"templates.commit_trailers='indent("Content: ", diff.git())'"#,
]);
insta::assert_snapshot!(output, @"
------- stderr -------
Error: Trailers should be valid utf-8
[EOF]
[exit status: 1]
");
Ok(())
}
#[test]
fn test_squash_description_editor_avoids_unc() -> TestResult {
let mut test_env = TestEnvironment::default();
let edit_script = test_env.set_up_fake_editor();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
work_dir.write_file("file1", "a\n");
work_dir.write_file("file2", "a\n");
work_dir.run_jj(["new"]).success();
work_dir.write_file("file1", "b\n");
work_dir.write_file("file2", "b\n");
work_dir
.run_jj(["describe", "@-", "-m", "destination"])
.success();
work_dir.run_jj(["describe", "-m", "source"]).success();
std::fs::write(edit_script, "dump-path path")?;
work_dir.run_jj(["squash"]).success();
let edited_path = PathBuf::from(std::fs::read_to_string(test_env.env_root().join("path"))?);
assert_eq!(edited_path, dunce::simplified(&edited_path));
Ok(())
}
#[test]
fn test_squash_empty() {
let mut test_env = TestEnvironment::default();
test_env.set_up_fake_editor();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
work_dir.run_jj(["commit", "-m", "parent"]).success();
let output = work_dir.run_jj(["squash"]);
insta::assert_snapshot!(output, @"
------- stderr -------
Working copy (@) now at: kkmpptxz db7ad962 (empty) (no description set)
Parent commit (@-) : qpvuntsm 771da191 (empty) parent
[EOF]
");
insta::assert_snapshot!(get_description(&work_dir, "@-"), @"
parent
[EOF]
");
work_dir.run_jj(["describe", "-m", "child"]).success();
work_dir.run_jj(["squash"]).success();
insta::assert_snapshot!(get_description(&work_dir, "@-"), @"
parent
child
[EOF]
");
}
#[test]
fn test_squash_use_destination_message() {
let test_env = TestEnvironment::default();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
work_dir.run_jj(["commit", "-m=a"]).success();
work_dir.run_jj(["commit", "-m=b"]).success();
work_dir.run_jj(["describe", "-m=c"]).success();
insta::assert_snapshot!(get_log_output_with_description(&work_dir), @"
@ cf388db088f7 c
â—‹ e412ddda5587 b
â—‹ b86e28cd6862 a
â—† 000000000000
[EOF]
");
let setup_opid = work_dir.current_operation_id();
work_dir.run_jj(["squash", "-u"]).success();
insta::assert_snapshot!(get_log_output_with_description(&work_dir), @"
@ 70c0f74e4486
â—‹ 44c1701e4ef8 b
â—‹ b86e28cd6862 a
â—† 000000000000
[EOF]
");
work_dir.run_jj(["op", "restore", &setup_opid]).success();
work_dir
.run_jj([
"squash",
"--use-destination-message",
"--from=subject(b)::",
"--into=subject(a)",
])
.success();
insta::assert_snapshot!(get_log_output_with_description(&work_dir), @"
@ e5a16e0e6a46
â—‹ 6e47254e0803 a
â—† 000000000000
[EOF]
");
}
#[test]
fn test_squash_option_exclusion() {
let test_env = TestEnvironment::default();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
work_dir.run_jj(["commit", "-m=a"]).success();
work_dir.run_jj(["describe", "-m=b"]).success();
insta::assert_snapshot!(work_dir.run_jj([
"squash",
"--message=123",
"--use-destination-message",
]), @"
------- stderr -------
error: the argument '--message <MESSAGE>' cannot be used with '--use-destination-message'
Usage: jj squash --message <MESSAGE> [FILESETS]...
For more information, try '--help'.
[EOF]
[exit status: 2]
");
insta::assert_snapshot!(work_dir.run_jj([
"squash",
"-r@",
"--into=@-"
]), @"
------- stderr -------
error: the argument '--revision <REVSET>' cannot be used with '--into <REVSET>'
Usage: jj squash --revision <REVSET> [FILESETS]...
For more information, try '--help'.
[EOF]
[exit status: 2]
");
insta::assert_snapshot!(work_dir.run_jj([
"squash",
"-r@",
"--onto=@-"
]), @"
------- stderr -------
error: the argument '--revision <REVSET>' cannot be used with '--onto <REVSETS>'
Usage: jj squash --revision <REVSET> [FILESETS]...
For more information, try '--help'.
[EOF]
[exit status: 2]
");
insta::assert_snapshot!(work_dir.run_jj([
"squash",
"-r@",
"--after=@-"
]), @"
------- stderr -------
error: the argument '--revision <REVSET>' cannot be used with '--insert-after <REVSETS>'
Usage: jj squash --revision <REVSET> [FILESETS]...
For more information, try '--help'.
[EOF]
[exit status: 2]
");
insta::assert_snapshot!(work_dir.run_jj([
"squash",
"-r@",
"--before=@-"
]), @"
------- stderr -------
error: the argument '--revision <REVSET>' cannot be used with '--insert-before <REVSETS>'
Usage: jj squash --revision <REVSET> [FILESETS]...
For more information, try '--help'.
[EOF]
[exit status: 2]
");
insta::assert_snapshot!(work_dir.run_jj([
"squash",
"--onto=@",
"--into=@-"
]), @"
------- stderr -------
error: the argument '--onto <REVSETS>' cannot be used with '--into <REVSET>'
Usage: jj squash --onto <REVSETS> [FILESETS]...
For more information, try '--help'.
[EOF]
[exit status: 2]
");
insta::assert_snapshot!(work_dir.run_jj([
"squash",
"--after=@",
"--into=@-"
]), @"
------- stderr -------
error: the argument '--insert-after <REVSETS>' cannot be used with '--into <REVSET>'
Usage: jj squash --insert-after <REVSETS> [FILESETS]...
For more information, try '--help'.
[EOF]
[exit status: 2]
");
insta::assert_snapshot!(work_dir.run_jj([
"squash",
"--before=@-",
"--into=@-"
]), @"
------- stderr -------
error: the argument '--insert-before <REVSETS>' cannot be used with '--into <REVSET>'
Usage: jj squash --insert-before <REVSETS> [FILESETS]...
For more information, try '--help'.
[EOF]
[exit status: 2]
");
}
#[test]
fn test_squash_to_new_commit() -> TestResult {
let mut test_env = TestEnvironment::default();
let edit_script = test_env.set_up_fake_editor();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
work_dir.write_file("file1", "file1\n");
work_dir.run_jj(["commit", "-m", "file1"]).success();
work_dir.write_file("file2", "file2\n");
work_dir.run_jj(["commit", "-m", "file2"]).success();
work_dir.write_file("file3", "file3\n");
work_dir.run_jj(["commit", "-m", "file3"]).success();
work_dir.write_file("file4", "file4\n");
work_dir.run_jj(["commit", "-m", "file4"]).success();
work_dir
.run_jj(["bookmark", "create", "bm4", "-r", "@-"])
.success();
work_dir
.run_jj(["bookmark", "create", "bm3", "-r", "bm4-"])
.success();
work_dir
.run_jj(["bookmark", "create", "bm2", "-r", "bm3-"])
.success();
work_dir
.run_jj(["bookmark", "create", "bm1", "-r", "bm2-"])
.success();
let setup_opid = work_dir.current_operation_id();
insta::assert_snapshot!(get_log_with_summary(&work_dir), @"
@ mzvwutvlkqwt
â—‹ zsuskulnrvyr bm4 file4
│ A file4
â—‹ kkmpptxzrspx bm3 file3
│ A file3
â—‹ rlvkpnrzqnoo bm2 file2
│ A file2
â—‹ qpvuntsmwlqt bm1 file1
│ A file1
â—† zzzzzzzzzzzz
[EOF]
");
let output = work_dir.run_jj([
"squash",
"-m",
"file 3&4",
"-f",
"kkmpptxzrspx::",
"--insert-before",
"qpvuntsmwlqt",
]);
insta::assert_snapshot!(output, @"
------- stderr -------
Created new commit kpqxywon f87660dd file 3&4
Rebased 2 descendant commits
Working copy (@) now at: vzqnnsmr 35736bd0 (empty) (no description set)
Parent commit (@-) : rlvkpnrz 4c273fe2 bm2 bm3 bm4 | file2
[EOF]
");
insta::assert_snapshot!(get_log_with_summary(&work_dir), @"
@ vzqnnsmrxxkw
â—‹ rlvkpnrzqnoo bm2 bm3 bm4 file2
│ A file2
â—‹ qpvuntsmwlqt bm1 file1
│ A file1
â—‹ kpqxywonksrl file 3&4
│ A file3
│ A file4
â—† zzzzzzzzzzzz
[EOF]
");
work_dir.run_jj(["op", "restore", &setup_opid]).success();
let output = work_dir.run_jj([
"squash",
"-m",
"file 3&4",
"-f",
"kkmpptxzrspx::",
"--insert-after",
"qpvuntsmwlqt",
]);
insta::assert_snapshot!(output, @"
------- stderr -------
Created new commit lylxulpl 43cf43eb file 3&4
Rebased 1 descendant commits
Working copy (@) now at: rsllmpnm 42df41a1 (empty) (no description set)
Parent commit (@-) : rlvkpnrz 3a4b2e8a bm2 bm3 bm4 | file2
[EOF]
");
insta::assert_snapshot!(get_log_with_summary(&work_dir), @"
@ rsllmpnmslon
â—‹ rlvkpnrzqnoo bm2 bm3 bm4 file2
│ A file2
â—‹ lylxulplsnyw file 3&4
│ A file3
│ A file4
â—‹ qpvuntsmwlqt bm1 file1
│ A file1
â—† zzzzzzzzzzzz
[EOF]
");
work_dir.run_jj(["op", "restore", &setup_opid]).success();
let output = work_dir.run_jj([
"squash",
"-m",
"file 3&4",
"-f",
"kkmpptxzrspx::",
"--onto",
"qpvuntsmwlqt",
]);
insta::assert_snapshot!(output, @"
------- stderr -------
Created new commit uyznsvlq fd4b7c85 file 3&4
Working copy (@) now at: uuqyqztp c2d532a4 (empty) (no description set)
Parent commit (@-) : rlvkpnrz 27974c44 bm2 bm3 bm4 | file2
Added 0 files, modified 0 files, removed 2 files
[EOF]
");
insta::assert_snapshot!(get_log_with_summary(&work_dir), @"
@ uuqyqztpptml
â—‹ rlvkpnrzqnoo bm2 bm3 bm4 file2
│ A file2
│ ○ uyznsvlquzzm file 3&4
├─╯ A file3
│ A file4
â—‹ qpvuntsmwlqt bm1 file1
│ A file1
â—† zzzzzzzzzzzz
[EOF]
");
work_dir.run_jj(["op", "restore", &setup_opid]).success();
let output = work_dir.run_jj([
"squash",
"-m",
"file 3&4",
"-f",
"kkmpptxzrspx::",
"--insert-after",
"zsuskulnrvyr",
]);
insta::assert_snapshot!(output, @"
------- stderr -------
Created new commit nmzmmopx c7558c47 file 3&4
Rebased 1 descendant commits
Working copy (@) now at: pwyqokvy 525d9441 (empty) (no description set)
Parent commit (@-) : nmzmmopx c7558c47 file 3&4
[EOF]
");
insta::assert_snapshot!(get_log_with_summary(&work_dir), @"
@ pwyqokvyvunr
â—‹ nmzmmopxokps file 3&4
│ A file3
│ A file4
â—‹ rlvkpnrzqnoo bm2 bm3 bm4 file2
│ A file2
â—‹ qpvuntsmwlqt bm1 file1
│ A file1
â—† zzzzzzzzzzzz
[EOF]
");
work_dir.run_jj(["op", "restore", &setup_opid]).success();
let output = work_dir.run_jj([
"squash",
"-m",
"file 3&4",
"-f",
"kkmpptxzrspx::",
"--insert-before",
"zsuskulnrvyr",
]);
insta::assert_snapshot!(output, @"
------- stderr -------
Created new commit nlrtlrxv c5286eac bm4 | file 3&4
Rebased 1 descendant commits
Working copy (@) now at: plymsszl faf348e7 (empty) (no description set)
Parent commit (@-) : nlrtlrxv c5286eac bm4 | file 3&4
[EOF]
");
insta::assert_snapshot!(get_log_with_summary(&work_dir), @"
@ plymsszllttm
â—‹ nlrtlrxvuusk bm4 file 3&4
│ A file3
│ A file4
â—‹ rlvkpnrzqnoo bm2 bm3 file2
│ A file2
â—‹ qpvuntsmwlqt bm1 file1
│ A file1
â—† zzzzzzzzzzzz
[EOF]
");
work_dir.run_jj(["op", "restore", &setup_opid]).success();
let output = work_dir.run_jj([
"squash",
"-m",
"file 3&4",
"-f",
"kkmpptxzrspx::",
"--onto",
"rlvkpnrzqnoo",
"--onto",
"kkmpptxzrspx",
]);
insta::assert_snapshot!(output, @"
------- stderr -------
Created new commit uuuvxpvw 2ad3f239 file 3&4
Working copy (@) now at: nmpuuozl 95ef3451 (empty) (no description set)
Parent commit (@-) : rlvkpnrz 27974c44 bm2 bm3 bm4 | file2
Added 0 files, modified 0 files, removed 2 files
[EOF]
");
insta::assert_snapshot!(get_log_with_summary(&work_dir), @"
@ nmpuuozlonyz
│ ○ uuuvxpvwspwr file 3&4
├─╯ A file3
│ A file4
â—‹ rlvkpnrzqnoo bm2 bm3 bm4 file2
│ A file2
â—‹ qpvuntsmwlqt bm1 file1
│ A file1
â—† zzzzzzzzzzzz
[EOF]
");
work_dir.run_jj(["op", "restore", &setup_opid]).success();
std::fs::write(edit_script, ["dump editor1", "write\nfile 3&4"].join("\0"))?;
let output = work_dir.run_jj([
"squash",
"-f",
"kkmpptxzrspx::zsuskulnrvyr",
"--insert-before",
"qpvuntsmwlqt",
]);
insta::assert_snapshot!(output, @"
------- stderr -------
Created new commit pkstwlsy 41510a56 file 3&4
Rebased 3 descendant commits
Working copy (@) now at: mzvwutvl 3d11750f (empty) (no description set)
Parent commit (@-) : rlvkpnrz 8ed73d06 bm2 bm3 bm4 | file2
[EOF]
");
let editor1 = std::fs::read_to_string(test_env.env_root().join("editor1"))?;
insta::assert_snapshot!(
editor1, @r#"
JJ: Enter a description for the combined commit.
JJ: Description from source commit:
file3
JJ: Description from source commit:
file4
JJ: Change ID: pkstwlsy
JJ: This commit contains the following changes:
JJ: A file3
JJ: A file4
JJ:
JJ: Lines starting with "JJ:" (like this one) will be removed.
"#);
insta::assert_snapshot!(get_log_with_summary(&work_dir), @"
@ mzvwutvlkqwt
â—‹ rlvkpnrzqnoo bm2 bm3 bm4 file2
│ A file2
â—‹ qpvuntsmwlqt bm1 file1
│ A file1
â—‹ pkstwlsyuyku file 3&4
│ A file3
│ A file4
â—† zzzzzzzzzzzz
[EOF]
");
let output = work_dir.run_jj(["evolog", "-r", "pkstwlsyuyku"]);
insta::assert_snapshot!(output, @"
â—‹ pkstwlsy test.user@example.com 2001-02-03 08:05:35 41510a56
├─╮ file 3&4
│ │ -- operation 3d6e647dccb7 squash commit 0d254956d33ed5bb11d93eb795c5e514aadc81b5 and 1 more
│ ○ zsuskuln/0 test.user@example.com 2001-02-03 08:05:35 a5bc761f (hidden)
│ │ file4
│ │ -- operation 3d6e647dccb7 squash commit 0d254956d33ed5bb11d93eb795c5e514aadc81b5 and 1 more
│ ○ zsuskuln/4 test.user@example.com 2001-02-03 08:05:11 38778966 (hidden)
│ │ file4
│ │ -- operation 9ca0f4771551 commit 89a30a7539466ed176c1ef122a020fd9cb15848e
│ ○ zsuskuln/5 test.user@example.com 2001-02-03 08:05:11 89a30a75 (hidden)
│ │ (no description set)
│ │ -- operation 26b29f385618 snapshot working copy
│ ○ zsuskuln/6 test.user@example.com 2001-02-03 08:05:10 bbf04d26 (hidden)
│ (empty) (no description set)
│ -- operation fc5403fc3984 commit c23c424826221bc4fdee9487926595324e50ee95
â—‹ kkmpptxz/0 test.user@example.com 2001-02-03 08:05:35 ce3b0a58 (hidden)
│ file3
│ -- operation 3d6e647dccb7 squash commit 0d254956d33ed5bb11d93eb795c5e514aadc81b5 and 1 more
â—‹ kkmpptxz/3 test.user@example.com 2001-02-03 08:05:10 0d254956 (hidden)
│ file3
│ -- operation fc5403fc3984 commit c23c424826221bc4fdee9487926595324e50ee95
â—‹ kkmpptxz/4 test.user@example.com 2001-02-03 08:05:10 c23c4248 (hidden)
│ (no description set)
│ -- operation c5043d80534d snapshot working copy
â—‹ kkmpptxz/5 test.user@example.com 2001-02-03 08:05:09 c1272e87 (hidden)
(empty) (no description set)
-- operation 4eb3252f7fd7 commit cb58ff1c6f1af92f827661e7275941ceb4d910c5
[EOF]
");
work_dir.run_jj(["op", "restore", &setup_opid]).success();
let output = work_dir.run_jj([
"squash",
"-f",
"kkmpptxzrspx::zsuskulnrvyr",
"--insert-before",
"qpvuntsmwlqt",
"--use-destination-message",
]);
insta::assert_snapshot!(output, @"
------- stderr -------
Created new commit soqnvnyz bf2d3b81 (no description set)
Rebased 3 descendant commits
Working copy (@) now at: mzvwutvl 9ebad59e (empty) (no description set)
Parent commit (@-) : rlvkpnrz 0c770834 bm2 bm3 bm4 | file2
[EOF]
");
insta::assert_snapshot!(get_log_with_summary(&work_dir), @"
@ mzvwutvlkqwt
â—‹ rlvkpnrzqnoo bm2 bm3 bm4 file2
│ A file2
â—‹ qpvuntsmwlqt bm1 file1
│ A file1
â—‹ soqnvnyzoxuuA file3
│ A file4
â—† zzzzzzzzzzzz
[EOF]
");
work_dir.run_jj(["op", "restore", &setup_opid]).success();
let output = work_dir.run_jj([
"squash",
"-f",
"none()",
"--insert-before",
"qpvuntsmwlqt",
"--use-destination-message",
]);
insta::assert_snapshot!(output, @"
------- stderr -------
Created new commit nsrwusvy c2183685 (empty) (no description set)
Rebased 5 descendant commits
Working copy (@) now at: mzvwutvl cb96ecf9 (empty) (no description set)
Parent commit (@-) : zsuskuln 97edce13 bm4 | file4
[EOF]
");
insta::assert_snapshot!(get_log_with_summary(&work_dir), @"
@ mzvwutvlkqwt
â—‹ zsuskulnrvyr bm4 file4
│ A file4
â—‹ kkmpptxzrspx bm3 file3
│ A file3
â—‹ rlvkpnrzqnoo bm2 file2
│ A file2
â—‹ qpvuntsmwlqt bm1 file1
│ A file1
â—‹ nsrwusvynpoy
â—† zzzzzzzzzzzz
[EOF]
");
let output = work_dir.run_jj(["evolog", "-r", "nsrwusvynpoy"]);
insta::assert_snapshot!(output, @"
â—‹ nsrwusvy test.user@example.com 2001-02-03 08:05:42 c2183685
(empty) (no description set)
-- operation 29b5af212226 squash 0 commits
[EOF]
");
work_dir.run_jj(["op", "restore", &setup_opid]).success();
let output = work_dir.run_jj([
"squash",
"-f",
"kkmpptxzrspx::zsuskulnrvyr",
"--insert-before",
"qpvuntsmwlqt",
"--use-destination-message",
"no file",
]);
insta::assert_snapshot!(output, @"
------- stderr -------
Warning: No matching entries for paths: no file
Created new commit wtlqussy 7eff41c8 (empty) (no description set)
Rebased 5 descendant commits
Working copy (@) now at: mzvwutvl cf8a98c4 (empty) (no description set)
Parent commit (@-) : zsuskuln 461e8bb9 bm4 | file4
[EOF]
");
insta::assert_snapshot!(get_log_with_summary(&work_dir), @"
@ mzvwutvlkqwt
â—‹ zsuskulnrvyr bm4 file4
│ A file4
â—‹ kkmpptxzrspx bm3 file3
│ A file3
â—‹ rlvkpnrzqnoo bm2 file2
│ A file2
â—‹ qpvuntsmwlqt bm1 file1
│ A file1
â—‹ wtlqussytxur
â—† zzzzzzzzzzzz
[EOF]
");
let output = work_dir.run_jj(["evolog", "-r", "wtlqussytxur"]);
insta::assert_snapshot!(output, @"
â—‹ wtlqussy test.user@example.com 2001-02-03 08:05:46 7eff41c8
(empty) (no description set)
-- operation f5c12bfd0cbc squash commit 0d254956d33ed5bb11d93eb795c5e514aadc81b5 and 1 more
[EOF]
");
work_dir.run_jj(["op", "restore", &setup_opid]).success();
let output = work_dir.run_jj(["new", "--no-edit", "root()"]);
insta::assert_snapshot!(output, @"
------- stderr -------
Created new commit szrrkvty f5e47d01 (empty) (no description set)
[EOF]
");
let output = work_dir.run_jj([
"squash",
"-f",
"szrrkvty",
"--onto",
"root()",
"--use-destination-message",
]);
insta::assert_snapshot!(output, @"
------- stderr -------
Created new commit pyoswmwk 991d0644 (empty) (no description set)
[EOF]
");
insta::assert_snapshot!(get_log_with_summary(&work_dir), @"
@ mzvwutvlkqwt
â—‹ zsuskulnrvyr bm4 file4
│ A file4
â—‹ kkmpptxzrspx bm3 file3
│ A file3
â—‹ rlvkpnrzqnoo bm2 file2
│ A file2
â—‹ qpvuntsmwlqt bm1 file1
│ A file1
│ ○ pyoswmwkkqyt
├─╯
â—† zzzzzzzzzzzz
[EOF]
");
let output = work_dir.run_jj(["evolog", "-r", "pyoswmwkkqyt"]);
insta::assert_snapshot!(output, @"
â—‹ pyoswmwk test.user@example.com 2001-02-03 08:05:50 991d0644
│ (empty) (no description set)
│ -- operation 587bcc3abdef squash commit f5e47d019271a392eb7f92a6b2e9f8cf41d97049
â—‹ szrrkvty/0 test.user@example.com 2001-02-03 08:05:50 f5e47d01 (hidden)
(empty) (no description set)
-- operation 4096cc584a23 new empty commit
[EOF]
");
work_dir.run_jj(["op", "restore", &setup_opid]).success();
let output = work_dir.run_jj([
"squash",
"-m",
"file 3&4",
"-f",
"kkmpptxzrspx::",
"--insert-after",
"root()",
"--insert-before",
"rlvkpnrzqnoo",
]);
insta::assert_snapshot!(output, @"
------- stderr -------
Created new commit vkywoywq 96673776 file 3&4
Rebased 1 descendant commits
Working copy (@) now at: rsmzzqvr e37e3e4a (empty) (no description set)
Parent commit (@-) : rlvkpnrz 8044909c bm2 bm3 bm4 | file2
[EOF]
");
insta::assert_snapshot!(get_log_with_summary(&work_dir), @"
@ rsmzzqvrnpvn
â—‹ rlvkpnrzqnoo bm2 bm3 bm4 file2
├─╮ A file2
│ ○ vkywoywqymtr file 3&4
│ │ A file3
│ │ A file4
○ │ qpvuntsmwlqt bm1 file1
├─╯ A file1
â—† zzzzzzzzzzzz
[EOF]
");
work_dir.run_jj(["op", "restore", &setup_opid]).success();
work_dir.run_jj(["edit", "bm3"]).success();
insta::assert_snapshot!(get_log_with_summary(&work_dir), @"
â—‹ zsuskulnrvyr bm4 file4
│ A file4
@ kkmpptxzrspx bm3 file3
│ A file3
â—‹ rlvkpnrzqnoo bm2 file2
│ A file2
â—‹ qpvuntsmwlqt bm1 file1
│ A file1
â—† zzzzzzzzzzzz
[EOF]
");
insta::assert_snapshot!(work_dir.run_jj(["squash", "--before", "rlvkpnrzqnoo"]), @"
------- stderr -------
Created new commit wxzmtyol bc0392dc file3
Rebased 2 descendant commits
Working copy (@) now at: musouqkq 1841cc81 (empty) (no description set)
Parent commit (@-) : rlvkpnrz 264a43af bm2 bm3 | file2
[EOF]
");
insta::assert_snapshot!(get_log_with_summary(&work_dir), @"
@ musouqkqsmll
│ ○ zsuskulnrvyr bm4 file4
├─╯ A file4
â—‹ rlvkpnrzqnoo bm2 bm3 file2
│ A file2
â—‹ wxzmtyollrwl file3
│ A file3
â—‹ qpvuntsmwlqt bm1 file1
│ A file1
â—† zzzzzzzzzzzz
[EOF]
");
Ok(())
}
#[test]
fn test_squash_with_editor_combine_messages() -> TestResult {
let mut test_env = TestEnvironment::default();
let edit_script = test_env.set_up_fake_editor();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
work_dir.run_jj(["describe", "-m", "destination"]).success();
work_dir.write_file("file1", "a\n");
work_dir.run_jj(["new", "-m", "source"]).success();
work_dir.write_file("file1", "b\n");
std::fs::write(
&edit_script,
["dump editor", "write\nfinal description from editor"].join("\0"),
)?;
work_dir.run_jj(["squash", "--editor"]).success();
let editor = std::fs::read_to_string(test_env.env_root().join("editor"))?;
insta::assert_snapshot!(
editor, @r#"
JJ: Enter a description for the combined commit.
JJ: Description from the destination commit:
destination
JJ: Description from source commit:
source
JJ: Change ID: qpvuntsm
JJ: This commit contains the following changes:
JJ: A file1
JJ:
JJ: Lines starting with "JJ:" (like this one) will be removed.
"#);
insta::assert_snapshot!(get_description(&work_dir, "@-"), @"
final description from editor
[EOF]
");
Ok(())
}
#[test]
fn test_squash_with_editor_and_message_args() -> TestResult {
let mut test_env = TestEnvironment::default();
let edit_script = test_env.set_up_fake_editor();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
work_dir.run_jj(["describe", "-m", "destination"]).success();
work_dir.write_file("file1", "a\n");
work_dir.run_jj(["new"]).success();
work_dir.write_file("file1", "b\n");
std::fs::write(&edit_script, "dump editor")?;
work_dir
.run_jj(["squash", "-m", "message from command line", "--editor"])
.success();
let editor = std::fs::read_to_string(test_env.env_root().join("editor"))?;
insta::assert_snapshot!(
editor, @r#"
message from command line
JJ: Change ID: qpvuntsm
JJ: This commit contains the following changes:
JJ: A file1
JJ:
JJ: Lines starting with "JJ:" (like this one) will be removed.
"#);
insta::assert_snapshot!(get_description(&work_dir, "@-"), @"
message from command line
[EOF]
");
Ok(())
}
#[test]
fn test_squash_with_editor_and_empty_message() -> TestResult {
let mut test_env = TestEnvironment::default();
let edit_script = test_env.set_up_fake_editor();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
work_dir.run_jj(["describe", "-m", "destination"]).success();
work_dir.write_file("file1", "a\n");
work_dir.run_jj(["new"]).success();
work_dir.write_file("file1", "b\n");
std::fs::write(&edit_script, "dump editor")?;
work_dir
.run_jj([
"squash",
"-m",
"",
"--editor",
"--config",
r#"templates.commit_trailers='"Trailer: value"'"#,
])
.success();
let editor = std::fs::read_to_string(test_env.env_root().join("editor"))?;
insta::assert_snapshot!(
editor, @r#"
Trailer: value
JJ: Change ID: qpvuntsm
JJ: This commit contains the following changes:
JJ: A file1
JJ:
JJ: Lines starting with "JJ:" (like this one) will be removed.
"#);
insta::assert_snapshot!(get_description(&work_dir, "@-"), @"
Trailer: value
[EOF]
");
Ok(())
}
#[must_use]
fn get_description(work_dir: &TestWorkDir, rev: &str) -> CommandOutput {
work_dir.run_jj(["log", "--no-graph", "-T", "description", "-r", rev])
}
#[must_use]
fn get_log_output_with_description(work_dir: &TestWorkDir) -> CommandOutput {
let template = r#"separate(" ", commit_id.short(), description)"#;
work_dir.run_jj(["log", "-T", template])
}
#[must_use]
fn get_log_with_summary(work_dir: &TestWorkDir) -> CommandOutput {
let template = r#"separate(" ", change_id.short(), local_bookmarks, description)"#;
work_dir.run_jj(["log", "-T", template, "--summary"])
}