// Copyright 2022 The Jujutsu Authors//// Licensed under the Apache License, Version 2.0 (the "License");// you may not use this file except in compliance with the License.// You may obtain a copy of the License at//// https://www.apache.org/licenses/LICENSE-2.0//// Unless required by applicable law or agreed to in writing, software// distributed under the License is distributed on an "AS IS" BASIS,// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.// See the License for the specific language governing permissions and// limitations under the License. use std::path::PathBuf; use indoc::indoc;use test_case::test_case;use testutils::TestResult; use crate::common::CommandOutput;use crate::common::TestEnvironment;use crate::common::TestWorkDir; #[must_use]fn get_log_output(work_dir: &TestWorkDir) -> CommandOutput { let template = r#"separate(" ", change_id.short(), empty, local_bookmarks, 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"])} #[must_use]fn get_workspace_log_output(work_dir: &TestWorkDir) -> CommandOutput { let template = r#"separate(" ", change_id.short(), working_copies, description)"#; work_dir.run_jj(["log", "-T", template, "-r", "all()"])} #[must_use]fn get_recorded_dates(work_dir: &TestWorkDir, revset: &str) -> CommandOutput { let template = r#"separate("\n", "Author date: " ++ author.timestamp(), "Committer date: " ++ committer.timestamp())"#; work_dir.run_jj(["log", "--no-graph", "-T", template, "-r", revset])} #[test]fn test_split_by_paths() -> 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", "foo"); work_dir.write_file("file2", "foo"); work_dir.write_file("file3", "foo"); insta::assert_snapshot!(get_log_output(&work_dir), @" @ qpvuntsmwlqt false ◆ zzzzzzzzzzzz true [EOF] "); insta::assert_snapshot!(get_recorded_dates(&work_dir, "@"), @" Author date: 2001-02-03 04:05:08.000 +07:00 Committer date: 2001-02-03 04:05:08.000 +07:00[EOF] "); let edit_instr = indoc! {" update-describe JJ: describe ************ ------- JJ: describe ************ ------- "}; std::fs::write(&edit_script, ["dump editor", edit_instr].join("\0"))?; let output = work_dir.run_jj([ "split", "file2", r#"--config=templates.commit_trailers='"Trailer: value"'"#, ]); insta::assert_snapshot!(output, @" ------- stderr ------- Selected changes : qpvuntsm 6dbc7747 (no description set) Remaining changes: zsuskuln 42cbbc02 (no description set) Working copy (@) now at: zsuskuln 42cbbc02 (no description set) Parent commit (@-) : qpvuntsm 6dbc7747 (no description set) [EOF] "); // Trailers should be added to the editor template insta::assert_snapshot!( std::fs::read_to_string(test_env.env_root().join("editor"))?, @r#" JJ: Enter or edit commit descriptions after the `JJ: describe` lines. JJ: Warning: JJ: - The text you enter will be lost on a syntax error. JJ: - The syntax of the separator lines may change in the future. JJ: JJ: describe 75d98a03733d ------- JJ: Enter a description for the selected changes. Trailer: value JJ: Change ID: qpvuntsm JJ: This commit contains the following changes: JJ: A file2 JJ: JJ: describe 12afeee3a9cc ------- JJ: Enter a description for the remaining changes. Trailer: value JJ: Change ID: zsuskuln JJ: This commit contains the following changes: JJ: A file1 JJ: A file3 JJ: JJ: Lines starting with "JJ:" (like this one) will be removed. "#); insta::assert_snapshot!(get_log_output(&work_dir), @" @ zsuskulnrvyr false ○ qpvuntsmwlqt false ◆ zzzzzzzzzzzz true [EOF] "); // The author dates of the new commits should be inherited from the commit being // split. The committer dates should be newer. insta::assert_snapshot!(get_recorded_dates(&work_dir, "@"), @" Author date: 2001-02-03 04:05:08.000 +07:00 Committer date: 2001-02-03 04:05:10.000 +07:00[EOF] "); insta::assert_snapshot!(get_recorded_dates(&work_dir, "@-"), @" Author date: 2001-02-03 04:05:08.000 +07:00 Committer date: 2001-02-03 04:05:10.000 +07:00[EOF] "); let output = work_dir.run_jj(["diff", "-s", "-r", "@-"]); insta::assert_snapshot!(output, @" A file2 [EOF] "); let output = work_dir.run_jj(["diff", "-s"]); insta::assert_snapshot!(output, @" A file1 A file3 [EOF] "); // Insert an empty commit after @- with "split ." std::fs::write(&edit_script, "")?; let output = work_dir.run_jj(["split", "-r", "@-", "."]); insta::assert_snapshot!(output, @" ------- stderr ------- Warning: All changes have been selected, so the original revision will become empty. Rebased 1 descendant commits. Selected changes : qpvuntsm 9fd1c9e1 (no description set) Remaining changes: znkkpsqq 41e0da21 (empty) (no description set) Working copy (@) now at: zsuskuln a06e40b8 (no description set) Parent commit (@-) : znkkpsqq 41e0da21 (empty) (no description set) [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @" @ zsuskulnrvyr false ○ znkkpsqqskkl true ○ qpvuntsmwlqt false ◆ zzzzzzzzzzzz true [EOF] "); let output = work_dir.run_jj(["diff", "-s", "-r", "@--"]); insta::assert_snapshot!(output, @" A file2 [EOF] "); // Remove newly created empty commit work_dir.run_jj(["abandon", "@-"]).success(); // Insert an empty commit before @- with "split nonexistent" std::fs::write(&edit_script, "")?; let output = work_dir.run_jj(["split", "-r", "@-", "nonexistent"]); insta::assert_snapshot!(output, @" ------- stderr ------- Warning: No matching entries for paths: nonexistent Warning: No changes have been selected, so the new revision will be empty. Rebased 1 descendant commits. Selected changes : qpvuntsm 49416632 (empty) (no description set) Remaining changes: lylxulpl 718afbf5 (no description set) Working copy (@) now at: zsuskuln 0ed53ee6 (no description set) Parent commit (@-) : lylxulpl 718afbf5 (no description set) [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @" @ zsuskulnrvyr false ○ lylxulplsnyw false ○ qpvuntsmwlqt true ◆ zzzzzzzzzzzz true [EOF] "); let output = work_dir.run_jj(["diff", "-s", "-r", "@-"]); insta::assert_snapshot!(output, @" A file2 [EOF] "); work_dir.run_jj(["new"]).success(); // Splitting a commit with deleted files should not show a warning. work_dir.remove_file("file1"); let output = work_dir.run_jj(["split", "file1"]); insta::assert_snapshot!(output, @" ------- stderr ------- Warning: All changes have been selected, so the original revision will become empty. Selected changes : uyznsvlq 971ccc0b (no description set) Remaining changes: xznxytkn a267cd96 (empty) (no description set) Working copy (@) now at: smwtzssm 6715dc2c (empty) (no description set) Parent commit (@-) : uyznsvlq 971ccc0b (no description set) [EOF] "); Ok(())} #[test]fn test_split_with_non_empty_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(); test_env.add_config(r#"template-aliases.default_commit_description = '"\n\nTESTED=TODO\n"'"#); let work_dir = test_env.work_dir("repo"); work_dir.write_file("file1", "foo\n"); work_dir.write_file("file2", "bar\n"); work_dir.run_jj(["describe", "-m", "test"]).success(); let edit_instr = indoc! {" update-describe JJ: describe ************ ------- part 1 JJ: describe ************ ------- part 2 "}; std::fs::write(edit_script, ["dump editor", edit_instr].join("\0"))?; let output = work_dir.run_jj(["split", "file1"]); insta::assert_snapshot!(output, @" ------- stderr ------- Selected changes : qpvuntsm c7f7b14b part 1 Remaining changes: kkmpptxz ac33a5a9 part 2 Working copy (@) now at: kkmpptxz ac33a5a9 part 2 Parent commit (@-) : qpvuntsm c7f7b14b part 1 [EOF] "); insta::assert_snapshot!( std::fs::read_to_string(test_env.env_root().join("editor"))?, @r#" JJ: Enter or edit commit descriptions after the `JJ: describe` lines. JJ: Warning: JJ: - The text you enter will be lost on a syntax error. JJ: - The syntax of the separator lines may change in the future. JJ: JJ: describe 2671a19fa813 ------- JJ: Enter a description for the selected changes. test JJ: Change ID: qpvuntsm JJ: This commit contains the following changes: JJ: A file1 JJ: JJ: describe 6a758f874bda ------- JJ: Enter a description for the remaining changes. test JJ: Change ID: kkmpptxz JJ: This commit contains the following changes: JJ: A file2 JJ: JJ: Lines starting with "JJ:" (like this one) will be removed. "#); insta::assert_snapshot!(get_log_output(&work_dir), @" @ kkmpptxzrspx false part 2 ○ qpvuntsmwlqt false part 1 ◆ zzzzzzzzzzzz true [EOF] "); Ok(())} #[test]fn test_split_with_default_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(); test_env.add_config(r#"template-aliases.default_commit_description = '"\n\nTESTED=TODO\n"'"#); let work_dir = test_env.work_dir("repo"); work_dir.write_file("file1", "foo\n"); work_dir.write_file("file2", "bar\n"); std::fs::write(edit_script, ["dump editor"].join("\0"))?; let output = work_dir.run_jj(["split", "file1"]); insta::assert_snapshot!(output, @" ------- stderr ------- Selected changes : qpvuntsm ff633dcc TESTED=TODO Remaining changes: rlvkpnrz af8463e1 TESTED=TODO Working copy (@) now at: rlvkpnrz af8463e1 TESTED=TODO Parent commit (@-) : qpvuntsm ff633dcc TESTED=TODO [EOF] "); // Since the commit being split has no description, the user will be // prompted to add a description. Both the first and second commits will use // the default value we set. insta::assert_snapshot!( std::fs::read_to_string(test_env.env_root().join("editor"))?, @r#" JJ: Enter or edit commit descriptions after the `JJ: describe` lines. JJ: Warning: JJ: - The text you enter will be lost on a syntax error. JJ: - The syntax of the separator lines may change in the future. JJ: JJ: describe c664a51bff8c ------- JJ: Enter a description for the selected changes. TESTED=TODO JJ: Change ID: qpvuntsm JJ: This commit contains the following changes: JJ: A file1 JJ: JJ: describe 7e5d65b1755b ------- JJ: Enter a description for the remaining changes. TESTED=TODO JJ: Change ID: rlvkpnrz JJ: This commit contains the following changes: JJ: A file2 JJ: JJ: Lines starting with "JJ:" (like this one) will be removed. "#); insta::assert_snapshot!(get_log_output(&work_dir), @" @ rlvkpnrzqnoo false TESTED=TODO ○ qpvuntsmwlqt false TESTED=TODO ◆ zzzzzzzzzzzz true [EOF] "); Ok(())} #[test]fn test_split_with_descendants() -> TestResult { // Configure the environment and make the initial commits. 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"); // First commit. This is the one we will split later. work_dir.write_file("file1", "foo\n"); work_dir.write_file("file2", "bar\n"); work_dir .run_jj(["commit", "-m", "Add file1 & file2"]) .success(); // Second commit. work_dir.write_file("file3", "baz\n"); work_dir.run_jj(["commit", "-m", "Add file3"]).success(); // Third commit. work_dir.write_file("file4", "foobarbaz\n"); work_dir.run_jj(["describe", "-m", "Add file4"]).success(); insta::assert_snapshot!(get_log_output(&work_dir), @" @ kkmpptxzrspx false Add file4 ○ rlvkpnrzqnoo false Add file3 ○ qpvuntsmwlqt false Add file1 & file2 ◆ zzzzzzzzzzzz true [EOF] "); // Set up the editor and do the split. let edit_instr = indoc! {" update-describe JJ: describe ************ ------- Add file1 JJ: describe ************ ------- Add file2 "}; std::fs::write(edit_script, ["dump editor", edit_instr].join("\0"))?; let output = work_dir.run_jj(["split", "file1", "-r", "qpvu"]); insta::assert_snapshot!(output, @" ------- stderr ------- Rebased 2 descendant commits. Selected changes : qpvuntsm 74306e35 Add file1 Remaining changes: royxmykx 0a37745e Add file2 Working copy (@) now at: kkmpptxz 7ee84812 Add file4 Parent commit (@-) : rlvkpnrz d335bd94 Add file3 [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @" @ kkmpptxzrspx false Add file4 ○ rlvkpnrzqnoo false Add file3 ○ royxmykxtrkr false Add file2 ○ qpvuntsmwlqt false Add file1 ◆ zzzzzzzzzzzz true [EOF] "); // The commit we're splitting has a description, so the user will be // prompted to enter a description for each of the commits. insta::assert_snapshot!( std::fs::read_to_string(test_env.env_root().join("editor"))?, @r#" JJ: Enter or edit commit descriptions after the `JJ: describe` lines. JJ: Warning: JJ: - The text you enter will be lost on a syntax error. JJ: - The syntax of the separator lines may change in the future. JJ: JJ: describe 96d63cfea6ac ------- JJ: Enter a description for the selected changes. Add file1 & file2 JJ: Change ID: qpvuntsm JJ: This commit contains the following changes: JJ: A file1 JJ: JJ: describe 564fe2e7f813 ------- JJ: Enter a description for the remaining changes. Add file1 & file2 JJ: Change ID: royxmykx JJ: This commit contains the following changes: JJ: A file2 JJ: JJ: Lines starting with "JJ:" (like this one) will be removed. "#); // Check the evolog for the first commit. It shows four entries: // - The initial empty commit. // - The rewritten commit from the snapshot after the files were added. // - The rewritten commit once the description is added during `jj commit`. // - The rewritten commit after the split. let evolog_1 = work_dir.run_jj(["evolog", "-r", "qpvun"]); insta::assert_snapshot!(evolog_1, @" ○ qpvuntsm test.user@example.com 2001-02-03 08:05:12 74306e35 │ Add file1 │ -- operation 8da478b86b17 split commit 1d2499e72cefc8a2b87ebb47569140857b96189f ○ qpvuntsm/1 test.user@example.com 2001-02-03 08:05:08 1d2499e7 (hidden) │ Add file1 & file2 │ -- operation 8f1bd50aa0bd commit f5700f8ef89e290e4e90ae6adc0908707e0d8c85 ○ qpvuntsm/2 test.user@example.com 2001-02-03 08:05:08 f5700f8e (hidden) │ (no description set) │ -- operation f470eed642a6 snapshot working copy ○ qpvuntsm/3 test.user@example.com 2001-02-03 08:05:07 e8849ae1 (hidden) (empty) (no description set) -- operation f63ee16f9553 add workspace 'default' [EOF] "); // The evolog for the second commit is the same, except that the change id // changes after the split. let evolog_2 = work_dir.run_jj(["evolog", "-r", "royxm"]); insta::assert_snapshot!(evolog_2, @" ○ royxmykx test.user@example.com 2001-02-03 08:05:12 0a37745e │ Add file2 │ -- operation 8da478b86b17 split commit 1d2499e72cefc8a2b87ebb47569140857b96189f ○ qpvuntsm/1 test.user@example.com 2001-02-03 08:05:08 1d2499e7 (hidden) │ Add file1 & file2 │ -- operation 8f1bd50aa0bd commit f5700f8ef89e290e4e90ae6adc0908707e0d8c85 ○ qpvuntsm/2 test.user@example.com 2001-02-03 08:05:08 f5700f8e (hidden) │ (no description set) │ -- operation f470eed642a6 snapshot working copy ○ qpvuntsm/3 test.user@example.com 2001-02-03 08:05:07 e8849ae1 (hidden) (empty) (no description set) -- operation f63ee16f9553 add workspace 'default' [EOF] "); Ok(())} // This test makes sure that the children of the commit being split retain any// other parents which weren't involved in the split.#[test]fn test_split_with_merge_child() -> 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=1"]).success(); work_dir.run_jj(["new", "root()", "-m=a"]).success(); work_dir.write_file("file1", "foo\n"); work_dir.write_file("file2", "bar\n"); work_dir .run_jj(["new", "subject(1)", "subject(a)", "-m=2"]) .success(); insta::assert_snapshot!(get_log_output(&work_dir), @" @ zsuskulnrvyr true 2 ├─╮ │ ○ kkmpptxzrspx false a ○ │ qpvuntsmwlqt true 1 ├─╯Lines 1–500 of 1957. Load more
// Copyright 2022 The Jujutsu Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // https://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. use std::path::PathBuf; use indoc::indoc; use test_case::test_case; use testutils::TestResult; use crate::common::CommandOutput; use crate::common::TestEnvironment; use crate::common::TestWorkDir; #[must_use] fn get_log_output(work_dir: &TestWorkDir) -> CommandOutput { let template = r#"separate(" ", change_id.short(), empty, local_bookmarks, 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"]) } #[must_use] fn get_workspace_log_output(work_dir: &TestWorkDir) -> CommandOutput { let template = r#"separate(" ", change_id.short(), working_copies, description)"#; work_dir.run_jj(["log", "-T", template, "-r", "all()"]) } #[must_use] fn get_recorded_dates(work_dir: &TestWorkDir, revset: &str) -> CommandOutput { let template = r#"separate("\n", "Author date: " ++ author.timestamp(), "Committer date: " ++ committer.timestamp())"#; work_dir.run_jj(["log", "--no-graph", "-T", template, "-r", revset]) } #[test] fn test_split_by_paths() -> 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", "foo"); work_dir.write_file("file2", "foo"); work_dir.write_file("file3", "foo"); insta::assert_snapshot!(get_log_output(&work_dir), @" @ qpvuntsmwlqt false ◆ zzzzzzzzzzzz true [EOF] "); insta::assert_snapshot!(get_recorded_dates(&work_dir, "@"), @" Author date: 2001-02-03 04:05:08.000 +07:00 Committer date: 2001-02-03 04:05:08.000 +07:00[EOF] "); let edit_instr = indoc! {" update-describe JJ: describe ************ ------- JJ: describe ************ ------- "}; std::fs::write(&edit_script, ["dump editor", edit_instr].join("\0"))?; let output = work_dir.run_jj([ "split", "file2", r#"--config=templates.commit_trailers='"Trailer: value"'"#, ]); insta::assert_snapshot!(output, @" ------- stderr ------- Selected changes : qpvuntsm 6dbc7747 (no description set) Remaining changes: zsuskuln 42cbbc02 (no description set) Working copy (@) now at: zsuskuln 42cbbc02 (no description set) Parent commit (@-) : qpvuntsm 6dbc7747 (no description set) [EOF] "); // Trailers should be added to the editor template insta::assert_snapshot!( std::fs::read_to_string(test_env.env_root().join("editor"))?, @r#" JJ: Enter or edit commit descriptions after the `JJ: describe` lines. JJ: Warning: JJ: - The text you enter will be lost on a syntax error. JJ: - The syntax of the separator lines may change in the future. JJ: JJ: describe 75d98a03733d ------- JJ: Enter a description for the selected changes. Trailer: value JJ: Change ID: qpvuntsm JJ: This commit contains the following changes: JJ: A file2 JJ: JJ: describe 12afeee3a9cc ------- JJ: Enter a description for the remaining changes. Trailer: value JJ: Change ID: zsuskuln JJ: This commit contains the following changes: JJ: A file1 JJ: A file3 JJ: JJ: Lines starting with "JJ:" (like this one) will be removed. "#); insta::assert_snapshot!(get_log_output(&work_dir), @" @ zsuskulnrvyr false ○ qpvuntsmwlqt false ◆ zzzzzzzzzzzz true [EOF] "); // The author dates of the new commits should be inherited from the commit being // split. The committer dates should be newer. insta::assert_snapshot!(get_recorded_dates(&work_dir, "@"), @" Author date: 2001-02-03 04:05:08.000 +07:00 Committer date: 2001-02-03 04:05:10.000 +07:00[EOF] "); insta::assert_snapshot!(get_recorded_dates(&work_dir, "@-"), @" Author date: 2001-02-03 04:05:08.000 +07:00 Committer date: 2001-02-03 04:05:10.000 +07:00[EOF] "); let output = work_dir.run_jj(["diff", "-s", "-r", "@-"]); insta::assert_snapshot!(output, @" A file2 [EOF] "); let output = work_dir.run_jj(["diff", "-s"]); insta::assert_snapshot!(output, @" A file1 A file3 [EOF] "); // Insert an empty commit after @- with "split ." std::fs::write(&edit_script, "")?; let output = work_dir.run_jj(["split", "-r", "@-", "."]); insta::assert_snapshot!(output, @" ------- stderr ------- Warning: All changes have been selected, so the original revision will become empty. Rebased 1 descendant commits. Selected changes : qpvuntsm 9fd1c9e1 (no description set) Remaining changes: znkkpsqq 41e0da21 (empty) (no description set) Working copy (@) now at: zsuskuln a06e40b8 (no description set) Parent commit (@-) : znkkpsqq 41e0da21 (empty) (no description set) [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @" @ zsuskulnrvyr false ○ znkkpsqqskkl true ○ qpvuntsmwlqt false ◆ zzzzzzzzzzzz true [EOF] "); let output = work_dir.run_jj(["diff", "-s", "-r", "@--"]); insta::assert_snapshot!(output, @" A file2 [EOF] "); // Remove newly created empty commit work_dir.run_jj(["abandon", "@-"]).success(); // Insert an empty commit before @- with "split nonexistent" std::fs::write(&edit_script, "")?; let output = work_dir.run_jj(["split", "-r", "@-", "nonexistent"]); insta::assert_snapshot!(output, @" ------- stderr ------- Warning: No matching entries for paths: nonexistent Warning: No changes have been selected, so the new revision will be empty. Rebased 1 descendant commits. Selected changes : qpvuntsm 49416632 (empty) (no description set) Remaining changes: lylxulpl 718afbf5 (no description set) Working copy (@) now at: zsuskuln 0ed53ee6 (no description set) Parent commit (@-) : lylxulpl 718afbf5 (no description set) [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @" @ zsuskulnrvyr false ○ lylxulplsnyw false ○ qpvuntsmwlqt true ◆ zzzzzzzzzzzz true [EOF] "); let output = work_dir.run_jj(["diff", "-s", "-r", "@-"]); insta::assert_snapshot!(output, @" A file2 [EOF] "); work_dir.run_jj(["new"]).success(); // Splitting a commit with deleted files should not show a warning. work_dir.remove_file("file1"); let output = work_dir.run_jj(["split", "file1"]); insta::assert_snapshot!(output, @" ------- stderr ------- Warning: All changes have been selected, so the original revision will become empty. Selected changes : uyznsvlq 971ccc0b (no description set) Remaining changes: xznxytkn a267cd96 (empty) (no description set) Working copy (@) now at: smwtzssm 6715dc2c (empty) (no description set) Parent commit (@-) : uyznsvlq 971ccc0b (no description set) [EOF] "); Ok(()) } #[test] fn test_split_with_non_empty_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(); test_env.add_config(r#"template-aliases.default_commit_description = '"\n\nTESTED=TODO\n"'"#); let work_dir = test_env.work_dir("repo"); work_dir.write_file("file1", "foo\n"); work_dir.write_file("file2", "bar\n"); work_dir.run_jj(["describe", "-m", "test"]).success(); let edit_instr = indoc! {" update-describe JJ: describe ************ ------- part 1 JJ: describe ************ ------- part 2 "}; std::fs::write(edit_script, ["dump editor", edit_instr].join("\0"))?; let output = work_dir.run_jj(["split", "file1"]); insta::assert_snapshot!(output, @" ------- stderr ------- Selected changes : qpvuntsm c7f7b14b part 1 Remaining changes: kkmpptxz ac33a5a9 part 2 Working copy (@) now at: kkmpptxz ac33a5a9 part 2 Parent commit (@-) : qpvuntsm c7f7b14b part 1 [EOF] "); insta::assert_snapshot!( std::fs::read_to_string(test_env.env_root().join("editor"))?, @r#" JJ: Enter or edit commit descriptions after the `JJ: describe` lines. JJ: Warning: JJ: - The text you enter will be lost on a syntax error. JJ: - The syntax of the separator lines may change in the future. JJ: JJ: describe 2671a19fa813 ------- JJ: Enter a description for the selected changes. test JJ: Change ID: qpvuntsm JJ: This commit contains the following changes: JJ: A file1 JJ: JJ: describe 6a758f874bda ------- JJ: Enter a description for the remaining changes. test JJ: Change ID: kkmpptxz JJ: This commit contains the following changes: JJ: A file2 JJ: JJ: Lines starting with "JJ:" (like this one) will be removed. "#); insta::assert_snapshot!(get_log_output(&work_dir), @" @ kkmpptxzrspx false part 2 ○ qpvuntsmwlqt false part 1 ◆ zzzzzzzzzzzz true [EOF] "); Ok(()) } #[test] fn test_split_with_default_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(); test_env.add_config(r#"template-aliases.default_commit_description = '"\n\nTESTED=TODO\n"'"#); let work_dir = test_env.work_dir("repo"); work_dir.write_file("file1", "foo\n"); work_dir.write_file("file2", "bar\n"); std::fs::write(edit_script, ["dump editor"].join("\0"))?; let output = work_dir.run_jj(["split", "file1"]); insta::assert_snapshot!(output, @" ------- stderr ------- Selected changes : qpvuntsm ff633dcc TESTED=TODO Remaining changes: rlvkpnrz af8463e1 TESTED=TODO Working copy (@) now at: rlvkpnrz af8463e1 TESTED=TODO Parent commit (@-) : qpvuntsm ff633dcc TESTED=TODO [EOF] "); // Since the commit being split has no description, the user will be // prompted to add a description. Both the first and second commits will use // the default value we set. insta::assert_snapshot!( std::fs::read_to_string(test_env.env_root().join("editor"))?, @r#" JJ: Enter or edit commit descriptions after the `JJ: describe` lines. JJ: Warning: JJ: - The text you enter will be lost on a syntax error. JJ: - The syntax of the separator lines may change in the future. JJ: JJ: describe c664a51bff8c ------- JJ: Enter a description for the selected changes. TESTED=TODO JJ: Change ID: qpvuntsm JJ: This commit contains the following changes: JJ: A file1 JJ: JJ: describe 7e5d65b1755b ------- JJ: Enter a description for the remaining changes. TESTED=TODO JJ: Change ID: rlvkpnrz JJ: This commit contains the following changes: JJ: A file2 JJ: JJ: Lines starting with "JJ:" (like this one) will be removed. "#); insta::assert_snapshot!(get_log_output(&work_dir), @" @ rlvkpnrzqnoo false TESTED=TODO ○ qpvuntsmwlqt false TESTED=TODO ◆ zzzzzzzzzzzz true [EOF] "); Ok(()) } #[test] fn test_split_with_descendants() -> TestResult { // Configure the environment and make the initial commits. 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"); // First commit. This is the one we will split later. work_dir.write_file("file1", "foo\n"); work_dir.write_file("file2", "bar\n"); work_dir .run_jj(["commit", "-m", "Add file1 & file2"]) .success(); // Second commit. work_dir.write_file("file3", "baz\n"); work_dir.run_jj(["commit", "-m", "Add file3"]).success(); // Third commit. work_dir.write_file("file4", "foobarbaz\n"); work_dir.run_jj(["describe", "-m", "Add file4"]).success(); insta::assert_snapshot!(get_log_output(&work_dir), @" @ kkmpptxzrspx false Add file4 ○ rlvkpnrzqnoo false Add file3 ○ qpvuntsmwlqt false Add file1 & file2 ◆ zzzzzzzzzzzz true [EOF] "); // Set up the editor and do the split. let edit_instr = indoc! {" update-describe JJ: describe ************ ------- Add file1 JJ: describe ************ ------- Add file2 "}; std::fs::write(edit_script, ["dump editor", edit_instr].join("\0"))?; let output = work_dir.run_jj(["split", "file1", "-r", "qpvu"]); insta::assert_snapshot!(output, @" ------- stderr ------- Rebased 2 descendant commits. Selected changes : qpvuntsm 74306e35 Add file1 Remaining changes: royxmykx 0a37745e Add file2 Working copy (@) now at: kkmpptxz 7ee84812 Add file4 Parent commit (@-) : rlvkpnrz d335bd94 Add file3 [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @" @ kkmpptxzrspx false Add file4 ○ rlvkpnrzqnoo false Add file3 ○ royxmykxtrkr false Add file2 ○ qpvuntsmwlqt false Add file1 ◆ zzzzzzzzzzzz true [EOF] "); // The commit we're splitting has a description, so the user will be // prompted to enter a description for each of the commits. insta::assert_snapshot!( std::fs::read_to_string(test_env.env_root().join("editor"))?, @r#" JJ: Enter or edit commit descriptions after the `JJ: describe` lines. JJ: Warning: JJ: - The text you enter will be lost on a syntax error. JJ: - The syntax of the separator lines may change in the future. JJ: JJ: describe 96d63cfea6ac ------- JJ: Enter a description for the selected changes. Add file1 & file2 JJ: Change ID: qpvuntsm JJ: This commit contains the following changes: JJ: A file1 JJ: JJ: describe 564fe2e7f813 ------- JJ: Enter a description for the remaining changes. Add file1 & file2 JJ: Change ID: royxmykx JJ: This commit contains the following changes: JJ: A file2 JJ: JJ: Lines starting with "JJ:" (like this one) will be removed. "#); // Check the evolog for the first commit. It shows four entries: // - The initial empty commit. // - The rewritten commit from the snapshot after the files were added. // - The rewritten commit once the description is added during `jj commit`. // - The rewritten commit after the split. let evolog_1 = work_dir.run_jj(["evolog", "-r", "qpvun"]); insta::assert_snapshot!(evolog_1, @" ○ qpvuntsm test.user@example.com 2001-02-03 08:05:12 74306e35 │ Add file1 │ -- operation 8da478b86b17 split commit 1d2499e72cefc8a2b87ebb47569140857b96189f ○ qpvuntsm/1 test.user@example.com 2001-02-03 08:05:08 1d2499e7 (hidden) │ Add file1 & file2 │ -- operation 8f1bd50aa0bd commit f5700f8ef89e290e4e90ae6adc0908707e0d8c85 ○ qpvuntsm/2 test.user@example.com 2001-02-03 08:05:08 f5700f8e (hidden) │ (no description set) │ -- operation f470eed642a6 snapshot working copy ○ qpvuntsm/3 test.user@example.com 2001-02-03 08:05:07 e8849ae1 (hidden) (empty) (no description set) -- operation f63ee16f9553 add workspace 'default' [EOF] "); // The evolog for the second commit is the same, except that the change id // changes after the split. let evolog_2 = work_dir.run_jj(["evolog", "-r", "royxm"]); insta::assert_snapshot!(evolog_2, @" ○ royxmykx test.user@example.com 2001-02-03 08:05:12 0a37745e │ Add file2 │ -- operation 8da478b86b17 split commit 1d2499e72cefc8a2b87ebb47569140857b96189f ○ qpvuntsm/1 test.user@example.com 2001-02-03 08:05:08 1d2499e7 (hidden) │ Add file1 & file2 │ -- operation 8f1bd50aa0bd commit f5700f8ef89e290e4e90ae6adc0908707e0d8c85 ○ qpvuntsm/2 test.user@example.com 2001-02-03 08:05:08 f5700f8e (hidden) │ (no description set) │ -- operation f470eed642a6 snapshot working copy ○ qpvuntsm/3 test.user@example.com 2001-02-03 08:05:07 e8849ae1 (hidden) (empty) (no description set) -- operation f63ee16f9553 add workspace 'default' [EOF] "); Ok(()) } // This test makes sure that the children of the commit being split retain any // other parents which weren't involved in the split. #[test] fn test_split_with_merge_child() -> 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=1"]).success(); work_dir.run_jj(["new", "root()", "-m=a"]).success(); work_dir.write_file("file1", "foo\n"); work_dir.write_file("file2", "bar\n"); work_dir .run_jj(["new", "subject(1)", "subject(a)", "-m=2"]) .success(); insta::assert_snapshot!(get_log_output(&work_dir), @" @ zsuskulnrvyr true 2 ├─╮ │ ○ kkmpptxzrspx false a ○ │ qpvuntsmwlqt true 1 ├─╯