| 1 |
// Copyright 2023 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 |
|
| 15 |
use indoc::indoc; |
| 16 |
use regex::Regex; |
| 17 |
use testutils::TestResult; |
| 18 |
|
| 19 |
use crate::common::TestEnvironment; |
| 20 |
|
| 21 |
#[test] |
| 22 |
fn test_log_parents() { |
| 23 |
let test_env = TestEnvironment::default(); |
| 24 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 25 |
let work_dir = test_env.work_dir("repo"); |
| 26 |
|
| 27 |
work_dir.run_jj(["new"]).success(); |
| 28 |
work_dir.run_jj(["new", "@-"]).success(); |
| 29 |
work_dir.run_jj(["new", "@", "@-"]).success(); |
| 30 |
|
| 31 |
let template = |
| 32 |
r#"commit_id ++ "\nP: " ++ parents.len() ++ " " ++ parents.map(|c| c.commit_id()) ++ "\n""#; |
| 33 |
let output = work_dir.run_jj(["log", "-T", template]); |
| 34 |
insta::assert_snapshot!(output, @" |
| 35 |
@ 8b93ef7a3ceefa4e4b1a506945588dd0da2d9e3e |
| 36 |
├─╮ P: 2 1c1c95df80e53b1e654608d7589f5baabb10ebb2 e8849ae12c709f2321908879bc724fdb2ab8a781 |
| 37 |
○ │ 1c1c95df80e53b1e654608d7589f5baabb10ebb2 |
| 38 |
├─╯ P: 1 e8849ae12c709f2321908879bc724fdb2ab8a781 |
| 39 |
○ e8849ae12c709f2321908879bc724fdb2ab8a781 |
| 40 |
│ P: 1 0000000000000000000000000000000000000000 |
| 41 |
◆ 0000000000000000000000000000000000000000 |
| 42 |
P: 0 |
| 43 |
[EOF] |
| 44 |
"); |
| 45 |
|
| 46 |
// List<Commit> can be filtered |
| 47 |
let template = |
| 48 |
r#""P: " ++ parents.filter(|c| !c.root()).map(|c| c.commit_id().short()) ++ "\n""#; |
| 49 |
let output = work_dir.run_jj(["log", "-T", template]); |
| 50 |
insta::assert_snapshot!(output, @" |
| 51 |
@ P: 1c1c95df80e5 e8849ae12c70 |
| 52 |
├─╮ |
| 53 |
○ │ P: e8849ae12c70 |
| 54 |
├─╯ |
| 55 |
○ P: |
| 56 |
◆ P: |
| 57 |
[EOF] |
| 58 |
"); |
| 59 |
|
| 60 |
let template = r#"parents.map(|c| c.commit_id().shortest(4))"#; |
| 61 |
let output = work_dir.run_jj(["log", "-T", template, "-r@", "--color=always"]); |
| 62 |
insta::assert_snapshot!(output, @" |
| 63 |
[1m[38;5;2m@[0m [1m[38;5;4m1[0m[38;5;8mc1c[39m [1m[38;5;4me[0m[38;5;8m884[39m |
| 64 |
│ |
| 65 |
~ |
| 66 |
[EOF] |
| 67 |
"); |
| 68 |
|
| 69 |
// Commit object isn't printable |
| 70 |
let output = work_dir.run_jj(["log", "-T", "parents"]); |
| 71 |
insta::assert_snapshot!(output, @" |
| 72 |
------- stderr ------- |
| 73 |
Error: Failed to parse template: Expected expression of type `Template`, but actual type is `List<Commit>` |
| 74 |
Caused by: --> 1:1 |
| 75 |
| |
| 76 |
1 | parents |
| 77 |
| ^-----^ |
| 78 |
| |
| 79 |
= Expected expression of type `Template`, but actual type is `List<Commit>` |
| 80 |
[EOF] |
| 81 |
[exit status: 1] |
| 82 |
"); |
| 83 |
|
| 84 |
// Redundant argument passed to keyword method |
| 85 |
let template = r#"parents.map(|c| c.commit_id(""))"#; |
| 86 |
let output = work_dir.run_jj(["log", "-T", template]); |
| 87 |
insta::assert_snapshot!(output, @r#" |
| 88 |
------- stderr ------- |
| 89 |
Error: Failed to parse template: Function `commit_id`: Expected 0 arguments |
| 90 |
Caused by: --> 1:29 |
| 91 |
| |
| 92 |
1 | parents.map(|c| c.commit_id("")) |
| 93 |
| ^^ |
| 94 |
| |
| 95 |
= Function `commit_id`: Expected 0 arguments |
| 96 |
[EOF] |
| 97 |
[exit status: 1] |
| 98 |
"#); |
| 99 |
} |
| 100 |
|
| 101 |
#[test] |
| 102 |
fn test_log_author_timestamp() { |
| 103 |
let test_env = TestEnvironment::default(); |
| 104 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 105 |
let work_dir = test_env.work_dir("repo"); |
| 106 |
|
| 107 |
work_dir.run_jj(["describe", "-m", "first"]).success(); |
| 108 |
work_dir.run_jj(["new", "-m", "second"]).success(); |
| 109 |
|
| 110 |
let output = work_dir.run_jj(["log", "-T", "author.timestamp()"]); |
| 111 |
insta::assert_snapshot!(output, @" |
| 112 |
@ 2001-02-03 04:05:09.000 +07:00 |
| 113 |
○ 2001-02-03 04:05:08.000 +07:00 |
| 114 |
◆ 1970-01-01 00:00:00.000 +00:00 |
| 115 |
[EOF] |
| 116 |
"); |
| 117 |
} |
| 118 |
|
| 119 |
#[test] |
| 120 |
fn test_log_author_timestamp_ago() -> TestResult { |
| 121 |
let test_env = TestEnvironment::default(); |
| 122 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 123 |
let work_dir = test_env.work_dir("repo"); |
| 124 |
|
| 125 |
work_dir.run_jj(["describe", "-m", "first"]).success(); |
| 126 |
work_dir.run_jj(["new", "-m", "second"]).success(); |
| 127 |
|
| 128 |
let template = r#"author.timestamp().ago() ++ "\n""#; |
| 129 |
let output = work_dir |
| 130 |
.run_jj(&["log", "--no-graph", "-T", template]) |
| 131 |
.success(); |
| 132 |
let line_re = Regex::new(r"[0-9]+ years ago")?; |
| 133 |
assert!( |
| 134 |
output.stdout.raw().lines().all(|x| line_re.is_match(x)), |
| 135 |
"expected every line to match regex" |
| 136 |
); |
| 137 |
Ok(()) |
| 138 |
} |
| 139 |
|
| 140 |
#[test] |
| 141 |
fn test_log_author_timestamp_utc() { |
| 142 |
let test_env = TestEnvironment::default(); |
| 143 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 144 |
let work_dir = test_env.work_dir("repo"); |
| 145 |
|
| 146 |
let output = work_dir.run_jj(["log", "-T", "author.timestamp().utc()"]); |
| 147 |
insta::assert_snapshot!(output, @" |
| 148 |
@ 2001-02-02 21:05:07.000 +00:00 |
| 149 |
◆ 1970-01-01 00:00:00.000 +00:00 |
| 150 |
[EOF] |
| 151 |
"); |
| 152 |
} |
| 153 |
|
| 154 |
#[cfg(unix)] |
| 155 |
#[test] |
| 156 |
fn test_log_author_timestamp_local() { |
| 157 |
let mut test_env = TestEnvironment::default(); |
| 158 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 159 |
|
| 160 |
test_env.add_env_var("TZ", "UTC-05:30"); |
| 161 |
let work_dir = test_env.work_dir("repo"); |
| 162 |
let output = work_dir.run_jj(["log", "-T", "author.timestamp().local()"]); |
| 163 |
insta::assert_snapshot!(output, @" |
| 164 |
@ 2001-02-03 08:05:07.000 +11:00 |
| 165 |
◆ 1970-01-01 11:00:00.000 +11:00 |
| 166 |
[EOF] |
| 167 |
"); |
| 168 |
test_env.add_env_var("TZ", "UTC+10:00"); |
| 169 |
let work_dir = test_env.work_dir("repo"); |
| 170 |
let output = work_dir.run_jj(["log", "-T", "author.timestamp().local()"]); |
| 171 |
insta::assert_snapshot!(output, @" |
| 172 |
@ 2001-02-03 08:05:07.000 +11:00 |
| 173 |
◆ 1970-01-01 11:00:00.000 +11:00 |
| 174 |
[EOF] |
| 175 |
"); |
| 176 |
} |
| 177 |
|
| 178 |
#[test] |
| 179 |
fn test_log_author_timestamp_after_before() { |
| 180 |
let test_env = TestEnvironment::default(); |
| 181 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 182 |
let work_dir = test_env.work_dir("repo"); |
| 183 |
|
| 184 |
work_dir.run_jj(["describe", "-m", "first"]).success(); |
| 185 |
|
| 186 |
let template = r#" |
| 187 |
separate(" ", |
| 188 |
author.timestamp(), |
| 189 |
":", |
| 190 |
if(author.timestamp().after("1969"), "(after 1969)", "(before 1969)"), |
| 191 |
if(author.timestamp().before("1975"), "(before 1975)", "(after 1975)"), |
| 192 |
if(author.timestamp().before("now"), "(before now)", "(after now)") |
| 193 |
) ++ "\n""#; |
| 194 |
let output = work_dir.run_jj(["log", "--no-graph", "-T", template]); |
| 195 |
insta::assert_snapshot!(output, @" |
| 196 |
2001-02-03 04:05:08.000 +07:00 : (after 1969) (after 1975) (before now) |
| 197 |
1970-01-01 00:00:00.000 +00:00 : (after 1969) (before 1975) (before now) |
| 198 |
[EOF] |
| 199 |
"); |
| 200 |
|
| 201 |
// Should display error with invalid date. |
| 202 |
let template = r#"author.timestamp().after("invalid date")"#; |
| 203 |
let output = work_dir.run_jj(["log", "-r@", "--no-graph", "-T", template]); |
| 204 |
insta::assert_snapshot!(output, @r#" |
| 205 |
------- stderr ------- |
| 206 |
Error: Failed to parse template: Invalid date pattern |
| 207 |
Caused by: |
| 208 |
1: --> 1:26 |
| 209 |
| |
| 210 |
1 | author.timestamp().after("invalid date") |
| 211 |
| ^------------^ |
| 212 |
| |
| 213 |
= Invalid date pattern |
| 214 |
2: expected unsupported identifier as position 0..7 |
| 215 |
[EOF] |
| 216 |
[exit status: 1] |
| 217 |
"#); |
| 218 |
} |
| 219 |
|
| 220 |
#[test] |
| 221 |
fn test_mine_is_true_when_author_is_user() { |
| 222 |
let test_env = TestEnvironment::default(); |
| 223 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 224 |
let work_dir = test_env.work_dir("repo"); |
| 225 |
work_dir |
| 226 |
.run_jj([ |
| 227 |
"[email protected]", |
| 228 |
"--config=user.name=John Doe", |
| 229 |
"new", |
| 230 |
]) |
| 231 |
.success(); |
| 232 |
|
| 233 |
let output = work_dir.run_jj([ |
| 234 |
"log", |
| 235 |
"-T", |
| 236 |
r#"coalesce(if(mine, "mine"), author.email(), email_placeholder)"#, |
| 237 |
]); |
| 238 |
insta::assert_snapshot!(output, @" |
| 239 |
@ [email protected] |
| 240 |
○ mine |
| 241 |
◆ (no email set) |
| 242 |
[EOF] |
| 243 |
"); |
| 244 |
} |
| 245 |
|
| 246 |
#[test] |
| 247 |
fn test_log_json() { |
| 248 |
let test_env = TestEnvironment::default(); |
| 249 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 250 |
let work_dir = test_env.work_dir("repo"); |
| 251 |
|
| 252 |
work_dir.run_jj(["describe", "-m", "first"]).success(); |
| 253 |
work_dir.run_jj(["new", "-m", "second"]).success(); |
| 254 |
|
| 255 |
let output = work_dir.run_jj(["log", r#"-Tjson(self) ++ "\n""#]); |
| 256 |
insta::assert_snapshot!(output, @r#" |
| 257 |
@ {"commit_id":"b1cb6b2f9141e6ffee18532a8bf9a2075ca02606","parents":["68a505386f936fff6d718f55005e77ea72589bc1"],"change_id":"kkmpptxzrspxrzommnulwmwkkqwworpl","description":"second\n","author":{"name":"Test User","email":"[email protected]","timestamp":"2001-02-03T04:05:09+07:00"},"committer":{"name":"Test User","email":"[email protected]","timestamp":"2001-02-03T04:05:09+07:00"}} |
| 258 |
○ {"commit_id":"68a505386f936fff6d718f55005e77ea72589bc1","parents":["0000000000000000000000000000000000000000"],"change_id":"qpvuntsmwlqtpsluzzsnyyzlmlwvmlnu","description":"first\n","author":{"name":"Test User","email":"[email protected]","timestamp":"2001-02-03T04:05:08+07:00"},"committer":{"name":"Test User","email":"[email protected]","timestamp":"2001-02-03T04:05:08+07:00"}} |
| 259 |
◆ {"commit_id":"0000000000000000000000000000000000000000","parents":[],"change_id":"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz","description":"","author":{"name":"","email":"","timestamp":"1970-01-01T00:00:00Z"},"committer":{"name":"","email":"","timestamp":"1970-01-01T00:00:00Z"}} |
| 260 |
[EOF] |
| 261 |
"#); |
| 262 |
} |
| 263 |
|
| 264 |
#[test] |
| 265 |
fn test_log_default() { |
| 266 |
let test_env = TestEnvironment::default(); |
| 267 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 268 |
let work_dir = test_env.work_dir("repo"); |
| 269 |
|
| 270 |
work_dir.write_file("file1", "foo\n"); |
| 271 |
work_dir.run_jj(["describe", "-m", "add a file"]).success(); |
| 272 |
work_dir.run_jj(["new", "-m", "description 1"]).success(); |
| 273 |
work_dir |
| 274 |
.run_jj(["bookmark", "create", "-r@", "my-bookmark"]) |
| 275 |
.success(); |
| 276 |
|
| 277 |
// Test default log output format |
| 278 |
let output = work_dir.run_jj(["log"]); |
| 279 |
insta::assert_snapshot!(output, @" |
| 280 |
@ kkmpptxz [email protected] 2001-02-03 08:05:09 my-bookmark c938c088 |
| 281 |
│ (empty) description 1 |
| 282 |
○ qpvuntsm [email protected] 2001-02-03 08:05:08 007859d3 |
| 283 |
│ add a file |
| 284 |
◆ zzzzzzzz root() 00000000 |
| 285 |
[EOF] |
| 286 |
"); |
| 287 |
|
| 288 |
// Color |
| 289 |
let output = work_dir.run_jj(["log", "--color=always"]); |
| 290 |
insta::assert_snapshot!(output, @" |
| 291 |
[1m[38;5;2m@[0m [1m[38;5;13mk[38;5;8mkmpptxz[39m [38;5;[email protected][39m [38;5;14m2001-02-03 08:05:09[39m [38;5;13mmy-bookmark[39m [38;5;12mc[38;5;8m938c088[39m[0m |
| 292 |
│ [1m[38;5;10m(empty)[39m description 1[0m |
| 293 |
○ [1m[38;5;5mq[0m[38;5;8mpvuntsm[39m [38;5;[email protected][39m [38;5;6m2001-02-03 08:05:08[39m [1m[38;5;4m007[0m[38;5;8m859d3[39m |
| 294 |
│ add a file |
| 295 |
[1m[38;5;14m◆[0m [1m[38;5;5mz[0m[38;5;8mzzzzzzz[39m [38;5;2mroot()[39m [1m[38;5;4m000[0m[38;5;8m00000[39m |
| 296 |
[EOF] |
| 297 |
"); |
| 298 |
|
| 299 |
// Color without graph |
| 300 |
let output = work_dir.run_jj(["log", "--color=always", "--no-graph"]); |
| 301 |
insta::assert_snapshot!(output, @" |
| 302 |
[1m[38;5;13mk[38;5;8mkmpptxz[39m [38;5;[email protected][39m [38;5;14m2001-02-03 08:05:09[39m [38;5;13mmy-bookmark[39m [38;5;12mc[38;5;8m938c088[39m[0m |
| 303 |
[1m[38;5;10m(empty)[39m description 1[0m |
| 304 |
[1m[38;5;5mq[0m[38;5;8mpvuntsm[39m [38;5;[email protected][39m [38;5;6m2001-02-03 08:05:08[39m [1m[38;5;4m007[0m[38;5;8m859d3[39m |
| 305 |
add a file |
| 306 |
[1m[38;5;5mz[0m[38;5;8mzzzzzzz[39m [38;5;2mroot()[39m [1m[38;5;4m000[0m[38;5;8m00000[39m |
| 307 |
[EOF] |
| 308 |
"); |
| 309 |
} |
| 310 |
|
| 311 |
#[test] |
| 312 |
fn test_log_default_without_working_copy() { |
| 313 |
let test_env = TestEnvironment::default(); |
| 314 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 315 |
let work_dir = test_env.work_dir("repo"); |
| 316 |
|
| 317 |
work_dir.run_jj(["workspace", "forget"]).success(); |
| 318 |
let output = work_dir.run_jj(["log"]); |
| 319 |
insta::assert_snapshot!(output, @" |
| 320 |
◆ zzzzzzzz root() 00000000 |
| 321 |
[EOF] |
| 322 |
"); |
| 323 |
} |
| 324 |
|
| 325 |
#[test] |
| 326 |
fn test_log_builtin_templates() { |
| 327 |
let test_env = TestEnvironment::default(); |
| 328 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 329 |
let work_dir = test_env.work_dir("repo"); |
| 330 |
// Render without graph to test line ending |
| 331 |
let render = |template| work_dir.run_jj(["log", "-T", template, "--no-graph"]); |
| 332 |
|
| 333 |
work_dir |
| 334 |
.run_jj(["--config=user.email=''", "--config=user.name=''", "new"]) |
| 335 |
.success(); |
| 336 |
work_dir |
| 337 |
.run_jj(["bookmark", "create", "-r@", "my-bookmark"]) |
| 338 |
.success(); |
| 339 |
|
| 340 |
insta::assert_snapshot!(render(r#"builtin_log_oneline"#), @" |
| 341 |
rlvkpnrz (no email set) 2001-02-03 08:05:08 my-bookmark aec3ec96 (empty) (no description set) |
| 342 |
qpvuntsm test.user 2001-02-03 08:05:07 e8849ae1 (empty) (no description set) |
| 343 |
zzzzzzzz root() 00000000 |
| 344 |
[EOF] |
| 345 |
"); |
| 346 |
|
| 347 |
insta::assert_snapshot!(render(r#"builtin_log_compact"#), @" |
| 348 |
rlvkpnrz (no email set) 2001-02-03 08:05:08 my-bookmark aec3ec96 |
| 349 |
(empty) (no description set) |
| 350 |
qpvuntsm [email protected] 2001-02-03 08:05:07 e8849ae1 |
| 351 |
(empty) (no description set) |
| 352 |
zzzzzzzz root() 00000000 |
| 353 |
[EOF] |
| 354 |
"); |
| 355 |
|
| 356 |
insta::assert_snapshot!(render(r#"builtin_log_comfortable"#), @" |
| 357 |
rlvkpnrz (no email set) 2001-02-03 08:05:08 my-bookmark aec3ec96 |
| 358 |
(empty) (no description set) |
| 359 |
|
| 360 |
qpvuntsm [email protected] 2001-02-03 08:05:07 e8849ae1 |
| 361 |
(empty) (no description set) |
| 362 |
|
| 363 |
zzzzzzzz root() 00000000 |
| 364 |
|
| 365 |
[EOF] |
| 366 |
"); |
| 367 |
|
| 368 |
insta::assert_snapshot!(render(r#"builtin_log_detailed"#), @" |
| 369 |
Commit ID: aec3ec964d0771edea9da48a2a170bc6ffa1c725 |
| 370 |
Change ID: rlvkpnrzqnoowoytxnquwvuryrwnrmlp |
| 371 |
Bookmarks: my-bookmark |
| 372 |
Author : (no name set) <(no email set)> (2001-02-03 08:05:08) |
| 373 |
Committer: (no name set) <(no email set)> (2001-02-03 08:05:08) |
| 374 |
|
| 375 |
(no description set) |
| 376 |
|
| 377 |
Commit ID: e8849ae12c709f2321908879bc724fdb2ab8a781 |
| 378 |
Change ID: qpvuntsmwlqtpsluzzsnyyzlmlwvmlnu |
| 379 |
Author : Test User <[email protected]> (2001-02-03 08:05:07) |
| 380 |
Committer: Test User <[email protected]> (2001-02-03 08:05:07) |
| 381 |
|
| 382 |
(no description set) |
| 383 |
|
| 384 |
Commit ID: 0000000000000000000000000000000000000000 |
| 385 |
Change ID: zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz |
| 386 |
Author : (no name set) <(no email set)> (1970-01-01 11:00:00) |
| 387 |
Committer: (no name set) <(no email set)> (1970-01-01 11:00:00) |
| 388 |
|
| 389 |
(no description set) |
| 390 |
|
| 391 |
[EOF] |
| 392 |
"); |
| 393 |
} |
| 394 |
|
| 395 |
#[test] |
| 396 |
fn test_log_builtin_templates_colored() { |
| 397 |
let test_env = TestEnvironment::default(); |
| 398 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 399 |
let work_dir = test_env.work_dir("repo"); |
| 400 |
let render = |template| work_dir.run_jj(["--color=always", "log", "-T", template]); |
| 401 |
|
| 402 |
work_dir |
| 403 |
.run_jj(["--config=user.email=''", "--config=user.name=''", "new"]) |
| 404 |
.success(); |
| 405 |
work_dir |
| 406 |
.run_jj(["bookmark", "create", "-r@", "my-bookmark"]) |
| 407 |
.success(); |
| 408 |
|
| 409 |
insta::assert_snapshot!(render(r#"builtin_log_oneline"#), @" |
| 410 |
[1m[38;5;2m@[0m [1m[38;5;13mr[38;5;8mlvkpnrz[39m [38;5;9m(no email set)[39m [38;5;14m2001-02-03 08:05:08[39m [38;5;13mmy-bookmark[39m [38;5;12ma[38;5;8mec3ec96[39m [38;5;10m(empty)[39m [38;5;10m(no description set)[39m[0m |
| 411 |
○ [1m[38;5;5mq[0m[38;5;8mpvuntsm[39m [38;5;3mtest.user[39m [38;5;6m2001-02-03 08:05:07[39m [1m[38;5;4me[0m[38;5;8m8849ae1[39m [38;5;2m(empty)[39m [38;5;2m(no description set)[39m |
| 412 |
[1m[38;5;14m◆[0m [1m[38;5;5mz[0m[38;5;8mzzzzzzz[39m [38;5;2mroot()[39m [1m[38;5;4m0[0m[38;5;8m0000000[39m |
| 413 |
[EOF] |
| 414 |
"); |
| 415 |
|
| 416 |
insta::assert_snapshot!(render(r#"builtin_log_compact"#), @" |
| 417 |
[1m[38;5;2m@[0m [1m[38;5;13mr[38;5;8mlvkpnrz[39m [38;5;9m(no email set)[39m [38;5;14m2001-02-03 08:05:08[39m [38;5;13mmy-bookmark[39m [38;5;12ma[38;5;8mec3ec96[39m[0m |
| 418 |
│ [1m[38;5;10m(empty)[39m [38;5;10m(no description set)[39m[0m |
| 419 |
○ [1m[38;5;5mq[0m[38;5;8mpvuntsm[39m [38;5;[email protected][39m [38;5;6m2001-02-03 08:05:07[39m [1m[38;5;4me[0m[38;5;8m8849ae1[39m |
| 420 |
│ [38;5;2m(empty)[39m [38;5;2m(no description set)[39m |
| 421 |
[1m[38;5;14m◆[0m [1m[38;5;5mz[0m[38;5;8mzzzzzzz[39m [38;5;2mroot()[39m [1m[38;5;4m0[0m[38;5;8m0000000[39m |
| 422 |
[EOF] |
| 423 |
"); |
| 424 |
|
| 425 |
insta::assert_snapshot!(render(r#"builtin_log_comfortable"#), @" |
| 426 |
[1m[38;5;2m@[0m [1m[38;5;13mr[38;5;8mlvkpnrz[39m [38;5;9m(no email set)[39m [38;5;14m2001-02-03 08:05:08[39m [38;5;13mmy-bookmark[39m [38;5;12ma[38;5;8mec3ec96[39m[0m |
| 427 |
│ [1m[38;5;10m(empty)[39m [38;5;10m(no description set)[39m[0m |
| 428 |
│ |
| 429 |
○ [1m[38;5;5mq[0m[38;5;8mpvuntsm[39m [38;5;[email protected][39m [38;5;6m2001-02-03 08:05:07[39m [1m[38;5;4me[0m[38;5;8m8849ae1[39m |
| 430 |
│ [38;5;2m(empty)[39m [38;5;2m(no description set)[39m |
| 431 |
│ |
| 432 |
[1m[38;5;14m◆[0m [1m[38;5;5mz[0m[38;5;8mzzzzzzz[39m [38;5;2mroot()[39m [1m[38;5;4m0[0m[38;5;8m0000000[39m |
| 433 |
|
| 434 |
[EOF] |
| 435 |
"); |
| 436 |
|
| 437 |
insta::assert_snapshot!(render(r#"builtin_log_detailed"#), @" |
| 438 |
[1m[38;5;2m@[0m Commit ID: [38;5;4maec3ec964d0771edea9da48a2a170bc6ffa1c725[39m |
| 439 |
│ Change ID: [38;5;5mrlvkpnrzqnoowoytxnquwvuryrwnrmlp[39m |
| 440 |
│ Bookmarks: [38;5;5mmy-bookmark[39m |
| 441 |
│ Author : [38;5;1m(no name set)[39m <[38;5;1m(no email set)[39m> ([38;5;6m2001-02-03 08:05:08[39m) |
| 442 |
│ Committer: [38;5;1m(no name set)[39m <[38;5;1m(no email set)[39m> ([38;5;6m2001-02-03 08:05:08[39m) |
| 443 |
│ |
| 444 |
│ [38;5;2m (no description set)[39m |
| 445 |
│ |
| 446 |
○ Commit ID: [38;5;4me8849ae12c709f2321908879bc724fdb2ab8a781[39m |
| 447 |
│ Change ID: [38;5;5mqpvuntsmwlqtpsluzzsnyyzlmlwvmlnu[39m |
| 448 |
│ Author : [38;5;3mTest User[39m <[38;5;[email protected][39m> ([38;5;6m2001-02-03 08:05:07[39m) |
| 449 |
│ Committer: [38;5;3mTest User[39m <[38;5;[email protected][39m> ([38;5;6m2001-02-03 08:05:07[39m) |
| 450 |
│ |
| 451 |
│ [38;5;2m (no description set)[39m |
| 452 |
│ |
| 453 |
[1m[38;5;14m◆[0m Commit ID: [38;5;4m0000000000000000000000000000000000000000[39m |
| 454 |
Change ID: [38;5;5mzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz[39m |
| 455 |
Author : [38;5;1m(no name set)[39m <[38;5;1m(no email set)[39m> ([38;5;6m1970-01-01 11:00:00[39m) |
| 456 |
Committer: [38;5;1m(no name set)[39m <[38;5;1m(no email set)[39m> ([38;5;6m1970-01-01 11:00:00[39m) |
| 457 |
|
| 458 |
[38;5;2m (no description set)[39m |
| 459 |
|
| 460 |
[EOF] |
| 461 |
"); |
| 462 |
} |
| 463 |
|
| 464 |
#[test] |
| 465 |
fn test_log_builtin_templates_colored_debug() { |
| 466 |
let test_env = TestEnvironment::default(); |
| 467 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 468 |
let work_dir = test_env.work_dir("repo"); |
| 469 |
let render = |template| work_dir.run_jj(["--color=debug", "log", "-T", template]); |
| 470 |
|
| 471 |
work_dir |
| 472 |
.run_jj(["--config=user.email=''", "--config=user.name=''", "new"]) |
| 473 |
.success(); |
| 474 |
work_dir |
| 475 |
.run_jj(["bookmark", "create", "-r@", "my-bookmark"]) |
| 476 |
.success(); |
| 477 |
|
| 478 |
insta::assert_snapshot!(render(r#"builtin_log_oneline"#), @" |
| 479 |
[1m[38;5;2m<<log commit node working_copy mutable::@>>[0m [1m[38;5;13m<<log commit working_copy mutable change_id shortest prefix::r>>[38;5;8m<<log commit working_copy mutable change_id shortest rest::lvkpnrz>>[39m<<log commit working_copy mutable:: >>[38;5;9m<<log commit working_copy mutable email placeholder::(no email set)>>[39m<<log commit working_copy mutable:: >>[38;5;14m<<log commit working_copy mutable committer timestamp local format::2001-02-03 08:05:08>>[39m<<log commit working_copy mutable:: >>[38;5;13m<<log commit working_copy mutable bookmarks name::my-bookmark>>[39m<<log commit working_copy mutable:: >>[38;5;12m<<log commit working_copy mutable commit_id shortest prefix::a>>[38;5;8m<<log commit working_copy mutable commit_id shortest rest::ec3ec96>>[39m<<log commit working_copy mutable:: >>[38;5;10m<<log commit working_copy mutable empty::(empty)>>[39m<<log commit working_copy mutable:: >>[38;5;10m<<log commit working_copy mutable empty description placeholder::(no description set)>>[39m<<log commit working_copy mutable::>>[0m |
| 480 |
<<log commit node mutable::○>> [1m[38;5;5m<<log commit mutable change_id shortest prefix::q>>[0m[38;5;8m<<log commit mutable change_id shortest rest::pvuntsm>>[39m<<log commit mutable:: >>[38;5;3m<<log commit mutable author email local::test.user>>[39m<<log commit mutable:: >>[38;5;6m<<log commit mutable committer timestamp local format::2001-02-03 08:05:07>>[39m<<log commit mutable:: >>[1m[38;5;4m<<log commit mutable commit_id shortest prefix::e>>[0m[38;5;8m<<log commit mutable commit_id shortest rest::8849ae1>>[39m<<log commit mutable:: >>[38;5;2m<<log commit mutable empty::(empty)>>[39m<<log commit mutable:: >>[38;5;2m<<log commit mutable empty description placeholder::(no description set)>>[39m<<log commit mutable::>> |
| 481 |
[1m[38;5;14m<<log commit node immutable::◆>>[0m [1m[38;5;5m<<log commit immutable change_id shortest prefix::z>>[0m[38;5;8m<<log commit immutable change_id shortest rest::zzzzzzz>>[39m<<log commit immutable:: >>[38;5;2m<<log commit immutable root::root()>>[39m<<log commit immutable:: >>[1m[38;5;4m<<log commit immutable commit_id shortest prefix::0>>[0m[38;5;8m<<log commit immutable commit_id shortest rest::0000000>>[39m<<log commit immutable::>> |
| 482 |
[EOF] |
| 483 |
"); |
| 484 |
|
| 485 |
insta::assert_snapshot!(render(r#"builtin_log_compact"#), @" |
| 486 |
[1m[38;5;2m<<log commit node working_copy mutable::@>>[0m [1m[38;5;13m<<log commit working_copy mutable change_id shortest prefix::r>>[38;5;8m<<log commit working_copy mutable change_id shortest rest::lvkpnrz>>[39m<<log commit working_copy mutable:: >>[38;5;9m<<log commit working_copy mutable email placeholder::(no email set)>>[39m<<log commit working_copy mutable:: >>[38;5;14m<<log commit working_copy mutable committer timestamp local format::2001-02-03 08:05:08>>[39m<<log commit working_copy mutable:: >>[38;5;13m<<log commit working_copy mutable bookmarks name::my-bookmark>>[39m<<log commit working_copy mutable:: >>[38;5;12m<<log commit working_copy mutable commit_id shortest prefix::a>>[38;5;8m<<log commit working_copy mutable commit_id shortest rest::ec3ec96>>[39m<<log commit working_copy mutable::>>[0m |
| 487 |
│ [1m[38;5;10m<<log commit working_copy mutable empty::(empty)>>[39m<<log commit working_copy mutable:: >>[38;5;10m<<log commit working_copy mutable empty description placeholder::(no description set)>>[39m<<log commit working_copy mutable::>>[0m |
| 488 |
<<log commit node mutable::○>> [1m[38;5;5m<<log commit mutable change_id shortest prefix::q>>[0m[38;5;8m<<log commit mutable change_id shortest rest::pvuntsm>>[39m<<log commit mutable:: >>[38;5;3m<<log commit mutable author email local::test.user>><<log commit mutable author email::@>><<log commit mutable author email domain::example.com>>[39m<<log commit mutable:: >>[38;5;6m<<log commit mutable committer timestamp local format::2001-02-03 08:05:07>>[39m<<log commit mutable:: >>[1m[38;5;4m<<log commit mutable commit_id shortest prefix::e>>[0m[38;5;8m<<log commit mutable commit_id shortest rest::8849ae1>>[39m<<log commit mutable::>> |
| 489 |
│ [38;5;2m<<log commit mutable empty::(empty)>>[39m<<log commit mutable:: >>[38;5;2m<<log commit mutable empty description placeholder::(no description set)>>[39m<<log commit mutable::>> |
| 490 |
[1m[38;5;14m<<log commit node immutable::◆>>[0m [1m[38;5;5m<<log commit immutable change_id shortest prefix::z>>[0m[38;5;8m<<log commit immutable change_id shortest rest::zzzzzzz>>[39m<<log commit immutable:: >>[38;5;2m<<log commit immutable root::root()>>[39m<<log commit immutable:: >>[1m[38;5;4m<<log commit immutable commit_id shortest prefix::0>>[0m[38;5;8m<<log commit immutable commit_id shortest rest::0000000>>[39m<<log commit immutable::>> |
| 491 |
[EOF] |
| 492 |
"); |
| 493 |
|
| 494 |
insta::assert_snapshot!(render(r#"builtin_log_comfortable"#), @" |
| 495 |
[1m[38;5;2m<<log commit node working_copy mutable::@>>[0m [1m[38;5;13m<<log commit working_copy mutable change_id shortest prefix::r>>[38;5;8m<<log commit working_copy mutable change_id shortest rest::lvkpnrz>>[39m<<log commit working_copy mutable:: >>[38;5;9m<<log commit working_copy mutable email placeholder::(no email set)>>[39m<<log commit working_copy mutable:: >>[38;5;14m<<log commit working_copy mutable committer timestamp local format::2001-02-03 08:05:08>>[39m<<log commit working_copy mutable:: >>[38;5;13m<<log commit working_copy mutable bookmarks name::my-bookmark>>[39m<<log commit working_copy mutable:: >>[38;5;12m<<log commit working_copy mutable commit_id shortest prefix::a>>[38;5;8m<<log commit working_copy mutable commit_id shortest rest::ec3ec96>>[39m<<log commit working_copy mutable::>>[0m |
| 496 |
│ [1m[38;5;10m<<log commit working_copy mutable empty::(empty)>>[39m<<log commit working_copy mutable:: >>[38;5;10m<<log commit working_copy mutable empty description placeholder::(no description set)>>[39m<<log commit working_copy mutable::>>[0m |
| 497 |
│ <<log commit::>> |
| 498 |
<<log commit node mutable::○>> [1m[38;5;5m<<log commit mutable change_id shortest prefix::q>>[0m[38;5;8m<<log commit mutable change_id shortest rest::pvuntsm>>[39m<<log commit mutable:: >>[38;5;3m<<log commit mutable author email local::test.user>><<log commit mutable author email::@>><<log commit mutable author email domain::example.com>>[39m<<log commit mutable:: >>[38;5;6m<<log commit mutable committer timestamp local format::2001-02-03 08:05:07>>[39m<<log commit mutable:: >>[1m[38;5;4m<<log commit mutable commit_id shortest prefix::e>>[0m[38;5;8m<<log commit mutable commit_id shortest rest::8849ae1>>[39m<<log commit mutable::>> |
| 499 |
│ [38;5;2m<<log commit mutable empty::(empty)>>[39m<<log commit mutable:: >>[38;5;2m<<log commit mutable empty description placeholder::(no description set)>>[39m<<log commit mutable::>> |
| 500 |
│ <<log commit::>> |
| 501 |
[1m[38;5;14m<<log commit node immutable::◆>>[0m [1m[38;5;5m<<log commit immutable change_id shortest prefix::z>>[0m[38;5;8m<<log commit immutable change_id shortest rest::zzzzzzz>>[39m<<log commit immutable:: >>[38;5;2m<<log commit immutable root::root()>>[39m<<log commit immutable:: >>[1m[38;5;4m<<log commit immutable commit_id shortest prefix::0>>[0m[38;5;8m<<log commit immutable commit_id shortest rest::0000000>>[39m<<log commit immutable::>> |
| 502 |
<<log commit::>> |
| 503 |
[EOF] |
| 504 |
"); |
| 505 |
|
| 506 |
insta::assert_snapshot!(render(r#"builtin_log_detailed"#), @" |
| 507 |
[1m[38;5;2m<<log commit node working_copy mutable::@>>[0m <<log commit::Commit ID: >>[38;5;4m<<log commit commit_id::aec3ec964d0771edea9da48a2a170bc6ffa1c725>>[39m<<log commit::>> |
| 508 |
│ <<log commit::Change ID: >>[38;5;5m<<log commit change_id::rlvkpnrzqnoowoytxnquwvuryrwnrmlp>>[39m<<log commit::>> |
| 509 |
│ <<log commit::Bookmarks: >>[38;5;5m<<log commit local_bookmarks name::my-bookmark>>[39m<<log commit::>> |
| 510 |
│ <<log commit::Author : >>[38;5;1m<<log commit name placeholder::(no name set)>>[39m<<log commit:: <>>[38;5;1m<<log commit email placeholder::(no email set)>>[39m<<log commit::> (>>[38;5;6m<<log commit author timestamp local format::2001-02-03 08:05:08>>[39m<<log commit::)>> |
| 511 |
│ <<log commit::Committer: >>[38;5;1m<<log commit name placeholder::(no name set)>>[39m<<log commit:: <>>[38;5;1m<<log commit email placeholder::(no email set)>>[39m<<log commit::> (>>[38;5;6m<<log commit committer timestamp local format::2001-02-03 08:05:08>>[39m<<log commit::)>> |
| 512 |
│ <<log commit::>> |
| 513 |
│ [38;5;2m<<log commit empty description placeholder:: (no description set)>>[39m<<log commit::>> |
| 514 |
│ <<log commit::>> |
| 515 |
<<log commit node mutable::○>> <<log commit::Commit ID: >>[38;5;4m<<log commit commit_id::e8849ae12c709f2321908879bc724fdb2ab8a781>>[39m<<log commit::>> |
| 516 |
│ <<log commit::Change ID: >>[38;5;5m<<log commit change_id::qpvuntsmwlqtpsluzzsnyyzlmlwvmlnu>>[39m<<log commit::>> |
| 517 |
│ <<log commit::Author : >>[38;5;3m<<log commit author name::Test User>>[39m<<log commit:: <>>[38;5;3m<<log commit author email local::test.user>><<log commit author email::@>><<log commit author email domain::example.com>>[39m<<log commit::> (>>[38;5;6m<<log commit author timestamp local format::2001-02-03 08:05:07>>[39m<<log commit::)>> |
| 518 |
│ <<log commit::Committer: >>[38;5;3m<<log commit committer name::Test User>>[39m<<log commit:: <>>[38;5;3m<<log commit committer email local::test.user>><<log commit committer email::@>><<log commit committer email domain::example.com>>[39m<<log commit::> (>>[38;5;6m<<log commit committer timestamp local format::2001-02-03 08:05:07>>[39m<<log commit::)>> |
| 519 |
│ <<log commit::>> |
| 520 |
│ [38;5;2m<<log commit empty description placeholder:: (no description set)>>[39m<<log commit::>> |
| 521 |
│ <<log commit::>> |
| 522 |
[1m[38;5;14m<<log commit node immutable::◆>>[0m <<log commit::Commit ID: >>[38;5;4m<<log commit commit_id::0000000000000000000000000000000000000000>>[39m<<log commit::>> |
| 523 |
<<log commit::Change ID: >>[38;5;5m<<log commit change_id::zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz>>[39m<<log commit::>> |
| 524 |
<<log commit::Author : >>[38;5;1m<<log commit name placeholder::(no name set)>>[39m<<log commit:: <>>[38;5;1m<<log commit email placeholder::(no email set)>>[39m<<log commit::> (>>[38;5;6m<<log commit author timestamp local format::1970-01-01 11:00:00>>[39m<<log commit::)>> |
| 525 |
<<log commit::Committer: >>[38;5;1m<<log commit name placeholder::(no name set)>>[39m<<log commit:: <>>[38;5;1m<<log commit email placeholder::(no email set)>>[39m<<log commit::> (>>[38;5;6m<<log commit committer timestamp local format::1970-01-01 11:00:00>>[39m<<log commit::)>> |
| 526 |
<<log commit::>> |
| 527 |
[38;5;2m<<log commit empty description placeholder:: (no description set)>>[39m<<log commit::>> |
| 528 |
<<log commit::>> |
| 529 |
[EOF] |
| 530 |
"); |
| 531 |
} |
| 532 |
|
| 533 |
#[test] |
| 534 |
fn test_log_evolog_divergence() { |
| 535 |
let test_env = TestEnvironment::default(); |
| 536 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 537 |
let work_dir = test_env.work_dir("repo"); |
| 538 |
|
| 539 |
work_dir.write_file("file", "foo\n"); |
| 540 |
work_dir |
| 541 |
.run_jj(["describe", "-m", "description 1"]) |
| 542 |
.success(); |
| 543 |
// No divergence |
| 544 |
let output = work_dir.run_jj(["log"]); |
| 545 |
insta::assert_snapshot!(output, @" |
| 546 |
@ qpvuntsm [email protected] 2001-02-03 08:05:08 556daeb7 |
| 547 |
│ description 1 |
| 548 |
◆ zzzzzzzz root() 00000000 |
| 549 |
[EOF] |
| 550 |
"); |
| 551 |
|
| 552 |
// Create divergence |
| 553 |
work_dir |
| 554 |
.run_jj(["describe", "-m", "description 2", "--at-operation", "@-"]) |
| 555 |
.success(); |
| 556 |
let output = work_dir.run_jj(["log"]); |
| 557 |
insta::assert_snapshot!(output, @" |
| 558 |
@ qpvuntsm/1 [email protected] 2001-02-03 08:05:08 556daeb7 (divergent) |
| 559 |
│ description 1 |
| 560 |
│ ○ qpvuntsm/0 [email protected] 2001-02-03 08:05:10 5cea51a1 (divergent) |
| 561 |
├─╯ description 2 |
| 562 |
◆ zzzzzzzz root() 00000000 |
| 563 |
[EOF] |
| 564 |
------- stderr ------- |
| 565 |
Concurrent modification detected, resolving automatically. |
| 566 |
[EOF] |
| 567 |
"); |
| 568 |
|
| 569 |
// Color |
| 570 |
let output = work_dir.run_jj(["log", "--color=always"]); |
| 571 |
insta::assert_snapshot!(output, @" |
| 572 |
[1m[38;5;2m@[0m [1m[38;5;9mq[38;5;8mpvuntsm[38;5;9m/1[39m [38;5;[email protected][39m [38;5;14m2001-02-03 08:05:08[39m [38;5;12m55[38;5;8m6daeb7[39m [38;5;9m(divergent)[39m[0m |
| 573 |
│ [1mdescription 1[0m |
| 574 |
│ ○ [1m[38;5;1mq[0m[38;5;8mpvuntsm[1m[38;5;1m/0[0m [38;5;[email protected][39m [38;5;6m2001-02-03 08:05:10[39m [1m[38;5;4m5c[0m[38;5;8mea51a1[39m [38;5;1m(divergent)[39m |
| 575 |
├─╯ description 2 |
| 576 |
[1m[38;5;14m◆[0m [1m[38;5;5mz[0m[38;5;8mzzzzzzz[39m [38;5;2mroot()[39m [1m[38;5;4m0[0m[38;5;8m0000000[39m |
| 577 |
[EOF] |
| 578 |
"); |
| 579 |
|
| 580 |
// Evolog and hidden divergent |
| 581 |
let output = work_dir.run_jj(["evolog"]); |
| 582 |
insta::assert_snapshot!(output, @" |
| 583 |
@ qpvuntsm/1 [email protected] 2001-02-03 08:05:08 556daeb7 (divergent) |
| 584 |
│ description 1 |
| 585 |
│ -- operation 30d053d9072b describe commit d0c049cd993a8d3a2e69ba6df98788e264ea9fa1 |
| 586 |
○ qpvuntsm/2 [email protected] 2001-02-03 08:05:08 d0c049cd (hidden) |
| 587 |
│ (no description set) |
| 588 |
│ -- operation 8003ebfc58c1 snapshot working copy |
| 589 |
○ qpvuntsm/3 [email protected] 2001-02-03 08:05:07 e8849ae1 (hidden) |
| 590 |
(empty) (no description set) |
| 591 |
-- operation f63ee16f9553 add workspace 'default' |
| 592 |
[EOF] |
| 593 |
"); |
| 594 |
|
| 595 |
// Colored evolog |
| 596 |
let output = work_dir.run_jj(["evolog", "--color=always"]); |
| 597 |
insta::assert_snapshot!(output, @" |
| 598 |
[1m[38;5;2m@[0m [1m[38;5;9mq[38;5;8mpvuntsm[38;5;9m/1[39m [38;5;[email protected][39m [38;5;14m2001-02-03 08:05:08[39m [38;5;12m55[38;5;8m6daeb7[39m [38;5;9m(divergent)[39m[0m |
| 599 |
│ [1mdescription 1[0m |
| 600 |
│ [38;5;8m--[39m operation [38;5;4m30d053d9072b[39m describe commit d0c049cd993a8d3a2e69ba6df98788e264ea9fa1 |
| 601 |
○ [1m[39mq[0m[38;5;8mpvuntsm[1m[39m/2[0m [38;5;[email protected][39m [38;5;6m2001-02-03 08:05:08[39m [1m[38;5;4md[0m[38;5;8m0c049cd[39m (hidden) |
| 602 |
│ [38;5;3m(no description set)[39m |
| 603 |
│ [38;5;8m--[39m operation [38;5;4m8003ebfc58c1[39m snapshot working copy |
| 604 |
○ [1m[39mq[0m[38;5;8mpvuntsm[1m[39m/3[0m [38;5;[email protected][39m [38;5;6m2001-02-03 08:05:07[39m [1m[38;5;4me[0m[38;5;8m8849ae1[39m (hidden) |
| 605 |
[38;5;2m(empty)[39m [38;5;2m(no description set)[39m |
| 606 |
[38;5;8m--[39m operation [38;5;4mf63ee16f9553[39m add workspace 'default' |
| 607 |
[EOF] |
| 608 |
"); |
| 609 |
} |
| 610 |
|
| 611 |
#[test] |
| 612 |
fn test_log_bookmarks() { |
| 613 |
let test_env = TestEnvironment::default(); |
| 614 |
test_env.add_config(r#"revset-aliases."immutable_heads()" = "none()""#); |
| 615 |
|
| 616 |
test_env.run_jj_in(".", ["git", "init", "origin"]).success(); |
| 617 |
let origin_dir = test_env.work_dir("origin"); |
| 618 |
let origin_git_repo_path = origin_dir |
| 619 |
.root() |
| 620 |
.join(".jj") |
| 621 |
.join("repo") |
| 622 |
.join("store") |
| 623 |
.join("git"); |
| 624 |
|
| 625 |
// Created some bookmarks on the remote |
| 626 |
origin_dir |
| 627 |
.run_jj(["describe", "-m=description 1"]) |
| 628 |
.success(); |
| 629 |
origin_dir |
| 630 |
.run_jj(["bookmark", "create", "-r@", "bookmark1"]) |
| 631 |
.success(); |
| 632 |
origin_dir |
| 633 |
.run_jj(["new", "root()", "-m=description 2"]) |
| 634 |
.success(); |
| 635 |
origin_dir |
| 636 |
.run_jj(["bookmark", "create", "-r@", "bookmark2", "unchanged"]) |
| 637 |
.success(); |
| 638 |
origin_dir |
| 639 |
.run_jj(["new", "root()", "-m=description 3"]) |
| 640 |
.success(); |
| 641 |
origin_dir |
| 642 |
.run_jj(["bookmark", "create", "-r@", "bookmark3"]) |
| 643 |
.success(); |
| 644 |
origin_dir.run_jj(["git", "export"]).success(); |
| 645 |
test_env |
| 646 |
.run_jj_in( |
| 647 |
".", |
| 648 |
[ |
| 649 |
"git", |
| 650 |
"clone", |
| 651 |
origin_git_repo_path.to_str().unwrap(), |
| 652 |
"local", |
| 653 |
], |
| 654 |
) |
| 655 |
.success(); |
| 656 |
let work_dir = test_env.work_dir("local"); |
| 657 |
|
| 658 |
// Track all remote bookmarks, rewrite bookmark1, move bookmark2 forward, |
| 659 |
// create conflict in bookmark3, add new-bookmark |
| 660 |
work_dir.run_jj(["bookmark", "track", "*"]).success(); |
| 661 |
work_dir |
| 662 |
.run_jj(["describe", "bookmark1", "-m", "modified bookmark1 commit"]) |
| 663 |
.success(); |
| 664 |
work_dir.run_jj(["new", "bookmark2"]).success(); |
| 665 |
work_dir |
| 666 |
.run_jj(["bookmark", "set", "bookmark2", "--to=@"]) |
| 667 |
.success(); |
| 668 |
work_dir |
| 669 |
.run_jj(["bookmark", "create", "-r@", "new-bookmark"]) |
| 670 |
.success(); |
| 671 |
work_dir |
| 672 |
.run_jj(["describe", "bookmark3", "-m=local"]) |
| 673 |
.success(); |
| 674 |
origin_dir |
| 675 |
.run_jj(["describe", "bookmark3", "-m=origin"]) |
| 676 |
.success(); |
| 677 |
origin_dir.run_jj(["git", "export"]).success(); |
| 678 |
work_dir.run_jj(["git", "fetch"]).success(); |
| 679 |
|
| 680 |
let template = r#"commit_id.short() ++ " " ++ if(bookmarks, bookmarks, "(no bookmarks)")"#; |
| 681 |
let output = work_dir.run_jj(["log", "-T", template]); |
| 682 |
insta::assert_snapshot!(output, @" |
| 683 |
@ 4bc3723efff8 bookmark2* new-bookmark |
| 684 |
○ 38a204733702 bookmark2@origin unchanged |
| 685 |
│ ○ 1c14797dac42 bookmark3?? bookmark3@origin |
| 686 |
├─╯ |
| 687 |
│ ○ 8223b15ac1f1 bookmark3?? |
| 688 |
├─╯ |
| 689 |
│ ○ a156ef717a61 bookmark1* |
| 690 |
├─╯ |
| 691 |
◆ 000000000000 (no bookmarks) |
| 692 |
[EOF] |
| 693 |
"); |
| 694 |
|
| 695 |
let template = r#"bookmarks.map(|b| separate("/", b.remote(), b.name())).join(", ")"#; |
| 696 |
let output = work_dir.run_jj(["log", "-T", template]); |
| 697 |
insta::assert_snapshot!(output, @" |
| 698 |
@ bookmark2, new-bookmark |
| 699 |
○ origin/bookmark2, unchanged |
| 700 |
│ ○ bookmark3, origin/bookmark3 |
| 701 |
├─╯ |
| 702 |
│ ○ bookmark3 |
| 703 |
├─╯ |
| 704 |
│ ○ bookmark1 |
| 705 |
├─╯ |
| 706 |
◆ |
| 707 |
[EOF] |
| 708 |
"); |
| 709 |
|
| 710 |
let template = r#"separate(" ", "L:", local_bookmarks, "R:", remote_bookmarks)"#; |
| 711 |
let output = work_dir.run_jj(["log", "-T", template]); |
| 712 |
insta::assert_snapshot!(output, @" |
| 713 |
@ L: bookmark2* new-bookmark R: |
| 714 |
○ L: unchanged R: bookmark2@origin unchanged@origin |
| 715 |
│ ○ L: bookmark3?? R: bookmark3@origin |
| 716 |
├─╯ |
| 717 |
│ ○ L: bookmark3?? R: |
| 718 |
├─╯ |
| 719 |
│ ○ L: bookmark1* R: |
| 720 |
├─╯ |
| 721 |
◆ L: R: |
| 722 |
[EOF] |
| 723 |
"); |
| 724 |
|
| 725 |
let template = r#" |
| 726 |
remote_bookmarks.map(|ref| concat( |
| 727 |
ref, |
| 728 |
if(ref.tracked(), |
| 729 |
"(+" ++ ref.tracking_ahead_count().lower() |
| 730 |
++ "/-" ++ ref.tracking_behind_count().lower() ++ ")"), |
| 731 |
)) |
| 732 |
"#; |
| 733 |
let output = work_dir.run_jj(["log", "-r::remote_bookmarks()", "-T", template]); |
| 734 |
insta::assert_snapshot!(output, @" |
| 735 |
○ bookmark3@origin(+0/-1) |
| 736 |
│ ○ bookmark2@origin(+0/-1) unchanged@origin(+0/-0) |
| 737 |
├─╯ |
| 738 |
│ ○ bookmark1@origin(+1/-1) |
| 739 |
├─╯ |
| 740 |
◆ |
| 741 |
[EOF] |
| 742 |
"); |
| 743 |
} |
| 744 |
|
| 745 |
#[test] |
| 746 |
fn test_log_tags() { |
| 747 |
let test_env = TestEnvironment::default(); |
| 748 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 749 |
let work_dir = test_env.work_dir("repo"); |
| 750 |
|
| 751 |
work_dir.run_jj(["commit", "-mcommit1"]).success(); |
| 752 |
work_dir.run_jj(["commit", "-mcommit2"]).success(); |
| 753 |
work_dir.run_jj(["tag", "set", "-r@--", "foo"]).success(); |
| 754 |
work_dir.run_jj(["tag", "set", "-r@-", "bar"]).success(); |
| 755 |
work_dir.run_jj(["git", "export"]).success(); |
| 756 |
work_dir |
| 757 |
.run_jj(["tag", "set", "--allow-move", "-r@-", "foo", "baz"]) |
| 758 |
.success(); |
| 759 |
|
| 760 |
let template = r#"commit_id.short() ++ " " ++ if(tags, tags, "(no tags)") ++ "\n""#; |
| 761 |
let output = work_dir.run_jj(["log", "-rall()", "-T", template]); |
| 762 |
insta::assert_snapshot!(output, @" |
| 763 |
@ 510df2613fc8 (no tags) |
| 764 |
◆ 3f672e728535 bar baz foo* |
| 765 |
◆ b876c5f49546 foo@git |
| 766 |
◆ 000000000000 (no tags) |
| 767 |
[EOF] |
| 768 |
"); |
| 769 |
|
| 770 |
let template = r#"separate(" ", "L:", local_tags, "R:", remote_tags) ++ "\n""#; |
| 771 |
let output = work_dir.run_jj(["log", "-rall()", "-T", template]); |
| 772 |
insta::assert_snapshot!(output, @" |
| 773 |
@ L: R: |
| 774 |
◆ L: bar baz foo* R: bar@git |
| 775 |
◆ L: R: foo@git |
| 776 |
◆ L: R: |
| 777 |
[EOF] |
| 778 |
"); |
| 779 |
} |
| 780 |
|
| 781 |
#[test] |
| 782 |
fn test_log_customize_short_id() { |
| 783 |
let test_env = TestEnvironment::default(); |
| 784 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 785 |
let work_dir = test_env.work_dir("repo"); |
| 786 |
|
| 787 |
work_dir.run_jj(["describe", "-m", "first"]).success(); |
| 788 |
|
| 789 |
// Customize both the commit and the change id |
| 790 |
let decl = "template-aliases.'format_short_id(id)'"; |
| 791 |
let output = work_dir.run_jj([ |
| 792 |
"log", |
| 793 |
"--config", |
| 794 |
&format!(r#"{decl}='id.shortest(5).prefix().upper() ++ "_" ++ id.shortest(5).rest()'"#), |
| 795 |
]); |
| 796 |
insta::assert_snapshot!(output, @" |
| 797 |
@ Q_pvun [email protected] 2001-02-03 08:05:08 6_8a50 |
| 798 |
│ (empty) first |
| 799 |
◆ Z_zzzz root() 0_0000 |
| 800 |
[EOF] |
| 801 |
"); |
| 802 |
|
| 803 |
// Customize only the change id |
| 804 |
let output = work_dir.run_jj([ |
| 805 |
"log", |
| 806 |
"--config=template-aliases.'format_short_change_id(id)'='format_short_id(id).upper()'", |
| 807 |
]); |
| 808 |
insta::assert_snapshot!(output, @" |
| 809 |
@ QPVUNTSM [email protected] 2001-02-03 08:05:08 68a50538 |
| 810 |
│ (empty) first |
| 811 |
◆ ZZZZZZZZ root() 00000000 |
| 812 |
[EOF] |
| 813 |
"); |
| 814 |
} |
| 815 |
|
| 816 |
#[test] |
| 817 |
fn test_log_immutable() { |
| 818 |
let test_env = TestEnvironment::default(); |
| 819 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 820 |
let work_dir = test_env.work_dir("repo"); |
| 821 |
work_dir.run_jj(["new", "-mA", "root()"]).success(); |
| 822 |
work_dir.run_jj(["new", "-mB"]).success(); |
| 823 |
work_dir |
| 824 |
.run_jj(["bookmark", "create", "-r@", "main"]) |
| 825 |
.success(); |
| 826 |
work_dir.run_jj(["new", "-mC"]).success(); |
| 827 |
work_dir.run_jj(["new", "-mD", "root()"]).success(); |
| 828 |
|
| 829 |
let template = r#" |
| 830 |
separate(" ", |
| 831 |
description.first_line(), |
| 832 |
bookmarks, |
| 833 |
if(immutable, "[immutable]"), |
| 834 |
) ++ "\n" |
| 835 |
"#; |
| 836 |
|
| 837 |
test_env.add_config("revset-aliases.'immutable_heads()' = 'main'"); |
| 838 |
let output = work_dir.run_jj(["log", "-r::", "-T", template]); |
| 839 |
insta::assert_snapshot!(output, @" |
| 840 |
@ D |
| 841 |
│ ○ C |
| 842 |
│ ◆ B main [immutable] |
| 843 |
│ ◆ A [immutable] |
| 844 |
├─╯ |
| 845 |
◆ [immutable] |
| 846 |
[EOF] |
| 847 |
"); |
| 848 |
|
| 849 |
// Suppress error that could be detected earlier |
| 850 |
test_env.add_config("revsets.short-prefixes = ''"); |
| 851 |
|
| 852 |
test_env.add_config("revset-aliases.'immutable_heads()' = 'unknown_fn()'"); |
| 853 |
let output = work_dir.run_jj(["log", "-r::", "-T", template]); |
| 854 |
insta::assert_snapshot!(output, @" |
| 855 |
------- stderr ------- |
| 856 |
Config error: Invalid `revset-aliases.immutable_heads()` |
| 857 |
Caused by: --> 1:1 |
| 858 |
| |
| 859 |
1 | unknown_fn() |
| 860 |
| ^--------^ |
| 861 |
| |
| 862 |
= Function `unknown_fn` doesn't exist |
| 863 |
For help, see https://docs.jj-vcs.dev/latest/config/ or use `jj help -k config`. |
| 864 |
[EOF] |
| 865 |
[exit status: 1] |
| 866 |
"); |
| 867 |
|
| 868 |
test_env.add_config("revset-aliases.'immutable_heads()' = 'unknown_symbol'"); |
| 869 |
let output = work_dir.run_jj(["log", "-r::", "-T", template]); |
| 870 |
insta::assert_snapshot!(output, @r#" |
| 871 |
------- stderr ------- |
| 872 |
Error: Failed to parse template: Failed to evaluate revset |
| 873 |
Caused by: |
| 874 |
1: --> 5:10 |
| 875 |
| |
| 876 |
5 | if(immutable, "[immutable]"), |
| 877 |
| ^-------^ |
| 878 |
| |
| 879 |
= Failed to evaluate revset |
| 880 |
2: Revision `unknown_symbol` doesn't exist |
| 881 |
[EOF] |
| 882 |
[exit status: 1] |
| 883 |
"#); |
| 884 |
} |
| 885 |
|
| 886 |
#[test] |
| 887 |
fn test_log_contained_in() { |
| 888 |
let test_env = TestEnvironment::default(); |
| 889 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 890 |
let work_dir = test_env.work_dir("repo"); |
| 891 |
work_dir.run_jj(["new", "-mA", "root()"]).success(); |
| 892 |
work_dir.run_jj(["new", "-mB"]).success(); |
| 893 |
work_dir |
| 894 |
.run_jj(["bookmark", "create", "-r@", "main"]) |
| 895 |
.success(); |
| 896 |
work_dir.run_jj(["new", "-mC"]).success(); |
| 897 |
work_dir.run_jj(["new", "-mD", "root()"]).success(); |
| 898 |
|
| 899 |
let template_for_revset = |revset: &str| { |
| 900 |
format!( |
| 901 |
r#" |
| 902 |
separate(" ", |
| 903 |
description.first_line(), |
| 904 |
bookmarks, |
| 905 |
if(self.contained_in("{revset}"), "[contained_in]"), |
| 906 |
) ++ "\n" |
| 907 |
"# |
| 908 |
) |
| 909 |
}; |
| 910 |
|
| 911 |
let output = work_dir.run_jj(["log", "-r::", "-T", &template_for_revset("subject(A)::")]); |
| 912 |
insta::assert_snapshot!(output, @" |
| 913 |
@ D |
| 914 |
│ ○ C [contained_in] |
| 915 |
│ ○ B main [contained_in] |
| 916 |
│ ○ A [contained_in] |
| 917 |
├─╯ |
| 918 |
◆ |
| 919 |
[EOF] |
| 920 |
"); |
| 921 |
|
| 922 |
let output = work_dir.run_jj([ |
| 923 |
"log", |
| 924 |
"-r::", |
| 925 |
"-T", |
| 926 |
&template_for_revset(r#"visible_heads()"#), |
| 927 |
]); |
| 928 |
insta::assert_snapshot!(output, @" |
| 929 |
@ D [contained_in] |
| 930 |
│ ○ C [contained_in] |
| 931 |
│ ○ B main |
| 932 |
│ ○ A |
| 933 |
├─╯ |
| 934 |
◆ |
| 935 |
[EOF] |
| 936 |
"); |
| 937 |
|
| 938 |
// Suppress error that could be detected earlier |
| 939 |
let output = work_dir.run_jj(["log", "-r::", "-T", &template_for_revset("unknown_fn()")]); |
| 940 |
insta::assert_snapshot!(output, @r#" |
| 941 |
------- stderr ------- |
| 942 |
Error: Failed to parse template: In revset expression |
| 943 |
Caused by: |
| 944 |
1: --> 5:28 |
| 945 |
| |
| 946 |
5 | if(self.contained_in("unknown_fn()"), "[contained_in]"), |
| 947 |
| ^------------^ |
| 948 |
| |
| 949 |
= In revset expression |
| 950 |
2: --> 1:1 |
| 951 |
| |
| 952 |
1 | unknown_fn() |
| 953 |
| ^--------^ |
| 954 |
| |
| 955 |
= Function `unknown_fn` doesn't exist |
| 956 |
[EOF] |
| 957 |
[exit status: 1] |
| 958 |
"#); |
| 959 |
|
| 960 |
let output = work_dir.run_jj(["log", "-r::", "-T", &template_for_revset("author(x:'y')")]); |
| 961 |
insta::assert_snapshot!(output, @r#" |
| 962 |
------- stderr ------- |
| 963 |
Error: Failed to parse template: In revset expression |
| 964 |
Caused by: |
| 965 |
1: --> 5:28 |
| 966 |
| |
| 967 |
5 | if(self.contained_in("author(x:'y')"), "[contained_in]"), |
| 968 |
| ^-------------^ |
| 969 |
| |
| 970 |
= In revset expression |
| 971 |
2: --> 1:8 |
| 972 |
| |
| 973 |
1 | author(x:'y') |
| 974 |
| ^---^ |
| 975 |
| |
| 976 |
= Invalid string pattern |
| 977 |
3: Invalid string pattern kind `x:` |
| 978 |
Hint: Try prefixing with one of `exact:`, `glob:`, `regex:`, `substring:`, or one of these with `-i` suffix added (e.g. `glob-i:`) for case-insensitive matching |
| 979 |
[EOF] |
| 980 |
[exit status: 1] |
| 981 |
"#); |
| 982 |
|
| 983 |
let output = work_dir.run_jj(["log", "-r::", "-T", &template_for_revset("maine")]); |
| 984 |
insta::assert_snapshot!(output, @r#" |
| 985 |
------- stderr ------- |
| 986 |
Error: Failed to parse template: Failed to evaluate revset |
| 987 |
Caused by: |
| 988 |
1: --> 5:28 |
| 989 |
| |
| 990 |
5 | if(self.contained_in("maine"), "[contained_in]"), |
| 991 |
| ^-----^ |
| 992 |
| |
| 993 |
= Failed to evaluate revset |
| 994 |
2: Revision `maine` doesn't exist |
| 995 |
Hint: Did you mean `main`? |
| 996 |
[EOF] |
| 997 |
[exit status: 1] |
| 998 |
"#); |
| 999 |
} |
| 1000 |
|
| 1001 |
#[test] |
| 1002 |
fn test_short_prefix_in_transaction() { |
| 1003 |
let test_env = TestEnvironment::default(); |
| 1004 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 1005 |
let work_dir = test_env.work_dir("repo"); |
| 1006 |
|
| 1007 |
test_env.add_config(r#" |
| 1008 |
[revsets] |
| 1009 |
log = '::subject(test)' |
| 1010 |
|
| 1011 |
[templates] |
| 1012 |
log = 'summary ++ "\n"' |
| 1013 |
commit_summary = 'summary' |
| 1014 |
|
| 1015 |
[template-aliases] |
| 1016 |
'format_id(id)' = 'id.shortest(12).prefix() ++ "[" ++ id.shortest(12).rest() ++ "]"' |
| 1017 |
'summary' = 'separate(" ", format_id(change_id), format_id(commit_id), description.first_line())' |
| 1018 |
"#); |
| 1019 |
|
| 1020 |
work_dir.write_file("file", "original file\n"); |
| 1021 |
work_dir.run_jj(["describe", "-m", "initial"]).success(); |
| 1022 |
|
| 1023 |
// Create a chain of 5 commits |
| 1024 |
for i in 0..5 { |
| 1025 |
work_dir |
| 1026 |
.run_jj(["new", "-m", &format!("commit{i}")]) |
| 1027 |
.success(); |
| 1028 |
work_dir.write_file("file", format!("file {i}\n")); |
| 1029 |
} |
| 1030 |
// Create 2^4 duplicates of the chain |
| 1031 |
for _ in 0..4 { |
| 1032 |
work_dir.run_jj(["duplicate", "subject(commit*)"]).success(); |
| 1033 |
} |
| 1034 |
|
| 1035 |
// Short prefix should be used for commit summary inside the transaction |
| 1036 |
let parent_id = "c0b41"; // Force id lookup to build index before mutation. |
| 1037 |
// If the cached index wasn't invalidated, the |
| 1038 |
// newly created commit wouldn't be found in it. |
| 1039 |
let output = work_dir.run_jj(["new", parent_id, "--no-edit", "-m", "test"]); |
| 1040 |
insta::assert_snapshot!(output, @" |
| 1041 |
------- stderr ------- |
| 1042 |
Created new commit km[kuslswpqwq] a[5d12a825adf] test |
| 1043 |
[EOF] |
| 1044 |
"); |
| 1045 |
|
| 1046 |
// Should match log's short prefixes |
| 1047 |
let output = work_dir.run_jj(["log", "--no-graph"]); |
| 1048 |
insta::assert_snapshot!(output, @" |
| 1049 |
km[kuslswpqwq] a[5d12a825adf] test |
| 1050 |
y[qosqzytrlsw] c0[b41b9a1b34] commit4 |
| 1051 |
r[oyxmykxtrkr] 1[2124aa50a07] commit3 |
| 1052 |
m[zvwutvlkqwt] c7[673aedfb82] commit2 |
| 1053 |
zs[uskulnrvyr] 4[36497fbfb9d] commit1 |
| 1054 |
kk[mpptxzrspx] d[70e8b9aa12b] commit0 |
| 1055 |
q[pvuntsmwlqt] 8[216f646c36d] initial |
| 1056 |
zz[zzzzzzzzzz] 0[00000000000] |
| 1057 |
[EOF] |
| 1058 |
"); |
| 1059 |
|
| 1060 |
test_env.add_config(r#"revsets.short-prefixes = """#); |
| 1061 |
|
| 1062 |
let output = work_dir.run_jj(["log", "--no-graph"]); |
| 1063 |
insta::assert_snapshot!(output, @" |
| 1064 |
kmk[uslswpqwq] a5[d12a825adf] test |
| 1065 |
yq[osqzytrlsw] c0b[41b9a1b34] commit4 |
| 1066 |
ro[yxmykxtrkr] 121[24aa50a07] commit3 |
| 1067 |
mz[vwutvlkqwt] c7[673aedfb82] commit2 |
| 1068 |
zs[uskulnrvyr] 43[6497fbfb9d] commit1 |
| 1069 |
kk[mpptxzrspx] d7[0e8b9aa12b] commit0 |
| 1070 |
qp[vuntsmwlqt] 82[16f646c36d] initial |
| 1071 |
zz[zzzzzzzzzz] 00[0000000000] |
| 1072 |
[EOF] |
| 1073 |
"); |
| 1074 |
} |
| 1075 |
|
| 1076 |
#[test] |
| 1077 |
fn test_log_diff_predefined_formats() -> TestResult { |
| 1078 |
let test_env = TestEnvironment::default(); |
| 1079 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 1080 |
let work_dir = test_env.work_dir("repo"); |
| 1081 |
|
| 1082 |
work_dir.write_file("file1", "a\nb\n"); |
| 1083 |
work_dir.write_file("file2", "a\n"); |
| 1084 |
work_dir.write_file("rename-source", "rename"); |
| 1085 |
work_dir.run_jj(["new"]).success(); |
| 1086 |
work_dir.write_file("file1", "a\nb\nc\n"); |
| 1087 |
work_dir.write_file("file2", "b\nc\n"); |
| 1088 |
std::fs::rename( |
| 1089 |
work_dir.root().join("rename-source"), |
| 1090 |
work_dir.root().join("rename-target"), |
| 1091 |
)?; |
| 1092 |
|
| 1093 |
let template = r#" |
| 1094 |
concat( |
| 1095 |
"=== color_words ===\n", |
| 1096 |
diff.color_words(), |
| 1097 |
"=== git ===\n", |
| 1098 |
diff.git(), |
| 1099 |
"=== stat ===\n", |
| 1100 |
diff.stat(80), |
| 1101 |
"=== summary ===\n", |
| 1102 |
diff.summary(), |
| 1103 |
) |
| 1104 |
"#; |
| 1105 |
|
| 1106 |
// color, without paths |
| 1107 |
let output = work_dir.run_jj(["log", "--no-graph", "--color=always", "-r@", "-T", template]); |
| 1108 |
insta::assert_snapshot!(output, @" |
| 1109 |
=== color_words === |
| 1110 |
[38;5;3mModified regular file file1:[39m |
| 1111 |
[2m[38;5;1m 1[0m [2m[38;5;2m 1[0m: a |
| 1112 |
[2m[38;5;1m 2[0m [2m[38;5;2m 2[0m: b |
| 1113 |
[38;5;2m 3[39m: [4m[38;5;2mc[24m[39m |
| 1114 |
[38;5;3mModified regular file file2:[39m |
| 1115 |
[38;5;1m 1[39m [38;5;2m 1[39m: [4m[38;5;1ma[38;5;2mb[24m[39m |
| 1116 |
[38;5;2m 2[39m: [4m[38;5;2mc[24m[39m |
| 1117 |
[38;5;3mModified regular file rename-target (rename-source => rename-target):[39m |
| 1118 |
=== git === |
| 1119 |
[1mdiff --git a/file1 b/file1[0m |
| 1120 |
[1mindex 422c2b7ab3..de980441c3 100644[0m |
| 1121 |
[1m--- a/file1[0m |
| 1122 |
[1m+++ b/file1[0m |
| 1123 |
[38;5;6m@@ -1,2 +1,3 @@[39m |
| 1124 |
a |
| 1125 |
b |
| 1126 |
[38;5;2m+[4mc[24m[39m |
| 1127 |
[1mdiff --git a/file2 b/file2[0m |
| 1128 |
[1mindex 7898192261..9ddeb5c484 100644[0m |
| 1129 |
[1m--- a/file2[0m |
| 1130 |
[1m+++ b/file2[0m |
| 1131 |
[38;5;6m@@ -1,1 +1,2 @@[39m |
| 1132 |
[38;5;1m-[4ma[24m[39m |
| 1133 |
[38;5;2m+[4mb[24m[39m |
| 1134 |
[38;5;2m+[4mc[24m[39m |
| 1135 |
[1mdiff --git a/rename-source b/rename-target[0m |
| 1136 |
[1mrename from rename-source[0m |
| 1137 |
[1mrename to rename-target[0m |
| 1138 |
=== stat === |
| 1139 |
file1 | 1 [38;5;2m+[38;5;1m[39m |
| 1140 |
file2 | 3 [38;5;2m++[38;5;1m-[39m |
| 1141 |
{rename-source => rename-target} | 0[38;5;1m[39m |
| 1142 |
3 files changed, 3 insertions(+), 1 deletion(-) |
| 1143 |
=== summary === |
| 1144 |
[38;5;6mM file1[39m |
| 1145 |
[38;5;6mM file2[39m |
| 1146 |
[38;5;6mR {rename-source => rename-target}[39m |
| 1147 |
[EOF] |
| 1148 |
"); |
| 1149 |
|
| 1150 |
// color labels |
| 1151 |
let output = work_dir.run_jj(["log", "--no-graph", "--color=debug", "-r@", "-T", template]); |
| 1152 |
insta::assert_snapshot!(output, @" |
| 1153 |
<<log commit::=== color_words ===>> |
| 1154 |
[38;5;3m<<log commit diff color_words header::Modified regular file file1:>>[39m |
| 1155 |
[2m[38;5;1m<<log commit diff color_words context removed line_number:: 1>>[0m<<log commit diff color_words context:: >>[2m[38;5;2m<<log commit diff color_words context added line_number:: 1>>[0m<<log commit diff color_words context::: a>> |
| 1156 |
[2m[38;5;1m<<log commit diff color_words context removed line_number:: 2>>[0m<<log commit diff color_words context:: >>[2m[38;5;2m<<log commit diff color_words context added line_number:: 2>>[0m<<log commit diff color_words context::: b>> |
| 1157 |
<<log commit diff color_words:: >>[38;5;2m<<log commit diff color_words added line_number:: 3>>[39m<<log commit diff color_words::: >>[4m[38;5;2m<<log commit diff color_words added token::c>>[24m[39m |
| 1158 |
[38;5;3m<<log commit diff color_words header::Modified regular file file2:>>[39m |
| 1159 |
[38;5;1m<<log commit diff color_words removed line_number:: 1>>[39m<<log commit diff color_words:: >>[38;5;2m<<log commit diff color_words added line_number:: 1>>[39m<<log commit diff color_words::: >>[4m[38;5;1m<<log commit diff color_words removed token::a>>[38;5;2m<<log commit diff color_words added token::b>>[24m[39m<<log commit diff color_words::>> |
| 1160 |
<<log commit diff color_words:: >>[38;5;2m<<log commit diff color_words added line_number:: 2>>[39m<<log commit diff color_words::: >>[4m[38;5;2m<<log commit diff color_words added token::c>>[24m[39m |
| 1161 |
[38;5;3m<<log commit diff color_words header::Modified regular file rename-target (rename-source => rename-target):>>[39m |
| 1162 |
<<log commit::=== git ===>> |
| 1163 |
[1m<<log commit diff git file_header::diff --git a/file1 b/file1>>[0m |
| 1164 |
[1m<<log commit diff git file_header::index 422c2b7ab3..de980441c3 100644>>[0m |
| 1165 |
[1m<<log commit diff git file_header::--- a/file1>>[0m |
| 1166 |
[1m<<log commit diff git file_header::+++ b/file1>>[0m |
| 1167 |
[38;5;6m<<log commit diff git hunk_header::@@ -1,2 +1,3 @@>>[39m |
| 1168 |
<<log commit diff git context:: a>> |
| 1169 |
<<log commit diff git context:: b>> |
| 1170 |
[38;5;2m<<log commit diff git added::+>>[4m<<log commit diff git added token::c>>[24m[39m |
| 1171 |
[1m<<log commit diff git file_header::diff --git a/file2 b/file2>>[0m |
| 1172 |
[1m<<log commit diff git file_header::index 7898192261..9ddeb5c484 100644>>[0m |
| 1173 |
[1m<<log commit diff git file_header::--- a/file2>>[0m |
| 1174 |
[1m<<log commit diff git file_header::+++ b/file2>>[0m |
| 1175 |
[38;5;6m<<log commit diff git hunk_header::@@ -1,1 +1,2 @@>>[39m |
| 1176 |
[38;5;1m<<log commit diff git removed::->>[4m<<log commit diff git removed token::a>>[24m<<log commit diff git removed::>>[39m |
| 1177 |
[38;5;2m<<log commit diff git added::+>>[4m<<log commit diff git added token::b>>[24m<<log commit diff git added::>>[39m |
| 1178 |
[38;5;2m<<log commit diff git added::+>>[4m<<log commit diff git added token::c>>[24m[39m |
| 1179 |
[1m<<log commit diff git file_header::diff --git a/rename-source b/rename-target>>[0m |
| 1180 |
[1m<<log commit diff git file_header::rename from rename-source>>[0m |
| 1181 |
[1m<<log commit diff git file_header::rename to rename-target>>[0m |
| 1182 |
<<log commit::=== stat ===>> |
| 1183 |
<<log commit diff stat::file1 | 1 >>[38;5;2m<<log commit diff stat added::+>>[38;5;1m<<log commit diff stat removed::>>[39m |
| 1184 |
<<log commit diff stat::file2 | 3 >>[38;5;2m<<log commit diff stat added::++>>[38;5;1m<<log commit diff stat removed::->>[39m |
| 1185 |
<<log commit diff stat::{rename-source => rename-target} | 0>>[38;5;1m<<log commit diff stat removed::>>[39m |
| 1186 |
<<log commit diff stat stat-summary::3 files changed, 3 insertions(+), 1 deletion(-)>> |
| 1187 |
<<log commit::=== summary ===>> |
| 1188 |
[38;5;6m<<log commit diff summary modified::M file1>>[39m |
| 1189 |
[38;5;6m<<log commit diff summary modified::M file2>>[39m |
| 1190 |
[38;5;6m<<log commit diff summary renamed::R {rename-source => rename-target}>>[39m |
| 1191 |
[EOF] |
| 1192 |
"); |
| 1193 |
|
| 1194 |
// cwd != workspace root |
| 1195 |
let output = test_env.run_jj_in(".", ["log", "-Rrepo", "--no-graph", "-r@", "-T", template]); |
| 1196 |
insta::assert_snapshot!(output.normalize_backslash(), @" |
| 1197 |
=== color_words === |
| 1198 |
Modified regular file repo/file1: |
| 1199 |
1 1: a |
| 1200 |
2 2: b |
| 1201 |
3: c |
| 1202 |
Modified regular file repo/file2: |
| 1203 |
1 : a |
| 1204 |
1: b |
| 1205 |
2: c |
| 1206 |
Modified regular file repo/rename-target (repo/rename-source => repo/rename-target): |
| 1207 |
=== git === |
| 1208 |
diff --git a/file1 b/file1 |
| 1209 |
index 422c2b7ab3..de980441c3 100644 |
| 1210 |
--- a/file1 |
| 1211 |
+++ b/file1 |
| 1212 |
@@ -1,2 +1,3 @@ |
| 1213 |
a |
| 1214 |
b |
| 1215 |
+c |
| 1216 |
diff --git a/file2 b/file2 |
| 1217 |
index 7898192261..9ddeb5c484 100644 |
| 1218 |
--- a/file2 |
| 1219 |
+++ b/file2 |
| 1220 |
@@ -1,1 +1,2 @@ |
| 1221 |
-a |
| 1222 |
+b |
| 1223 |
+c |
| 1224 |
diff --git a/rename-source b/rename-target |
| 1225 |
rename from rename-source |
| 1226 |
rename to rename-target |
| 1227 |
=== stat === |
| 1228 |
repo/file1 | 1 + |
| 1229 |
repo/file2 | 3 ++- |
| 1230 |
repo/{rename-source => rename-target} | 0 |
| 1231 |
3 files changed, 3 insertions(+), 1 deletion(-) |
| 1232 |
=== summary === |
| 1233 |
M repo/file1 |
| 1234 |
M repo/file2 |
| 1235 |
R repo/{rename-source => rename-target} |
| 1236 |
[EOF] |
| 1237 |
"); |
| 1238 |
|
| 1239 |
// with non-default config |
| 1240 |
std::fs::write( |
| 1241 |
test_env.env_root().join("config-good.toml"), |
| 1242 |
indoc! {" |
| 1243 |
diff.color-words.context = 0 |
| 1244 |
diff.color-words.max-inline-alternation = 0 |
| 1245 |
diff.git.context = 1 |
| 1246 |
"}, |
| 1247 |
)?; |
| 1248 |
let output = work_dir.run_jj([ |
| 1249 |
"log", |
| 1250 |
"--config-file=../config-good.toml", |
| 1251 |
"--no-graph", |
| 1252 |
"-r@", |
| 1253 |
"-T", |
| 1254 |
template, |
| 1255 |
]); |
| 1256 |
insta::assert_snapshot!(output, @" |
| 1257 |
=== color_words === |
| 1258 |
Modified regular file file1: |
| 1259 |
... |
| 1260 |
3: c |
| 1261 |
Modified regular file file2: |
| 1262 |
1 : a |
| 1263 |
1: b |
| 1264 |
2: c |
| 1265 |
Modified regular file rename-target (rename-source => rename-target): |
| 1266 |
=== git === |
| 1267 |
diff --git a/file1 b/file1 |
| 1268 |
index 422c2b7ab3..de980441c3 100644 |
| 1269 |
--- a/file1 |
| 1270 |
+++ b/file1 |
| 1271 |
@@ -2,1 +2,2 @@ |
| 1272 |
b |
| 1273 |
+c |
| 1274 |
diff --git a/file2 b/file2 |
| 1275 |
index 7898192261..9ddeb5c484 100644 |
| 1276 |
--- a/file2 |
| 1277 |
+++ b/file2 |
| 1278 |
@@ -1,1 +1,2 @@ |
| 1279 |
-a |
| 1280 |
+b |
| 1281 |
+c |
| 1282 |
diff --git a/rename-source b/rename-target |
| 1283 |
rename from rename-source |
| 1284 |
rename to rename-target |
| 1285 |
=== stat === |
| 1286 |
file1 | 1 + |
| 1287 |
file2 | 3 ++- |
| 1288 |
{rename-source => rename-target} | 0 |
| 1289 |
3 files changed, 3 insertions(+), 1 deletion(-) |
| 1290 |
=== summary === |
| 1291 |
M file1 |
| 1292 |
M file2 |
| 1293 |
R {rename-source => rename-target} |
| 1294 |
[EOF] |
| 1295 |
"); |
| 1296 |
|
| 1297 |
// bad config |
| 1298 |
std::fs::write( |
| 1299 |
test_env.env_root().join("config-bad.toml"), |
| 1300 |
"diff.git.context = 'not an integer'\n", |
| 1301 |
)?; |
| 1302 |
let output = work_dir.run_jj([ |
| 1303 |
"log", |
| 1304 |
"--config-file=../config-bad.toml", |
| 1305 |
"-Tself.diff().git()", |
| 1306 |
]); |
| 1307 |
insta::assert_snapshot!(output, @r#" |
| 1308 |
------- stderr ------- |
| 1309 |
Error: Failed to parse template: Failed to load diff settings |
| 1310 |
Caused by: |
| 1311 |
1: --> 1:13 |
| 1312 |
| |
| 1313 |
1 | self.diff().git() |
| 1314 |
| ^-^ |
| 1315 |
| |
| 1316 |
= Failed to load diff settings |
| 1317 |
2: Invalid type or value for diff.git.context |
| 1318 |
3: invalid type: string "not an integer", expected usize |
| 1319 |
|
| 1320 |
Hint: Check the config file: ../config-bad.toml |
| 1321 |
[EOF] |
| 1322 |
[exit status: 1] |
| 1323 |
"#); |
| 1324 |
|
| 1325 |
// color_words() with parameters |
| 1326 |
let template = "self.diff('file1').color_words(0)"; |
| 1327 |
let output = work_dir.run_jj(["log", "--no-graph", "-r@", "-T", template]); |
| 1328 |
insta::assert_snapshot!(output, @" |
| 1329 |
Modified regular file file1: |
| 1330 |
... |
| 1331 |
3: c |
| 1332 |
[EOF] |
| 1333 |
"); |
| 1334 |
|
| 1335 |
// git() with parameters |
| 1336 |
let template = "self.diff('file1').git(1)"; |
| 1337 |
let output = work_dir.run_jj(["log", "--no-graph", "-r@", "-T", template]); |
| 1338 |
insta::assert_snapshot!(output, @" |
| 1339 |
diff --git a/file1 b/file1 |
| 1340 |
index 422c2b7ab3..de980441c3 100644 |
| 1341 |
--- a/file1 |
| 1342 |
+++ b/file1 |
| 1343 |
@@ -2,1 +2,2 @@ |
| 1344 |
b |
| 1345 |
+c |
| 1346 |
[EOF] |
| 1347 |
"); |
| 1348 |
|
| 1349 |
// custom template with files() |
| 1350 |
let template = indoc! {r#" |
| 1351 |
concat( |
| 1352 |
"=== " ++ commit_id.short() ++ " ===\n", |
| 1353 |
diff.files().map(|e| separate(" ", |
| 1354 |
e.path(), |
| 1355 |
"[" ++ e.status() ++ "]", |
| 1356 |
"source=" ++ e.source().path() ++ " [" ++ e.source().file_type() ++ "]", |
| 1357 |
"target=" ++ e.target().path() ++ " [" ++ e.target().file_type() ++ "]", |
| 1358 |
) ++ "\n").join(""), |
| 1359 |
"* " ++ separate(" ", |
| 1360 |
if(diff.files(), "non-empty", "empty"), |
| 1361 |
"len=" ++ diff.files().len(), |
| 1362 |
) ++ "\n", |
| 1363 |
) |
| 1364 |
"#}; |
| 1365 |
let output = work_dir.run_jj(["log", "--no-graph", "-T", template]); |
| 1366 |
insta::assert_snapshot!(output, @" |
| 1367 |
=== d9ea8f447a3b === |
| 1368 |
file1 [modified] source=file1 [file] target=file1 [file] |
| 1369 |
file2 [modified] source=file2 [file] target=file2 [file] |
| 1370 |
rename-target [renamed] source=rename-source [file] target=rename-target [file] |
| 1371 |
* non-empty len=3 |
| 1372 |
=== 20bc00d202c2 === |
| 1373 |
file1 [added] source=file1 [] target=file1 [file] |
| 1374 |
file2 [added] source=file2 [] target=file2 [file] |
| 1375 |
rename-source [added] source=rename-source [] target=rename-source [file] |
| 1376 |
* non-empty len=3 |
| 1377 |
=== 000000000000 === |
| 1378 |
* empty len=0 |
| 1379 |
[EOF] |
| 1380 |
"); |
| 1381 |
|
| 1382 |
// custom diff stat template |
| 1383 |
let template = indoc! {r#" |
| 1384 |
concat( |
| 1385 |
"=== " ++ commit_id.short() ++ " ===\n", |
| 1386 |
"* " ++ separate(" ", |
| 1387 |
"total_added=" ++ diff.stat().total_added(), |
| 1388 |
"total_removed=" ++ diff.stat().total_removed(), |
| 1389 |
) ++ "\n", |
| 1390 |
) |
| 1391 |
"#}; |
| 1392 |
let output = work_dir.run_jj(["log", "--no-graph", "-T", template]); |
| 1393 |
insta::assert_snapshot!(output, @" |
| 1394 |
=== d9ea8f447a3b === |
| 1395 |
* total_added=3 total_removed=1 |
| 1396 |
=== 20bc00d202c2 === |
| 1397 |
* total_added=4 total_removed=0 |
| 1398 |
=== 000000000000 === |
| 1399 |
* total_added=0 total_removed=0 |
| 1400 |
[EOF] |
| 1401 |
"); |
| 1402 |
Ok(()) |
| 1403 |
} |
| 1404 |
|
| 1405 |
#[test] |
| 1406 |
fn test_log_diff_path_display() { |
| 1407 |
let test_env = TestEnvironment::default(); |
| 1408 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 1409 |
let work_dir = test_env.work_dir("repo"); |
| 1410 |
|
| 1411 |
// Create a structure with nested directories. |
| 1412 |
work_dir.create_dir("src"); |
| 1413 |
work_dir.create_dir("src/old"); |
| 1414 |
work_dir.create_dir("src/new"); |
| 1415 |
work_dir.write_file("src/old/file.rs", "content"); |
| 1416 |
work_dir.write_file("src/common.rs", "content"); |
| 1417 |
work_dir.write_file("top.txt", "content"); |
| 1418 |
work_dir.run_jj(["commit", "-m", "initial"]).success(); |
| 1419 |
|
| 1420 |
// Rename within nested directory (common prefix/suffix). |
| 1421 |
work_dir.write_file("src/new/file.rs", "content"); |
| 1422 |
work_dir.remove_file("src/old/file.rs"); |
| 1423 |
work_dir.run_jj(["commit", "-m", "rename nested"]).success(); |
| 1424 |
|
| 1425 |
// Rename at top level. |
| 1426 |
work_dir.write_file("renamed.txt", "content"); |
| 1427 |
work_dir.remove_file("top.txt"); |
| 1428 |
work_dir.run_jj(["commit", "-m", "rename top"]).success(); |
| 1429 |
|
| 1430 |
// Test display_diff_path shows compact format for renames. |
| 1431 |
let template = indoc! {r#" |
| 1432 |
concat( |
| 1433 |
"=== " ++ description.first_line() ++ " ===\n", |
| 1434 |
"--- files() ---\n", |
| 1435 |
diff.files().map(|e| |
| 1436 |
e.display_diff_path() ++ " [" ++ e.status() ++ "]\n" |
| 1437 |
).join(""), |
| 1438 |
"--- stat().files() ---\n", |
| 1439 |
diff.stat().files().map(|e| |
| 1440 |
e.display_diff_path() ++ " [" ++ e.status() ++ "]\n" |
| 1441 |
).join(""), |
| 1442 |
) |
| 1443 |
"#}; |
| 1444 |
let output = work_dir.run_jj(["log", "--no-graph", "-r", "::@- & ~root()", "-T", template]); |
| 1445 |
insta::assert_snapshot!(output.normalize_backslash(), @" |
| 1446 |
=== rename top === |
| 1447 |
--- files() --- |
| 1448 |
{top.txt => renamed.txt} [renamed] |
| 1449 |
--- stat().files() --- |
| 1450 |
{top.txt => renamed.txt} [renamed] |
| 1451 |
=== rename nested === |
| 1452 |
--- files() --- |
| 1453 |
src/{old => new}/file.rs [renamed] |
| 1454 |
--- stat().files() --- |
| 1455 |
src/{old => new}/file.rs [renamed] |
| 1456 |
=== initial === |
| 1457 |
--- files() --- |
| 1458 |
src/common.rs [added] |
| 1459 |
src/old/file.rs [added] |
| 1460 |
top.txt [added] |
| 1461 |
--- stat().files() --- |
| 1462 |
src/common.rs [added] |
| 1463 |
src/old/file.rs [added] |
| 1464 |
top.txt [added] |
| 1465 |
[EOF] |
| 1466 |
"); |
| 1467 |
} |
| 1468 |
|
| 1469 |
#[test] |
| 1470 |
fn test_file_list_entries() { |
| 1471 |
let test_env = TestEnvironment::default(); |
| 1472 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 1473 |
let work_dir = test_env.work_dir("repo"); |
| 1474 |
|
| 1475 |
work_dir.create_dir("dir"); |
| 1476 |
work_dir.write_file("dir/file", "content1"); |
| 1477 |
work_dir.write_file("exec-file", "content1"); |
| 1478 |
work_dir.write_file("conflict-exec-file", "content1"); |
| 1479 |
work_dir.write_file("conflict-file", "content1"); |
| 1480 |
work_dir |
| 1481 |
.run_jj(["file", "chmod", "x", "exec-file", "conflict-exec-file"]) |
| 1482 |
.success(); |
| 1483 |
|
| 1484 |
work_dir.run_jj(["new", "root()"]).success(); |
| 1485 |
work_dir.write_file("conflict-exec-file", "content2"); |
| 1486 |
work_dir.write_file("conflict-file", "content2"); |
| 1487 |
work_dir |
| 1488 |
.run_jj(["file", "chmod", "x", "conflict-exec-file"]) |
| 1489 |
.success(); |
| 1490 |
|
| 1491 |
work_dir.run_jj(["new", "visible_heads()"]).success(); |
| 1492 |
|
| 1493 |
let template = r#"if(files, files.map(|e| e.path()), "(empty)") ++ "\n""#; |
| 1494 |
let output = work_dir.run_jj(["log", "-T", template]); |
| 1495 |
insta::assert_snapshot!(output, @" |
| 1496 |
@ conflict-exec-file conflict-file dir/file exec-file |
| 1497 |
├─╮ |
| 1498 |
│ ○ conflict-exec-file conflict-file dir/file exec-file |
| 1499 |
○ │ conflict-exec-file conflict-file |
| 1500 |
├─╯ |
| 1501 |
◆ (empty) |
| 1502 |
[EOF] |
| 1503 |
"); |
| 1504 |
|
| 1505 |
let template = r#"self.files("dir").map(|e| e.path()) ++ "\n""#; |
| 1506 |
let output = work_dir.run_jj(["log", "-T", template]); |
| 1507 |
insta::assert_snapshot!(output, @" |
| 1508 |
@ dir/file |
| 1509 |
├─╮ |
| 1510 |
│ ○ dir/file |
| 1511 |
○ │ |
| 1512 |
├─╯ |
| 1513 |
◆ |
| 1514 |
[EOF] |
| 1515 |
"); |
| 1516 |
} |
| 1517 |
|
| 1518 |
#[test] |
| 1519 |
fn test_conflicted_files() { |
| 1520 |
let test_env = TestEnvironment::default(); |
| 1521 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 1522 |
let work_dir = test_env.work_dir("repo"); |
| 1523 |
|
| 1524 |
// Base commit with files. |
| 1525 |
work_dir.write_file("normal-file", "base content"); |
| 1526 |
work_dir.write_file("conflict-file1", "base content"); |
| 1527 |
work_dir.write_file("conflict-file2", "base content"); |
| 1528 |
work_dir.run_jj(["commit", "-m", "base"]).success(); |
| 1529 |
|
| 1530 |
// Sibling branches with conflicting changes. |
| 1531 |
work_dir.write_file("conflict-file1", "left content"); |
| 1532 |
work_dir.write_file("conflict-file2", "left content"); |
| 1533 |
work_dir.run_jj(["commit", "-m", "left"]).success(); |
| 1534 |
|
| 1535 |
work_dir.run_jj(["new", "subject(base)"]).success(); |
| 1536 |
work_dir.write_file("conflict-file1", "right content"); |
| 1537 |
work_dir.write_file("conflict-file2", "right content"); |
| 1538 |
work_dir.run_jj(["commit", "-m", "right"]).success(); |
| 1539 |
|
| 1540 |
// Merge with conflicts. |
| 1541 |
work_dir |
| 1542 |
.run_jj(["new", "subject(left)", "subject(right)"]) |
| 1543 |
.success(); |
| 1544 |
|
| 1545 |
// Test basic conflicted_files() listing. |
| 1546 |
let template = r#"self.conflicted_files().map(|e| e.path()) ++ "\n""#; |
| 1547 |
let output = work_dir.run_jj(["log", "-r", "@", "-T", template, "--no-graph"]); |
| 1548 |
insta::assert_snapshot!(output, @" |
| 1549 |
conflict-file1 conflict-file2 |
| 1550 |
[EOF] |
| 1551 |
"); |
| 1552 |
|
| 1553 |
// Test that non-conflicted commit returns empty list. |
| 1554 |
let template = r#"self.conflicted_files().len() ++ "\n""#; |
| 1555 |
let output = work_dir.run_jj(["log", "-r", "subject(left)", "-T", template, "--no-graph"]); |
| 1556 |
insta::assert_snapshot!(output, @" |
| 1557 |
0 |
| 1558 |
[EOF] |
| 1559 |
"); |
| 1560 |
|
| 1561 |
// Metadata for conflicted_files. |
| 1562 |
let template = indoc! {r#" |
| 1563 |
self.conflicted_files().map(|e| separate(" ", |
| 1564 |
e.path(), |
| 1565 |
"conflict=" ++ e.conflict(), |
| 1566 |
"type=" ++ e.file_type(), |
| 1567 |
"sides=" ++ e.conflict_side_count(), |
| 1568 |
)).join("\n") ++ "\n" |
| 1569 |
"#}; |
| 1570 |
let output = work_dir.run_jj(["log", "-r", "@", "-T", template, "--no-graph"]); |
| 1571 |
insta::assert_snapshot!(output, @" |
| 1572 |
conflict-file1 conflict=true type=conflict sides=2 |
| 1573 |
conflict-file2 conflict=true type=conflict sides=2 |
| 1574 |
[EOF] |
| 1575 |
"); |
| 1576 |
|
| 1577 |
// Metadata for all files. |
| 1578 |
let template = indoc! {r#" |
| 1579 |
self.files().map(|e| separate(" ", |
| 1580 |
e.path(), |
| 1581 |
"conflict=" ++ e.conflict(), |
| 1582 |
"type=" ++ e.file_type(), |
| 1583 |
"sides=" ++ e.conflict_side_count(), |
| 1584 |
)).join("\n") ++ "\n" |
| 1585 |
"#}; |
| 1586 |
let output = work_dir.run_jj(["log", "-r", "@", "-T", template, "--no-graph"]); |
| 1587 |
insta::assert_snapshot!(output, @" |
| 1588 |
conflict-file1 conflict=true type=conflict sides=2 |
| 1589 |
conflict-file2 conflict=true type=conflict sides=2 |
| 1590 |
normal-file conflict=false type=file sides=1 |
| 1591 |
[EOF] |
| 1592 |
"); |
| 1593 |
} |
| 1594 |
|
| 1595 |
#[cfg(unix)] |
| 1596 |
#[test] |
| 1597 |
fn test_file_list_symlink() -> TestResult { |
| 1598 |
let test_env = TestEnvironment::default(); |
| 1599 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 1600 |
let work_dir = test_env.work_dir("repo"); |
| 1601 |
|
| 1602 |
std::os::unix::fs::symlink("symlink_target", work_dir.root().join("symlink"))?; |
| 1603 |
|
| 1604 |
let template = r#"separate(" ", path, "[" ++ file_type ++ "]") ++ "\n""#; |
| 1605 |
let output = work_dir.run_jj(["file", "list", "-T", template]); |
| 1606 |
insta::assert_snapshot!(output, @" |
| 1607 |
symlink [symlink] |
| 1608 |
[EOF] |
| 1609 |
"); |
| 1610 |
Ok(()) |
| 1611 |
} |
| 1612 |
|
| 1613 |
#[test] |
| 1614 |
fn test_signature_templates() { |
| 1615 |
let test_env = TestEnvironment::default(); |
| 1616 |
|
| 1617 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 1618 |
let work_dir = test_env.work_dir("repo"); |
| 1619 |
|
| 1620 |
work_dir.run_jj(["commit", "-m", "unsigned"]).success(); |
| 1621 |
test_env.add_config("signing.behavior = 'own'"); |
| 1622 |
test_env.add_config("signing.backend = 'test'"); |
| 1623 |
work_dir.run_jj(["describe", "-m", "signed"]).success(); |
| 1624 |
|
| 1625 |
let template = r#" |
| 1626 |
if(signature, |
| 1627 |
signature.status() ++ " " ++ signature.display(), |
| 1628 |
"no", |
| 1629 |
) ++ " signature""#; |
| 1630 |
|
| 1631 |
// show that signatures can render |
| 1632 |
let output = work_dir.run_jj(["log", "-T", template]); |
| 1633 |
insta::assert_snapshot!(output, @" |
| 1634 |
@ good test-display signature |
| 1635 |
○ no signature |
| 1636 |
◆ no signature |
| 1637 |
[EOF] |
| 1638 |
"); |
| 1639 |
let output = work_dir.run_jj(["show", "-T", template]); |
| 1640 |
insta::assert_snapshot!(output, @"good test-display signature[EOF]"); |
| 1641 |
|
| 1642 |
// builtin templates |
| 1643 |
test_env.add_config("ui.show-cryptographic-signatures = true"); |
| 1644 |
|
| 1645 |
let args = ["log", "-r", "..", "-T"]; |
| 1646 |
|
| 1647 |
let output = work_dir.run_jj_with(|cmd| cmd.args(args).arg("builtin_log_oneline")); |
| 1648 |
insta::assert_snapshot!(output, @" |
| 1649 |
@ rlvkpnrz test.user 2001-02-03 08:05:09 eb0e9b58 [✓︎] (empty) signed |
| 1650 |
○ qpvuntsm test.user 2001-02-03 08:05:08 0604e056 (empty) unsigned |
| 1651 |
│ |
| 1652 |
~ |
| 1653 |
[EOF] |
| 1654 |
"); |
| 1655 |
|
| 1656 |
let output = work_dir.run_jj_with(|cmd| cmd.args(args).arg("builtin_log_compact")); |
| 1657 |
insta::assert_snapshot!(output, @" |
| 1658 |
@ rlvkpnrz [email protected] 2001-02-03 08:05:09 eb0e9b58 [✓︎] |
| 1659 |
│ (empty) signed |
| 1660 |
○ qpvuntsm [email protected] 2001-02-03 08:05:08 0604e056 |
| 1661 |
│ (empty) unsigned |
| 1662 |
~ |
| 1663 |
[EOF] |
| 1664 |
"); |
| 1665 |
|
| 1666 |
let output = work_dir.run_jj_with(|cmd| cmd.args(args).arg("builtin_log_detailed")); |
| 1667 |
insta::assert_snapshot!(output, @" |
| 1668 |
@ Commit ID: eb0e9b58b724003df03b4277d3066c1c20187ce5 |
| 1669 |
│ Change ID: rlvkpnrzqnoowoytxnquwvuryrwnrmlp |
| 1670 |
│ Author : Test User <[email protected]> (2001-02-03 08:05:09) |
| 1671 |
│ Committer: Test User <[email protected]> (2001-02-03 08:05:09) |
| 1672 |
│ Signature: good signature by test-display |
| 1673 |
│ |
| 1674 |
│ signed |
| 1675 |
│ |
| 1676 |
○ Commit ID: 0604e056feaf8ee553fae4e06d4bfc57cdd319d6 |
| 1677 |
│ Change ID: qpvuntsmwlqtpsluzzsnyyzlmlwvmlnu |
| 1678 |
~ Author : Test User <[email protected]> (2001-02-03 08:05:08) |
| 1679 |
Committer: Test User <[email protected]> (2001-02-03 08:05:08) |
| 1680 |
Signature: (no signature) |
| 1681 |
|
| 1682 |
unsigned |
| 1683 |
|
| 1684 |
[EOF] |
| 1685 |
"); |
| 1686 |
|
| 1687 |
// customization point |
| 1688 |
let config_val = r#"template-aliases."format_short_cryptographic_signature(signature)"="'status: ' ++ signature.status()""#; |
| 1689 |
let output = work_dir.run_jj_with(|cmd| { |
| 1690 |
cmd.args(args) |
| 1691 |
.arg("builtin_log_oneline") |
| 1692 |
.args(["--config", config_val]) |
| 1693 |
}); |
| 1694 |
insta::assert_snapshot!(output, @" |
| 1695 |
@ rlvkpnrz test.user 2001-02-03 08:05:09 eb0e9b58 status: good (empty) signed |
| 1696 |
○ qpvuntsm test.user 2001-02-03 08:05:08 0604e056 status: <Error: No CryptographicSignature available> (empty) unsigned |
| 1697 |
│ |
| 1698 |
~ |
| 1699 |
[EOF] |
| 1700 |
"); |
| 1701 |
} |
| 1702 |
|
| 1703 |
#[test] |
| 1704 |
fn test_log_git_format_patch_template() { |
| 1705 |
let test_env = TestEnvironment::default(); |
| 1706 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 1707 |
let work_dir = test_env.work_dir("repo"); |
| 1708 |
|
| 1709 |
work_dir.write_file("file1", "foo\n"); |
| 1710 |
work_dir.write_file("file2", "bar\n"); |
| 1711 |
work_dir |
| 1712 |
.run_jj([ |
| 1713 |
"new", |
| 1714 |
"-m", |
| 1715 |
"some change\n\nmultiline desc\nsecond line\n\nwith blanks\n", |
| 1716 |
]) |
| 1717 |
.success(); |
| 1718 |
work_dir.remove_file("file1"); |
| 1719 |
work_dir.write_file("file2", "modified\n"); |
| 1720 |
work_dir.write_file("file3", "new\n"); |
| 1721 |
|
| 1722 |
let output = work_dir.run_jj([ |
| 1723 |
"log", |
| 1724 |
"--no-graph", |
| 1725 |
"-T", |
| 1726 |
"git_format_patch_email_headers", |
| 1727 |
"-r@", |
| 1728 |
]); |
| 1729 |
insta::assert_snapshot!(output, @" |
| 1730 |
From fee27496968a4347a49d69c0a634fc0d5cf7fbc0 Mon Sep 17 00:00:00 2001 |
| 1731 |
From: Test User <[email protected]> |
| 1732 |
Date: Sat, 3 Feb 2001 04:05:08 +0700 |
| 1733 |
Subject: [PATCH] some change |
| 1734 |
|
| 1735 |
multiline desc |
| 1736 |
second line |
| 1737 |
|
| 1738 |
with blanks |
| 1739 |
--- |
| 1740 |
file1 | 1 - |
| 1741 |
file2 | 2 +- |
| 1742 |
file3 | 1 + |
| 1743 |
3 files changed, 2 insertions(+), 2 deletions(-) |
| 1744 |
|
| 1745 |
[EOF] |
| 1746 |
"); |
| 1747 |
} |
| 1748 |
|
| 1749 |
#[test] |
| 1750 |
fn test_log_format_trailers() { |
| 1751 |
let test_env = TestEnvironment::default(); |
| 1752 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 1753 |
let work_dir = test_env.work_dir("repo"); |
| 1754 |
|
| 1755 |
let output = work_dir.run_jj([ |
| 1756 |
"log", |
| 1757 |
"--no-graph", |
| 1758 |
"-T", |
| 1759 |
"format_gerrit_change_id_trailer(self) ++ format_signed_off_by_trailer(self)", |
| 1760 |
"-r@", |
| 1761 |
]); |
| 1762 |
insta::assert_snapshot!(output, @" |
| 1763 |
Change-Id: I9a45c67d3e96a7e5007c110ede34dec56a6a6964 |
| 1764 |
Signed-off-by: Test User <[email protected]> |
| 1765 |
[EOF] |
| 1766 |
"); |
| 1767 |
|
| 1768 |
work_dir |
| 1769 |
.run_jj([ |
| 1770 |
"describe", |
| 1771 |
"-r@", |
| 1772 |
"-m", |
| 1773 |
"a change with trailers", |
| 1774 |
r#"--config=templates.commit_trailers="format_signed_off_by_trailer(self) ++ format_gerrit_change_id_trailer(self)""#, |
| 1775 |
]) |
| 1776 |
.success(); |
| 1777 |
|
| 1778 |
let output = work_dir.run_jj(["log", "--no-graph", "-T", r#"trailers ++ "\n""#, "-r@"]); |
| 1779 |
insta::assert_snapshot!(output, @" |
| 1780 |
Signed-off-by: Test User <[email protected]> |
| 1781 |
Change-Id: I9a45c67d3e96a7e5007c110ede34dec56a6a6964 |
| 1782 |
[EOF] |
| 1783 |
"); |
| 1784 |
|
| 1785 |
let output = work_dir.run_jj([ |
| 1786 |
"log", |
| 1787 |
"--no-graph", |
| 1788 |
"-T", |
| 1789 |
"trailers.map(|t| t.key())", |
| 1790 |
"-r@", |
| 1791 |
]); |
| 1792 |
insta::assert_snapshot!(output, @"Signed-off-by Change-Id[EOF]"); |
| 1793 |
|
| 1794 |
let output = work_dir.run_jj([ |
| 1795 |
"log", |
| 1796 |
"--no-graph", |
| 1797 |
"-T", |
| 1798 |
"trailers.map(|t| t.value())", |
| 1799 |
"-r@", |
| 1800 |
]); |
| 1801 |
insta::assert_snapshot!(output, @"Test User <[email protected]> I9a45c67d3e96a7e5007c110ede34dec56a6a6964[EOF]"); |
| 1802 |
|
| 1803 |
let output = work_dir.run_jj([ |
| 1804 |
"log", |
| 1805 |
"--no-graph", |
| 1806 |
"-T", |
| 1807 |
r#"self.trailers().contains_key("Signed-off-by")"#, |
| 1808 |
"-r@", |
| 1809 |
]); |
| 1810 |
insta::assert_snapshot!(output, @"true[EOF]"); |
| 1811 |
|
| 1812 |
let output = work_dir.run_jj([ |
| 1813 |
"log", |
| 1814 |
"--no-graph", |
| 1815 |
"-T", |
| 1816 |
r#"self.trailers().contains_key("foo")"#, |
| 1817 |
"-r@", |
| 1818 |
]); |
| 1819 |
insta::assert_snapshot!(output, @"false[EOF]"); |
| 1820 |
} |
| 1821 |
|
| 1822 |
#[test] |
| 1823 |
fn test_log_git_web_url() { |
| 1824 |
let test_env = TestEnvironment::default(); |
| 1825 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 1826 |
let work_dir = test_env.work_dir("repo"); |
| 1827 |
|
| 1828 |
// Add test remotes |
| 1829 |
work_dir |
| 1830 |
.run_jj([ |
| 1831 |
"git", |
| 1832 |
"remote", |
| 1833 |
"add", |
| 1834 |
"origin", |
| 1835 |
"[email protected]:owner/repo", |
| 1836 |
]) |
| 1837 |
.success(); |
| 1838 |
work_dir |
| 1839 |
.run_jj([ |
| 1840 |
"git", |
| 1841 |
"remote", |
| 1842 |
"add", |
| 1843 |
"upstream", |
| 1844 |
"https://github.com/upstream/repo.git", |
| 1845 |
]) |
| 1846 |
.success(); |
| 1847 |
|
| 1848 |
// Test default remote, explicit remote, and nonexistent remote |
| 1849 |
let output = work_dir.run_jj([ |
| 1850 |
"log", |
| 1851 |
"--no-graph", |
| 1852 |
"-r@-", |
| 1853 |
"-T", |
| 1854 |
r#"git_web_url() ++ " " ++ git_web_url(remote="upstream") ++ " " ++ git_web_url(remote="nonexistent")"#, |
| 1855 |
]); |
| 1856 |
insta::assert_snapshot!(output, @"https://github.com/owner/repo https://github.com/upstream/repo [EOF]"); |
| 1857 |
} |