// 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 test_case::test_case; 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() { 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), @r" @ qpvuntsmwlqt false ◆ zzzzzzzzzzzz true [EOF] "); insta::assert_snapshot!(get_recorded_dates(&work_dir, "@"), @r" Author date: 2001-02-03 04:05:08.000 +07:00 Committer date: 2001-02-03 04:05:08.000 +07:00[EOF] "); std::fs::write( &edit_script, ["dump editor0", "next invocation\n", "dump editor1"].join("\0"), ) .unwrap(); let output = work_dir.run_jj(["split", "file2"]); insta::assert_snapshot!(output, @r" ------- 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] "); insta::assert_snapshot!( std::fs::read_to_string(test_env.env_root().join("editor0")).unwrap(), @r#" JJ: Enter a description for the selected changes. JJ: This commit contains the following changes: JJ: A file2 JJ: JJ: Lines starting with "JJ:" (like this one) will be removed. "#); assert!(!test_env.env_root().join("editor1").exists()); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 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, "@"), @r" 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, "@-"), @r" 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, @r" A file2 [EOF] "); let output = work_dir.run_jj(["diff", "-s"]); insta::assert_snapshot!(output, @r" A file1 A file3 [EOF] "); // Insert an empty commit after @- with "split ." std::fs::write(&edit_script, "").unwrap(); let output = work_dir.run_jj(["split", "-r", "@-", "."]); insta::assert_snapshot!(output, @r" ------- 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), @r" @ zsuskulnrvyr false ○ znkkpsqqskkl true ○ qpvuntsmwlqt false ◆ zzzzzzzzzzzz true [EOF] "); let output = work_dir.run_jj(["diff", "-s", "-r", "@--"]); insta::assert_snapshot!(output, @r" 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, "").unwrap(); let output = work_dir.run_jj(["split", "-r", "@-", "nonexistent"]); insta::assert_snapshot!(output, @r" ------- stderr ------- 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), @r" @ zsuskulnrvyr false ○ lylxulplsnyw false ○ qpvuntsmwlqt true ◆ zzzzzzzzzzzz true [EOF] "); let output = work_dir.run_jj(["diff", "-s", "-r", "@-"]); insta::assert_snapshot!(output, @r" A file2 [EOF] ");} #[test]fn test_split_with_non_empty_description() { 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#"ui.default-description = "\n\nTESTED=TODO""#); 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(); std::fs::write( edit_script, [ "dump editor1", "write\npart 1", "next invocation\n", "dump editor2", "write\npart 2", ] .join("\0"), ) .unwrap(); let output = work_dir.run_jj(["split", "file1"]); insta::assert_snapshot!(output, @r#" ------- stderr ------- Warning: Deprecated user-level config: ui.default-description is updated to template-aliases.default_commit_description = '"\n\nTESTED=TODO\n"' 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("editor1")).unwrap(), @r#" JJ: Enter a description for the selected changes. test 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!( std::fs::read_to_string(test_env.env_root().join("editor2")).unwrap(), @r#" JJ: Enter a description for the remaining changes. test 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), @r#" @ kkmpptxzrspx false part 2 ○ qpvuntsmwlqt false part 1 ◆ zzzzzzzzzzzz true [EOF] ------- stderr ------- Warning: Deprecated user-level config: ui.default-description is updated to template-aliases.default_commit_description = '"\n\nTESTED=TODO\n"' [EOF] "#);} #[test]fn test_split_with_default_description() { 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#"ui.default-description = "\n\nTESTED=TODO""#); 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 editor1", "next invocation\n", "dump editor2"].join("\0"), ) .unwrap(); let output = work_dir.run_jj(["split", "file1"]); insta::assert_snapshot!(output, @r#" ------- stderr ------- Warning: Deprecated user-level config: ui.default-description is updated to template-aliases.default_commit_description = '"\n\nTESTED=TODO\n"' Selected changes : qpvuntsm ff633dcc TESTED=TODO Remaining changes: rlvkpnrz b1d20b7e (no description set) Working copy (@) now at: rlvkpnrz b1d20b7e (no description set) Parent commit (@-) : qpvuntsm ff633dcc TESTED=TODO [EOF] "#); // Since the commit being split has no description, the user will only be // prompted to add a description to the first commit, which will use the // default value we set. The second commit will inherit the empty // description from the commit being split. insta::assert_snapshot!( std::fs::read_to_string(test_env.env_root().join("editor1")).unwrap(), @r#" JJ: Enter a description for the selected changes. TESTED=TODO JJ: This commit contains the following changes: JJ: A file1 JJ: JJ: Lines starting with "JJ:" (like this one) will be removed. "#); assert!(!test_env.env_root().join("editor2").exists()); insta::assert_snapshot!(get_log_output(&work_dir), @r#" @ rlvkpnrzqnoo false ○ qpvuntsmwlqt false TESTED=TODO ◆ zzzzzzzzzzzz true [EOF] ------- stderr ------- Warning: Deprecated user-level config: ui.default-description is updated to template-aliases.default_commit_description = '"\n\nTESTED=TODO\n"' [EOF] "#);} #[test]fn test_split_with_descendants() { // 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), @r###" @ kkmpptxzrspx false Add file4 ○ rlvkpnrzqnoo false Add file3 ○ qpvuntsmwlqt false Add file1 & file2 ◆ zzzzzzzzzzzz true [EOF] "###); // Set up the editor and do the split. std::fs::write( edit_script, [ "dump editor1", "write\nAdd file1", "next invocation\n", "dump editor2", "write\nAdd file2", ] .join("\0"), ) .unwrap(); let output = work_dir.run_jj(["split", "file1", "-r", "qpvu"]); insta::assert_snapshot!(output, @r" ------- 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), @r###" @ 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("editor1")).unwrap(), @r#" JJ: Enter a description for the selected changes. Add file1 & file2 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!( std::fs::read_to_string(test_env.env_root().join("editor2")).unwrap(), @r#" JJ: Enter a description for the remaining changes. Add file1 & file2 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, @r" ○ qpvuntsm test.user@example.com 2001-02-03 08:05:12 74306e35 │ Add file1 │ -- operation 994b490f285d (2001-02-03 08:05:12) split commit 1d2499e72cefc8a2b87ebb47569140857b96189f ○ qpvuntsm hidden test.user@example.com 2001-02-03 08:05:08 1d2499e7 │ Add file1 & file2 │ -- operation adf4f33386c9 (2001-02-03 08:05:08) commit f5700f8ef89e290e4e90ae6adc0908707e0d8c85 ○ qpvuntsm hidden test.user@example.com 2001-02-03 08:05:08 f5700f8e │ (no description set) │ -- operation 78ead2155fcc (2001-02-03 08:05:08) snapshot working copy ○ qpvuntsm hidden test.user@example.com 2001-02-03 08:05:07 e8849ae1 (empty) (no description set) -- operation 8f47435a3990 (2001-02-03 08:05:07) 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, @r" ○ royxmykx test.user@example.com 2001-02-03 08:05:12 0a37745e │ Add file2 │ -- operation 994b490f285d (2001-02-03 08:05:12) split commit 1d2499e72cefc8a2b87ebb47569140857b96189f ○ qpvuntsm hidden test.user@example.com 2001-02-03 08:05:08 1d2499e7 │ Add file1 & file2 │ -- operation adf4f33386c9 (2001-02-03 08:05:08) commit f5700f8ef89e290e4e90ae6adc0908707e0d8c85 ○ qpvuntsm hidden test.user@example.com 2001-02-03 08:05:08 f5700f8e │ (no description set) │ -- operation 78ead2155fcc (2001-02-03 08:05:08) snapshot working copy ○ qpvuntsm hidden test.user@example.com 2001-02-03 08:05:07 e8849ae1 (empty) (no description set) -- operation 8f47435a3990 (2001-02-03 08:05:07) add workspace 'default' [EOF] ");} // 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() { 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", "description(1)", "description(a)", "-m=2"]) .success(); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ zsuskulnrvyr true 2 ├─╮ │ ○ kkmpptxzrspx false a ○ │ qpvuntsmwlqt true 1 ├─╯ ◆ zzzzzzzzzzzz true [EOF] "); // Set up the editor and do the split. std::fs::write( edit_script, ["write\nAdd file1", "next invocation\n", "write\nAdd file2"].join("\0"), ) .unwrap(); let output = work_dir.run_jj(["split", "-r", "description(a)", "file1"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Rebased 1 descendant commits Selected changes : kkmpptxz cc199567 Add file1 Remaining changes: royxmykx e488409f Add file2 Working copy (@) now at: zsuskuln ace61421 (empty) 2 Parent commit (@-) : qpvuntsm 884fe9b9 (empty) 1 Parent commit (@-) : royxmykx e488409f Add file2 [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ zsuskulnrvyr true 2 ├─╮ │ ○ royxmykxtrkr false Add file2 │ ○ kkmpptxzrspx false Add file1 ○ │ qpvuntsmwlqt true 1 ├─╯ ◆ zzzzzzzzzzzz true [EOF] ");} #[test]// Split a commit with no descendants into siblings. Also tests that the default// description is set correctly on the first commit.fn test_split_parallel_no_descendants() { 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#"ui.default-description = "\n\nTESTED=TODO""#); let work_dir = test_env.work_dir("repo"); work_dir.write_file("file1", "foo\n"); work_dir.write_file("file2", "bar\n"); insta::assert_snapshot!(get_log_output(&work_dir), @r#" @ qpvuntsmwlqt false ◆ zzzzzzzzzzzz true [EOF] ------- stderr -------Lines 1–500 of 1547. 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 test_case::test_case; 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() { 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), @r" @ qpvuntsmwlqt false ◆ zzzzzzzzzzzz true [EOF] "); insta::assert_snapshot!(get_recorded_dates(&work_dir, "@"), @r" Author date: 2001-02-03 04:05:08.000 +07:00 Committer date: 2001-02-03 04:05:08.000 +07:00[EOF] "); std::fs::write( &edit_script, ["dump editor0", "next invocation\n", "dump editor1"].join("\0"), ) .unwrap(); let output = work_dir.run_jj(["split", "file2"]); insta::assert_snapshot!(output, @r" ------- 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] "); insta::assert_snapshot!( std::fs::read_to_string(test_env.env_root().join("editor0")).unwrap(), @r#" JJ: Enter a description for the selected changes. JJ: This commit contains the following changes: JJ: A file2 JJ: JJ: Lines starting with "JJ:" (like this one) will be removed. "#); assert!(!test_env.env_root().join("editor1").exists()); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 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, "@"), @r" 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, "@-"), @r" 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, @r" A file2 [EOF] "); let output = work_dir.run_jj(["diff", "-s"]); insta::assert_snapshot!(output, @r" A file1 A file3 [EOF] "); // Insert an empty commit after @- with "split ." std::fs::write(&edit_script, "").unwrap(); let output = work_dir.run_jj(["split", "-r", "@-", "."]); insta::assert_snapshot!(output, @r" ------- 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), @r" @ zsuskulnrvyr false ○ znkkpsqqskkl true ○ qpvuntsmwlqt false ◆ zzzzzzzzzzzz true [EOF] "); let output = work_dir.run_jj(["diff", "-s", "-r", "@--"]); insta::assert_snapshot!(output, @r" 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, "").unwrap(); let output = work_dir.run_jj(["split", "-r", "@-", "nonexistent"]); insta::assert_snapshot!(output, @r" ------- stderr ------- 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), @r" @ zsuskulnrvyr false ○ lylxulplsnyw false ○ qpvuntsmwlqt true ◆ zzzzzzzzzzzz true [EOF] "); let output = work_dir.run_jj(["diff", "-s", "-r", "@-"]); insta::assert_snapshot!(output, @r" A file2 [EOF] "); } #[test] fn test_split_with_non_empty_description() { 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#"ui.default-description = "\n\nTESTED=TODO""#); 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(); std::fs::write( edit_script, [ "dump editor1", "write\npart 1", "next invocation\n", "dump editor2", "write\npart 2", ] .join("\0"), ) .unwrap(); let output = work_dir.run_jj(["split", "file1"]); insta::assert_snapshot!(output, @r#" ------- stderr ------- Warning: Deprecated user-level config: ui.default-description is updated to template-aliases.default_commit_description = '"\n\nTESTED=TODO\n"' 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("editor1")).unwrap(), @r#" JJ: Enter a description for the selected changes. test 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!( std::fs::read_to_string(test_env.env_root().join("editor2")).unwrap(), @r#" JJ: Enter a description for the remaining changes. test 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), @r#" @ kkmpptxzrspx false part 2 ○ qpvuntsmwlqt false part 1 ◆ zzzzzzzzzzzz true [EOF] ------- stderr ------- Warning: Deprecated user-level config: ui.default-description is updated to template-aliases.default_commit_description = '"\n\nTESTED=TODO\n"' [EOF] "#); } #[test] fn test_split_with_default_description() { 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#"ui.default-description = "\n\nTESTED=TODO""#); 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 editor1", "next invocation\n", "dump editor2"].join("\0"), ) .unwrap(); let output = work_dir.run_jj(["split", "file1"]); insta::assert_snapshot!(output, @r#" ------- stderr ------- Warning: Deprecated user-level config: ui.default-description is updated to template-aliases.default_commit_description = '"\n\nTESTED=TODO\n"' Selected changes : qpvuntsm ff633dcc TESTED=TODO Remaining changes: rlvkpnrz b1d20b7e (no description set) Working copy (@) now at: rlvkpnrz b1d20b7e (no description set) Parent commit (@-) : qpvuntsm ff633dcc TESTED=TODO [EOF] "#); // Since the commit being split has no description, the user will only be // prompted to add a description to the first commit, which will use the // default value we set. The second commit will inherit the empty // description from the commit being split. insta::assert_snapshot!( std::fs::read_to_string(test_env.env_root().join("editor1")).unwrap(), @r#" JJ: Enter a description for the selected changes. TESTED=TODO JJ: This commit contains the following changes: JJ: A file1 JJ: JJ: Lines starting with "JJ:" (like this one) will be removed. "#); assert!(!test_env.env_root().join("editor2").exists()); insta::assert_snapshot!(get_log_output(&work_dir), @r#" @ rlvkpnrzqnoo false ○ qpvuntsmwlqt false TESTED=TODO ◆ zzzzzzzzzzzz true [EOF] ------- stderr ------- Warning: Deprecated user-level config: ui.default-description is updated to template-aliases.default_commit_description = '"\n\nTESTED=TODO\n"' [EOF] "#); } #[test] fn test_split_with_descendants() { // 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), @r###" @ kkmpptxzrspx false Add file4 ○ rlvkpnrzqnoo false Add file3 ○ qpvuntsmwlqt false Add file1 & file2 ◆ zzzzzzzzzzzz true [EOF] "###); // Set up the editor and do the split. std::fs::write( edit_script, [ "dump editor1", "write\nAdd file1", "next invocation\n", "dump editor2", "write\nAdd file2", ] .join("\0"), ) .unwrap(); let output = work_dir.run_jj(["split", "file1", "-r", "qpvu"]); insta::assert_snapshot!(output, @r" ------- 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), @r###" @ 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("editor1")).unwrap(), @r#" JJ: Enter a description for the selected changes. Add file1 & file2 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!( std::fs::read_to_string(test_env.env_root().join("editor2")).unwrap(), @r#" JJ: Enter a description for the remaining changes. Add file1 & file2 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, @r" ○ qpvuntsm test.user@example.com 2001-02-03 08:05:12 74306e35 │ Add file1 │ -- operation 994b490f285d (2001-02-03 08:05:12) split commit 1d2499e72cefc8a2b87ebb47569140857b96189f ○ qpvuntsm hidden test.user@example.com 2001-02-03 08:05:08 1d2499e7 │ Add file1 & file2 │ -- operation adf4f33386c9 (2001-02-03 08:05:08) commit f5700f8ef89e290e4e90ae6adc0908707e0d8c85 ○ qpvuntsm hidden test.user@example.com 2001-02-03 08:05:08 f5700f8e │ (no description set) │ -- operation 78ead2155fcc (2001-02-03 08:05:08) snapshot working copy ○ qpvuntsm hidden test.user@example.com 2001-02-03 08:05:07 e8849ae1 (empty) (no description set) -- operation 8f47435a3990 (2001-02-03 08:05:07) 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, @r" ○ royxmykx test.user@example.com 2001-02-03 08:05:12 0a37745e │ Add file2 │ -- operation 994b490f285d (2001-02-03 08:05:12) split commit 1d2499e72cefc8a2b87ebb47569140857b96189f ○ qpvuntsm hidden test.user@example.com 2001-02-03 08:05:08 1d2499e7 │ Add file1 & file2 │ -- operation adf4f33386c9 (2001-02-03 08:05:08) commit f5700f8ef89e290e4e90ae6adc0908707e0d8c85 ○ qpvuntsm hidden test.user@example.com 2001-02-03 08:05:08 f5700f8e │ (no description set) │ -- operation 78ead2155fcc (2001-02-03 08:05:08) snapshot working copy ○ qpvuntsm hidden test.user@example.com 2001-02-03 08:05:07 e8849ae1 (empty) (no description set) -- operation 8f47435a3990 (2001-02-03 08:05:07) add workspace 'default' [EOF] "); } // 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() { 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", "description(1)", "description(a)", "-m=2"]) .success(); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ zsuskulnrvyr true 2 ├─╮ │ ○ kkmpptxzrspx false a ○ │ qpvuntsmwlqt true 1 ├─╯ ◆ zzzzzzzzzzzz true [EOF] "); // Set up the editor and do the split. std::fs::write( edit_script, ["write\nAdd file1", "next invocation\n", "write\nAdd file2"].join("\0"), ) .unwrap(); let output = work_dir.run_jj(["split", "-r", "description(a)", "file1"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Rebased 1 descendant commits Selected changes : kkmpptxz cc199567 Add file1 Remaining changes: royxmykx e488409f Add file2 Working copy (@) now at: zsuskuln ace61421 (empty) 2 Parent commit (@-) : qpvuntsm 884fe9b9 (empty) 1 Parent commit (@-) : royxmykx e488409f Add file2 [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ zsuskulnrvyr true 2 ├─╮ │ ○ royxmykxtrkr false Add file2 │ ○ kkmpptxzrspx false Add file1 ○ │ qpvuntsmwlqt true 1 ├─╯ ◆ zzzzzzzzzzzz true [EOF] "); } #[test] // Split a commit with no descendants into siblings. Also tests that the default // description is set correctly on the first commit. fn test_split_parallel_no_descendants() { 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#"ui.default-description = "\n\nTESTED=TODO""#); let work_dir = test_env.work_dir("repo"); work_dir.write_file("file1", "foo\n"); work_dir.write_file("file2", "bar\n"); insta::assert_snapshot!(get_log_output(&work_dir), @r#" @ qpvuntsmwlqt false ◆ zzzzzzzzzzzz true [EOF] ------- stderr -------