just playing with tangled
at diffedit3 293 lines 12 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 crate::common::{get_stdout_string, TestEnvironment}; 16 17#[test] 18fn test_obslog_with_or_without_diff() { 19 let test_env = TestEnvironment::default(); 20 test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]); 21 let repo_path = test_env.env_root().join("repo"); 22 23 std::fs::write(repo_path.join("file1"), "foo\n").unwrap(); 24 test_env.jj_cmd_ok(&repo_path, &["new", "-m", "my description"]); 25 std::fs::write(repo_path.join("file1"), "foo\nbar\n").unwrap(); 26 std::fs::write(repo_path.join("file2"), "foo\n").unwrap(); 27 test_env.jj_cmd_ok(&repo_path, &["rebase", "-r", "@", "-d", "root()"]); 28 std::fs::write(repo_path.join("file1"), "resolved\n").unwrap(); 29 30 let stdout = test_env.jj_cmd_success(&repo_path, &["obslog"]); 31 insta::assert_snapshot!(stdout, @r###" 32 @ rlvkpnrz test.user@example.com 2001-02-03 08:05:10 66b42ad3 33 │ my description 34 ◉ rlvkpnrz hidden test.user@example.com 2001-02-03 08:05:09 cf73917d conflict 35 │ my description 36 ◉ rlvkpnrz hidden test.user@example.com 2001-02-03 08:05:09 6fbba7bc 37 │ my description 38 ◉ rlvkpnrz hidden test.user@example.com 2001-02-03 08:05:08 eac0d0da 39 (empty) my description 40 "###); 41 42 // Color 43 let stdout = test_env.jj_cmd_success(&repo_path, &["--color=always", "obslog"]); 44 insta::assert_snapshot!(stdout, @r###" 45 @ rlvkpnrz test.user@example.com 2001-02-03 08:05:10 66b42ad3 46 │ my description 47 ◉ rlvkpnrz hidden test.user@example.com 2001-02-03 08:05:09 cf73917d conflict 48 │ my description 49 ◉ rlvkpnrz hidden test.user@example.com 2001-02-03 08:05:09 6fbba7bc 50 │ my description 51 ◉ rlvkpnrz hidden test.user@example.com 2001-02-03 08:05:08 eac0d0da 52 (empty) my description 53 "###); 54 55 // There should be no diff caused by the rebase because it was a pure rebase 56 // (even even though it resulted in a conflict). 57 let stdout = test_env.jj_cmd_success(&repo_path, &["obslog", "-p"]); 58 insta::assert_snapshot!(stdout, @r###" 59 @ rlvkpnrz test.user@example.com 2001-02-03 08:05:10 66b42ad3 60 │ my description 61 │ Resolved conflict in file1: 62 │ 1 1: <<<<<<< Conflict 1 of 1resolved 63 │ 2 : %%%%%%% Changes from base to side #1 64 │ 3 : -foo 65 │ 4 : +++++++ Contents of side #2 66 │ 5 : foo 67 │ 6 : bar 68 │ 7 : >>>>>>> 69 ◉ rlvkpnrz hidden test.user@example.com 2001-02-03 08:05:09 cf73917d conflict 70 │ my description 71 ◉ rlvkpnrz hidden test.user@example.com 2001-02-03 08:05:09 6fbba7bc 72 │ my description 73 │ Modified regular file file1: 74 │ 1 1: foo 75 │ 2: bar 76 │ Added regular file file2: 77 │ 1: foo 78 ◉ rlvkpnrz hidden test.user@example.com 2001-02-03 08:05:08 eac0d0da 79 (empty) my description 80 "###); 81 82 // Test `--limit` 83 let stdout = test_env.jj_cmd_success(&repo_path, &["obslog", "--limit=2"]); 84 insta::assert_snapshot!(stdout, @r###" 85 @ rlvkpnrz test.user@example.com 2001-02-03 08:05:10 66b42ad3 86 │ my description 87 ◉ rlvkpnrz hidden test.user@example.com 2001-02-03 08:05:09 cf73917d conflict 88 │ my description 89 "###); 90 91 // Test `--no-graph` 92 let stdout = test_env.jj_cmd_success(&repo_path, &["obslog", "--no-graph"]); 93 insta::assert_snapshot!(stdout, @r###" 94 rlvkpnrz test.user@example.com 2001-02-03 08:05:10 66b42ad3 95 my description 96 rlvkpnrz hidden test.user@example.com 2001-02-03 08:05:09 cf73917d conflict 97 my description 98 rlvkpnrz hidden test.user@example.com 2001-02-03 08:05:09 6fbba7bc 99 my description 100 rlvkpnrz hidden test.user@example.com 2001-02-03 08:05:08 eac0d0da 101 (empty) my description 102 "###); 103 104 // Test `--git` format, and that it implies `-p` 105 let stdout = test_env.jj_cmd_success(&repo_path, &["obslog", "--no-graph", "--git"]); 106 insta::assert_snapshot!(stdout, @r###" 107 rlvkpnrz test.user@example.com 2001-02-03 08:05:10 66b42ad3 108 my description 109 diff --git a/file1 b/file1 110 index 0000000000...2ab19ae607 100644 111 --- a/file1 112 +++ b/file1 113 @@ -1,7 +1,1 @@ 114 -<<<<<<< Conflict 1 of 1 115 -%%%%%%% Changes from base to side #1 116 --foo 117 -+++++++ Contents of side #2 118 -foo 119 -bar 120 ->>>>>>> 121 +resolved 122 rlvkpnrz hidden test.user@example.com 2001-02-03 08:05:09 cf73917d conflict 123 my description 124 rlvkpnrz hidden test.user@example.com 2001-02-03 08:05:09 6fbba7bc 125 my description 126 diff --git a/file1 b/file1 127 index 257cc5642c...3bd1f0e297 100644 128 --- a/file1 129 +++ b/file1 130 @@ -1,1 +1,2 @@ 131 foo 132 +bar 133 diff --git a/file2 b/file2 134 new file mode 100644 135 index 0000000000..257cc5642c 136 --- /dev/null 137 +++ b/file2 138 @@ -1,0 +1,1 @@ 139 +foo 140 rlvkpnrz hidden test.user@example.com 2001-02-03 08:05:08 eac0d0da 141 (empty) my description 142 "###); 143} 144 145#[test] 146fn test_obslog_with_custom_symbols() { 147 let test_env = TestEnvironment::default(); 148 test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]); 149 let repo_path = test_env.env_root().join("repo"); 150 151 std::fs::write(repo_path.join("file1"), "foo\n").unwrap(); 152 test_env.jj_cmd_ok(&repo_path, &["new", "-m", "my description"]); 153 std::fs::write(repo_path.join("file1"), "foo\nbar\n").unwrap(); 154 std::fs::write(repo_path.join("file2"), "foo\n").unwrap(); 155 test_env.jj_cmd_ok(&repo_path, &["rebase", "-r", "@", "-d", "root()"]); 156 std::fs::write(repo_path.join("file1"), "resolved\n").unwrap(); 157 158 let toml = concat!("templates.log_node = 'if(current_working_copy, \"$\", \"\")'\n",); 159 160 let stdout = test_env.jj_cmd_success(&repo_path, &["obslog", "--config-toml", toml]); 161 162 insta::assert_snapshot!(stdout, @r###" 163 $ rlvkpnrz test.user@example.com 2001-02-03 08:05:10 66b42ad3 164 │ my description 165 ┝ rlvkpnrz hidden test.user@example.com 2001-02-03 08:05:09 cf73917d conflict 166 │ my description 167 ┝ rlvkpnrz hidden test.user@example.com 2001-02-03 08:05:09 6fbba7bc 168 │ my description 169 ┝ rlvkpnrz hidden test.user@example.com 2001-02-03 08:05:08 eac0d0da 170 (empty) my description 171 "###); 172} 173 174#[test] 175fn test_obslog_word_wrap() { 176 let test_env = TestEnvironment::default(); 177 test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]); 178 let repo_path = test_env.env_root().join("repo"); 179 let render = |args: &[&str], columns: u32, word_wrap: bool| { 180 let mut args = args.to_vec(); 181 if word_wrap { 182 args.push("--config-toml=ui.log-word-wrap=true"); 183 } 184 let assert = test_env 185 .jj_cmd(&repo_path, &args) 186 .env("COLUMNS", columns.to_string()) 187 .assert() 188 .success() 189 .stderr(""); 190 get_stdout_string(&assert) 191 }; 192 193 test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "first"]); 194 195 // ui.log-word-wrap option applies to both graph/no-graph outputs 196 insta::assert_snapshot!(render(&["obslog"], 40, false), @r###" 197 @ qpvuntsm test.user@example.com 2001-02-03 08:05:08 69542c19 198 │ (empty) first 199 ◉ qpvuntsm hidden test.user@example.com 2001-02-03 08:05:07 230dd059 200 (empty) (no description set) 201 "###); 202 insta::assert_snapshot!(render(&["obslog"], 40, true), @r###" 203 @ qpvuntsm test.user@example.com 204 │ 2001-02-03 08:05:08 69542c19 205 │ (empty) first 206 ◉ qpvuntsm hidden test.user@example.com 207 2001-02-03 08:05:07 230dd059 208 (empty) (no description set) 209 "###); 210 insta::assert_snapshot!(render(&["obslog", "--no-graph"], 40, false), @r###" 211 qpvuntsm test.user@example.com 2001-02-03 08:05:08 69542c19 212 (empty) first 213 qpvuntsm hidden test.user@example.com 2001-02-03 08:05:07 230dd059 214 (empty) (no description set) 215 "###); 216 insta::assert_snapshot!(render(&["obslog", "--no-graph"], 40, true), @r###" 217 qpvuntsm test.user@example.com 218 2001-02-03 08:05:08 69542c19 219 (empty) first 220 qpvuntsm hidden test.user@example.com 221 2001-02-03 08:05:07 230dd059 222 (empty) (no description set) 223 "###); 224} 225 226#[test] 227fn test_obslog_squash() { 228 let mut test_env = TestEnvironment::default(); 229 test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]); 230 let repo_path = test_env.env_root().join("repo"); 231 232 test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "first"]); 233 std::fs::write(repo_path.join("file1"), "foo\n").unwrap(); 234 test_env.jj_cmd_ok(&repo_path, &["new", "-m", "second"]); 235 std::fs::write(repo_path.join("file1"), "foo\nbar\n").unwrap(); 236 237 let edit_script = test_env.set_up_fake_editor(); 238 std::fs::write(edit_script, "write\nsquashed").unwrap(); 239 test_env.jj_cmd_ok(&repo_path, &["squash"]); 240 241 let stdout = test_env.jj_cmd_success(&repo_path, &["obslog", "-p", "-r", "@-"]); 242 insta::assert_snapshot!(stdout, @r###" 243 ◉ qpvuntsm test.user@example.com 2001-02-03 08:05:10 27e721a5 244 ├─╮ squashed 245 │ │ Modified regular file file1: 246 │ │ 1 1: foo 247 │ │ 2: bar 248 ◉ │ qpvuntsm hidden test.user@example.com 2001-02-03 08:05:09 9764e503 249 │ │ first 250 │ │ Added regular file file1: 251 │ │ 1: foo 252 ◉ │ qpvuntsm hidden test.user@example.com 2001-02-03 08:05:08 69542c19 253 │ │ (empty) first 254 ◉ │ qpvuntsm hidden test.user@example.com 2001-02-03 08:05:07 230dd059 255 │ (empty) (no description set) 256 ◉ kkmpptxz hidden test.user@example.com 2001-02-03 08:05:10 f09a3889 257 │ second 258 │ Modified regular file file1: 259 │ 1 1: foo 260 │ 2: bar 261 ◉ kkmpptxz hidden test.user@example.com 2001-02-03 08:05:09 57996536 262 (empty) second 263 "###); 264} 265 266#[test] 267fn test_obslog_with_no_template() { 268 let test_env = TestEnvironment::default(); 269 test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]); 270 let repo_path = test_env.env_root().join("repo"); 271 272 let stderr = test_env.jj_cmd_cli_error(&repo_path, &["obslog", "-T"]); 273 insta::assert_snapshot!(stderr, @r###" 274 error: a value is required for '--template <TEMPLATE>' but none was supplied 275 276 For more information, try '--help'. 277 Hint: The following template aliases are defined: 278 - builtin_log_comfortable 279 - builtin_log_compact 280 - builtin_log_detailed 281 - builtin_log_node 282 - builtin_log_node_ascii 283 - builtin_log_oneline 284 - builtin_op_log_comfortable 285 - builtin_op_log_compact 286 - builtin_op_log_node 287 - builtin_op_log_node_ascii 288 - commit_summary_separator 289 - description_placeholder 290 - email_placeholder 291 - name_placeholder 292 "###); 293}