just playing with tangled
at tmp-tutorial 141 lines 5.0 kB view raw
1// Copyright 2022 The Jujutsu Authors 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// https://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15use std::path::Path; 16 17use crate::common::TestEnvironment; 18 19pub mod common; 20 21#[test] 22fn test_split_by_paths() { 23 let mut test_env = TestEnvironment::default(); 24 test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]); 25 let repo_path = test_env.env_root().join("repo"); 26 27 std::fs::write(repo_path.join("file1"), "foo").unwrap(); 28 std::fs::write(repo_path.join("file2"), "foo").unwrap(); 29 std::fs::write(repo_path.join("file3"), "foo").unwrap(); 30 31 insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###" 32 @ qpvuntsmwlqt false 33 ◉ zzzzzzzzzzzz true 34 "###); 35 36 let edit_script = test_env.set_up_fake_editor(); 37 std::fs::write( 38 edit_script, 39 ["dump editor0", "next invocation\n", "dump editor1"].join("\0"), 40 ) 41 .unwrap(); 42 let stdout = test_env.jj_cmd_success(&repo_path, &["split", "file2"]); 43 insta::assert_snapshot!(stdout, @r###" 44 First part: 5eebce1de3b0 (no description set) 45 Second part: 45833353d94e (no description set) 46 Working copy now at: 45833353d94e (no description set) 47 Parent commit : 5eebce1de3b0 (no description set) 48 "###); 49 insta::assert_snapshot!( 50 std::fs::read_to_string(test_env.env_root().join("editor0")).unwrap(), @r###" 51 JJ: Enter commit description for the first part (parent). 52 53 JJ: This commit contains the following changes: 54 JJ: A file2 55 56 JJ: Lines starting with "JJ: " (like this one) will be removed. 57 "###); 58 insta::assert_snapshot!( 59 std::fs::read_to_string(test_env.env_root().join("editor1")).unwrap(), @r###" 60 JJ: Enter commit description for the second part (child). 61 62 JJ: This commit contains the following changes: 63 JJ: A file1 64 JJ: A file3 65 66 JJ: Lines starting with "JJ: " (like this one) will be removed. 67 "###); 68 69 insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###" 70 @ kkmpptxzrspx false 71 ◉ qpvuntsmwlqt false 72 ◉ zzzzzzzzzzzz true 73 "###); 74 75 let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s", "-r", "@-"]); 76 insta::assert_snapshot!(stdout, @r###" 77 A file2 78 "###); 79 let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s"]); 80 insta::assert_snapshot!(stdout, @r###" 81 A file1 82 A file3 83 "###); 84 85 // Insert an empty commit after @- with "split ." 86 test_env.set_up_fake_editor(); 87 let stdout = test_env.jj_cmd_success(&repo_path, &["split", "-r", "@-", "."]); 88 insta::assert_snapshot!(stdout, @r###" 89 Rebased 1 descendant commits 90 First part: 31425b568fcf (no description set) 91 Second part: af0963926ac3 (empty) (no description set) 92 Working copy now at: 28d4ec20efa9 (no description set) 93 Parent commit : af0963926ac3 (empty) (no description set) 94 "###); 95 96 insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###" 97 @ kkmpptxzrspx false 98 ◉ yqosqzytrlsw true 99 ◉ qpvuntsmwlqt false 100 ◉ zzzzzzzzzzzz true 101 "###); 102 103 let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s", "-r", "@--"]); 104 insta::assert_snapshot!(stdout, @r###" 105 A file2 106 "###); 107 108 // Remove newly created empty commit 109 test_env.jj_cmd_success(&repo_path, &["abandon", "@-"]); 110 111 // Insert an empty commit before @- with "split nonexistent" 112 test_env.set_up_fake_editor(); 113 let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["split", "-r", "@-", "nonexistent"]); 114 insta::assert_snapshot!(stdout, @r###" 115 Rebased 1 descendant commits 116 First part: 0647b2cbd0da (empty) (no description set) 117 Second part: d5d77af65446 (no description set) 118 Working copy now at: 86f228dc3a50 (no description set) 119 Parent commit : d5d77af65446 (no description set) 120 "###); 121 insta::assert_snapshot!(stderr, @r###" 122 The given paths do not match any file: nonexistent 123 "###); 124 125 insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###" 126 @ kkmpptxzrspx false 127 ◉ kpqxywonksrl false 128 ◉ qpvuntsmwlqt true 129 ◉ zzzzzzzzzzzz true 130 "###); 131 132 let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s", "-r", "@-"]); 133 insta::assert_snapshot!(stdout, @r###" 134 A file2 135 "###); 136} 137 138fn get_log_output(test_env: &TestEnvironment, cwd: &Path) -> String { 139 let template = r#"change_id.short() ++ " " ++ empty"#; 140 test_env.jj_cmd_success(cwd, &["log", "-T", template]) 141}