Debian Codegraph @

cli/tests/test_log_command.rs

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
15 use crate::common::TestEnvironment;
16 use crate::common::to_toml_value;
17
18 #[test]
19 fn test_log_with_empty_revision() {
20 let test_env = TestEnvironment::default();
21 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
22 let work_dir = test_env.work_dir("repo");
23
24 let output = work_dir.run_jj(["log", "-r="]);
25 insta::assert_snapshot!(output, @"
26 ------- stderr -------
27 error: a value is required for '--revision <REVSETS>' but none was supplied
28
29 For more information, try '--help'.
30 [EOF]
31 [exit status: 2]
32 ");
33 }
34
35 #[test]
36 fn test_log_with_no_template() {
37 let test_env = TestEnvironment::default();
38 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
39 let work_dir = test_env.work_dir("repo");
40
41 let output = work_dir.run_jj(["log", "-T"]);
42 insta::assert_snapshot!(output, @"
43 ------- stderr -------
44 error: a value is required for '--template <TEMPLATE>' but none was supplied
45
46 For more information, try '--help'.
47 Hint: The following template aliases are defined:
48 - builtin_config_list
49 - builtin_config_list_detailed
50 - builtin_draft_commit_description
51 - builtin_draft_commit_description_with_diff
52 - builtin_evolog_compact
53 - builtin_log_comfortable
54 - builtin_log_compact
55 - builtin_log_compact_full_description
56 - builtin_log_detailed
57 - builtin_log_node
58 - builtin_log_node_ascii
59 - builtin_log_oneline
60 - builtin_log_redacted
61 - builtin_op_log_comfortable
62 - builtin_op_log_compact
63 - builtin_op_log_node
64 - builtin_op_log_node_ascii
65 - builtin_op_log_oneline
66 - builtin_op_log_redacted
67 - builtin_workspace_list
68 - commit_summary_separator
69 - default_commit_description
70 - description_placeholder
71 - email_placeholder
72 - empty_commit_marker
73 - git_format_patch_email_headers
74 - name_placeholder
75 [EOF]
76 [exit status: 2]
77 ");
78 }
79
80 #[test]
81 fn test_log_with_diff_stats() {
82 let test_env = TestEnvironment::default();
83 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
84 let work_dir = test_env.work_dir("repo");
85
86 work_dir.write_file("file1", "foo\n");
87 work_dir.write_file("file2", "bar\nfoo\n");
88 work_dir.write_file("file3", "foo\n");
89 work_dir.write_file("file4", "foo\n");
90 work_dir.write_file("file5", "foobar\nbaz\n");
91 work_dir
92 .run_jj(["describe", "-m", "initial commit"])
93 .success();
94 work_dir.run_jj(["new", "-m", "multiple changes"]).success();
95 work_dir.write_file("file1", "foo\nbar\n");
96 work_dir.write_file("file2", "bar\n");
97 work_dir.write_file("file3", "baz\n");
98 work_dir.remove_file("file4");
99 work_dir.remove_file("file5");
100 work_dir.write_file("file6", "foobar\nbaz\n");
101
102 let template = r#"
103 self.diff().files().map(
104 |f| f.status_char() ++ " " ++ f.status() ++ " " ++ f.source().path() ++ " " ++ f.target().path()
105 ).join("\n")
106 ++ "\n" ++
107 self.diff().stat().files().map(
108 |f| f.status_char() ++ " " ++ f.status() ++ " " ++ f.lines_added() ++ " " ++ f.lines_removed() ++ " " ++ f.path()
109 ).join("\n")
110 "#;
111
112 let output = work_dir.run_jj(["log", "-T", template]);
113 insta::assert_snapshot!(output, @"
114 @ M modified file1 file1
115 │ M modified file2 file2
116 │ M modified file3 file3
117 │ D removed file4 file4
118 │ R renamed file5 file6
119 │ M modified 1 0 file1
120 │ M modified 0 1 file2
121 │ M modified 1 1 file3
122 │ D removed 0 1 file4
123 │ R renamed 0 0 file6
124 ○ A added file1 file1
125 │ A added file2 file2
126 │ A added file3 file3
127 │ A added file4 file4
128 │ A added file5 file5
129 │ A added 1 0 file1
130 │ A added 2 0 file2
131 │ A added 1 0 file3
132 │ A added 1 0 file4
133 │ A added 2 0 file5
134 ◆
135 [EOF]
136 ");
137 }
138
139 #[test]
140 fn test_log_with_or_without_diff() {
141 let test_env = TestEnvironment::default();
142 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
143 let work_dir = test_env.work_dir("repo");
144
145 work_dir.write_file("file1", "foo\n");
146 work_dir.run_jj(["describe", "-m", "add a file"]).success();
147 work_dir.run_jj(["new", "-m", "a new commit"]).success();
148 work_dir.write_file("file1", "foo\nbar\n");
149
150 let output = work_dir.run_jj(["log", "-T", "description"]);
151 insta::assert_snapshot!(output, @"
152 @ a new commit
153 ○ add a file
154 ◆
155 [EOF]
156 ");
157
158 let output = work_dir.run_jj(["log", "-T", "description", "-p"]);
159 insta::assert_snapshot!(output, @"
160 @ a new commit
161 │ Modified regular file file1:
162 │ 1 1: foo
163 │ 2: bar
164 ○ add a file
165 │ Added regular file file1:
166 │ 1: foo
167 ◆
168 [EOF]
169 ");
170
171 let output = work_dir.run_jj(["log", "-T", "description", "--no-graph"]);
172 insta::assert_snapshot!(output, @"
173 a new commit
174 add a file
175 [EOF]
176 ");
177
178 // `-G` is the short name of --no-graph
179 let output = work_dir.run_jj(["log", "-T", r#"commit_id.short() ++ "\n""#, "-G"]);
180 insta::assert_snapshot!(output, @"
181 58c940c45833
182 007859d3ad71
183 000000000000
184 [EOF]
185 ");
186
187 // `-p` for default diff output, `-s` for summary
188 let output = work_dir.run_jj(["log", "-T", "description", "-p", "-s"]);
189 insta::assert_snapshot!(output, @"
190 @ a new commit
191 │ M file1
192 │ Modified regular file file1:
193 │ 1 1: foo
194 │ 2: bar
195 ○ add a file
196 │ A file1
197 │ Added regular file file1:
198 │ 1: foo
199 ◆
200 [EOF]
201 ");
202
203 // `-s` for summary, `--git` for git diff (which implies `-p`)
204 let output = work_dir.run_jj(["log", "-T", "description", "-s", "--git"]);
205 insta::assert_snapshot!(output, @"
206 @ a new commit
207 │ M file1
208 │ diff --git a/file1 b/file1
209 │ index 257cc5642c..3bd1f0e297 100644
210 │ --- a/file1
211 │ +++ b/file1
212 │ @@ -1,1 +1,2 @@
213 │ foo
214 │ +bar
215 ○ add a file
216 │ A file1
217 │ diff --git a/file1 b/file1
218 │ new file mode 100644
219 │ index 0000000000..257cc5642c
220 │ --- /dev/null
221 │ +++ b/file1
222 │ @@ -0,0 +1,1 @@
223 │ +foo
224 ◆
225 [EOF]
226 ");
227
228 // `-p` for default diff output, `--stat` for diff-stat
229 let output = work_dir.run_jj(["log", "-T", "description", "-p", "--stat"]);
230 insta::assert_snapshot!(output, @"
231 @ a new commit
232 │ file1 | 1 +
233 │ 1 file changed, 1 insertion(+), 0 deletions(-)
234 │ Modified regular file file1:
235 │ 1 1: foo
236 │ 2: bar
237 ○ add a file
238 │ file1 | 1 +
239 │ 1 file changed, 1 insertion(+), 0 deletions(-)
240 │ Added regular file file1:
241 │ 1: foo
242 ◆ 0 files changed, 0 insertions(+), 0 deletions(-)
243 [EOF]
244 ");
245
246 // `--stat` is short format, which should be printed first
247 let output = work_dir.run_jj(["log", "-T", "description", "--git", "--stat"]);
248 insta::assert_snapshot!(output, @"
249 @ a new commit
250 │ file1 | 1 +
251 │ 1 file changed, 1 insertion(+), 0 deletions(-)
252 │ diff --git a/file1 b/file1
253 │ index 257cc5642c..3bd1f0e297 100644
254 │ --- a/file1
255 │ +++ b/file1
256 │ @@ -1,1 +1,2 @@
257 │ foo
258 │ +bar
259 ○ add a file
260 │ file1 | 1 +
261 │ 1 file changed, 1 insertion(+), 0 deletions(-)
262 │ diff --git a/file1 b/file1
263 │ new file mode 100644
264 │ index 0000000000..257cc5642c
265 │ --- /dev/null
266 │ +++ b/file1
267 │ @@ -0,0 +1,1 @@
268 │ +foo
269 ◆ 0 files changed, 0 insertions(+), 0 deletions(-)
270 [EOF]
271 ");
272
273 // `-p` enables default "summary" output, so `-s` is noop
274 let output = work_dir.run_jj([
275 "log",
276 "-T",
277 "description",
278 "-p",
279 "-s",
280 "--config=ui.diff-formatter=:summary",
281 ]);
282 insta::assert_snapshot!(output, @"
283 @ a new commit
284 │ M file1
285 ○ add a file
286 │ A file1
287 ◆
288 [EOF]
289 ");
290
291 // `-p` enables default "color-words" diff output, so `--color-words` is noop
292 let output = work_dir.run_jj(["log", "-T", "description", "-p", "--color-words"]);
293 insta::assert_snapshot!(output, @"
294 @ a new commit
295 │ Modified regular file file1:
296 │ 1 1: foo
297 │ 2: bar
298 ○ add a file
299 │ Added regular file file1:
300 │ 1: foo
301 ◆
302 [EOF]
303 ");
304
305 // `--git` enables git diff, so `-p` is noop
306 let output = work_dir.run_jj(["log", "-T", "description", "--no-graph", "-p", "--git"]);
307 insta::assert_snapshot!(output, @"
308 a new commit
309 diff --git a/file1 b/file1
310 index 257cc5642c..3bd1f0e297 100644
311 --- a/file1
312 +++ b/file1
313 @@ -1,1 +1,2 @@
314 foo
315 +bar
316 add a file
317 diff --git a/file1 b/file1
318 new file mode 100644
319 index 0000000000..257cc5642c
320 --- /dev/null
321 +++ b/file1
322 @@ -0,0 +1,1 @@
323 +foo
324 [EOF]
325 ");
326
327 // Cannot use both `--git` and `--color-words`
328 let output = work_dir.run_jj([
329 "log",
330 "-T",
331 "description",
332 "--no-graph",
333 "-p",
334 "--git",
335 "--color-words",
336 ]);
337 insta::assert_snapshot!(output, @"
338 ------- stderr -------
339 error: the argument '--git' cannot be used with '--color-words'
340
341 Usage: jj log --template <TEMPLATE> --no-graph --patch --git [FILESETS]...
342
343 For more information, try '--help'.
344 [EOF]
345 [exit status: 2]
346 ");
347
348 // `-s` with or without graph
349 let output = work_dir.run_jj(["log", "-T", "description", "-s"]);
350 insta::assert_snapshot!(output, @"
351 @ a new commit
352 │ M file1
353 ○ add a file
354 │ A file1
355 ◆
356 [EOF]
357 ");
358 let output = work_dir.run_jj(["log", "-T", "description", "--no-graph", "-s"]);
359 insta::assert_snapshot!(output, @"
360 a new commit
361 M file1
362 add a file
363 A file1
364 [EOF]
365 ");
366
367 // `--git` implies `-p`, with or without graph
368 let output = work_dir.run_jj(["log", "-T", "description", "-r", "@", "--git"]);
369 insta::assert_snapshot!(output, @"
370 @ a new commit
371 │ diff --git a/file1 b/file1
372 ~ index 257cc5642c..3bd1f0e297 100644
373 --- a/file1
374 +++ b/file1
375 @@ -1,1 +1,2 @@
376 foo
377 +bar
378 [EOF]
379 ");
380 let output = work_dir.run_jj(["log", "-T", "description", "-r", "@", "--no-graph", "--git"]);
381 insta::assert_snapshot!(output, @"
382 a new commit
383 diff --git a/file1 b/file1
384 index 257cc5642c..3bd1f0e297 100644
385 --- a/file1
386 +++ b/file1
387 @@ -1,1 +1,2 @@
388 foo
389 +bar
390 [EOF]
391 ");
392
393 // `--color-words` implies `-p`, with or without graph
394 let output = work_dir.run_jj(["log", "-T", "description", "-r", "@", "--color-words"]);
395 insta::assert_snapshot!(output, @"
396 @ a new commit
397 │ Modified regular file file1:
398 ~ 1 1: foo
399 2: bar
400 [EOF]
401 ");
402 let output = work_dir.run_jj([
403 "log",
404 "-T",
405 "description",
406 "-r",
407 "@",
408 "--no-graph",
409 "--color-words",
410 ]);
411 insta::assert_snapshot!(output, @"
412 a new commit
413 Modified regular file file1:
414 1 1: foo
415 2: bar
416 [EOF]
417 ");
418 }
419
420 #[test]
421 fn test_log_null_terminate_multiline_descriptions() {
422 let test_env = TestEnvironment::default();
423 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
424 let work_dir = test_env.work_dir("repo");
425
426 work_dir
427 .run_jj(["commit", "-m", "commit 1 line 1", "-m", "commit 1 line 2"])
428 .success();
429 work_dir
430 .run_jj(["commit", "-m", "commit 2 line 1", "-m", "commit 2 line 2"])
431 .success();
432 work_dir
433 .run_jj(["describe", "-m", "commit 3 line 1", "-m", "commit 3 line 2"])
434 .success();
435
436 let output = work_dir
437 .run_jj([
438 "log",
439 "-r",
440 "~root()",
441 "-T",
442 r#"description ++ "\0""#,
443 "--no-graph",
444 ])
445 .success();
446 insta::assert_debug_snapshot!(
447 output.stdout.normalized(),
448 @r#""commit 3 line 1\n\ncommit 3 line 2\n\0commit 2 line 1\n\ncommit 2 line 2\n\0commit 1 line 1\n\ncommit 1 line 2\n\0""#
449 );
450 }
451
452 #[test]
453 fn test_log_shortest_accessors() {
454 let test_env = TestEnvironment::default();
455 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
456 let work_dir = test_env.work_dir("repo");
457 let render = |rev, template| work_dir.run_jj(["log", "--no-graph", "-r", rev, "-T", template]);
458 test_env.add_config(
459 r#"
460 [template-aliases]
461 'format_id(id)' = 'id.shortest(12).prefix() ++ "[" ++ id.shortest(12).rest() ++ "]"'
462 "#,
463 );
464
465 work_dir.write_file("file", "original file\n");
466 work_dir.run_jj(["describe", "-m", "initial"]).success();
467 work_dir
468 .run_jj(["bookmark", "c", "-r@", "original"])
469 .success();
470 insta::assert_snapshot!(
471 render("original", r#"format_id(change_id) ++ " " ++ format_id(commit_id)"#),
472 @"q[pvuntsmwlqt] 8[216f646c36d][EOF]");
473
474 // Create a chain of 10 commits
475 for i in 1..10 {
476 work_dir
477 .run_jj(["new", "-m", &format!("commit{i}")])
478 .success();
479 work_dir.write_file("file", format!("file {i}\n"));
480 }
481 // Create 2^3 duplicates of the chain
482 for _ in 0..3 {
483 work_dir.run_jj(["duplicate", "subject(commit*)"]).success();
484 }
485
486 insta::assert_snapshot!(
487 render("original", r#"format_id(change_id) ++ " " ++ format_id(commit_id)"#),
488 @"qpv[untsmwlqt] 82[16f646c36d][EOF]");
489
490 insta::assert_snapshot!(
491 render("::@", r#"change_id.shortest() ++ " " ++ commit_id.shortest() ++ "\n""#), @"
492 wq c2
493 km 74
494 kp 97
495 zn 78
496 yo 40
497 vr bc9
498 yq 28
499 ro af
500 mz 04
501 qpv 82
502 zzz 00
503 [EOF]
504 ");
505
506 insta::assert_snapshot!(
507 render("::@", r#"format_id(change_id) ++ " " ++ format_id(commit_id) ++ "\n""#), @"
508 wq[nwkozpkust] c2[b4c0bb3362]
509 km[kuslswpqwq] 74[fcd50c0643]
510 kp[qxywonksrl] 97[dcaada9b8d]
511 zn[kkpsqqskkl] 78[c03ab2235b]
512 yo[stqsxwqrlt] 40[1119280761]
513 vr[uxwmqvtpmx] bc9[e8942b459]
514 yq[osqzytrlsw] 28[edbc9658ef]
515 ro[yxmykxtrkr] af[3e6a27a1d0]
516 mz[vwutvlkqwt] 04[6c6a1df762]
517 qpv[untsmwlqt] 82[16f646c36d]
518 zzz[zzzzzzzzz] 00[0000000000]
519 [EOF]
520 ");
521
522 // Can get shorter prefixes in configured revset
523 test_env.add_config(r#"revsets.short-prefixes = "(@----)::""#);
524 insta::assert_snapshot!(
525 render("::@", r#"format_id(change_id) ++ " " ++ format_id(commit_id) ++ "\n""#), @"
526 w[qnwkozpkust] c[2b4c0bb3362]
527 km[kuslswpqwq] 74[fcd50c0643]
528 kp[qxywonksrl] 9[7dcaada9b8d]
529 z[nkkpsqqskkl] 78[c03ab2235b]
530 y[ostqsxwqrlt] 4[01119280761]
531 vr[uxwmqvtpmx] bc9[e8942b459]
532 yq[osqzytrlsw] 28[edbc9658ef]
533 ro[yxmykxtrkr] af[3e6a27a1d0]
534 mz[vwutvlkqwt] 04[6c6a1df762]
535 qpv[untsmwlqt] 82[16f646c36d]
536 zzz[zzzzzzzzz] 00[0000000000]
537 [EOF]
538 ");
539
540 // Can disable short prefixes by setting to empty string
541 test_env.add_config(r#"revsets.short-prefixes = """#);
542 insta::assert_snapshot!(
543 render("::@", r#"format_id(change_id) ++ " " ++ format_id(commit_id) ++ "\n""#), @"
544 wq[nwkozpkust] c2[b4c0bb3362]
545 km[kuslswpqwq] 74[fcd50c0643]
546 kp[qxywonksrl] 97[dcaada9b8d]
547 zn[kkpsqqskkl] 78[c03ab2235b]
548 yo[stqsxwqrlt] 401[119280761]
549 vr[uxwmqvtpmx] bc9[e8942b459]
550 yq[osqzytrlsw] 28[edbc9658ef]
551 ro[yxmykxtrkr] af[3e6a27a1d0]
552 mz[vwutvlkqwt] 04[6c6a1df762]
553 qpv[untsmwlqt] 82[16f646c36d]
554 zzz[zzzzzzzzz] 00[0000000000]
555 [EOF]
556 ");
557
558 // The shortest prefix "zzz" is shadowed by bookmark
559 work_dir
560 .run_jj(["bookmark", "set", "-r@", "z", "zz", "zzz"])
561 .success();
562 insta::assert_snapshot!(
563 render("root()", r#"format_id(change_id) ++ " " ++ format_id(commit_id) ++ "\n""#), @"
564 zzzz[zzzzzzzz] 00[0000000000]
565 [EOF]
566 ");
567 }
568
569 #[test]
570 fn test_log_bad_short_prefixes() {
571 let test_env = TestEnvironment::default();
572 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
573 let work_dir = test_env.work_dir("repo");
574
575 // Suppress warning in the commit summary template
576 test_env.add_config("template-aliases.'format_short_id(id)' = 'id.short(8)'");
577
578 // Error on bad config of short prefixes
579 test_env.add_config(r#"revsets.short-prefixes = "!nval!d""#);
580 let output = work_dir.run_jj(["status"]);
581 insta::assert_snapshot!(output, @"
582 ------- stderr -------
583 Config error: Invalid `revsets.short-prefixes`
584 Caused by: --> 1:1
585 |
586 1 | !nval!d
587 | ^---
588 |
589 = expected <expression>
590 For help, see https://docs.jj-vcs.dev/latest/config/ or use `jj help -k config`.
591 [EOF]
592 [exit status: 1]
593 ");
594
595 // Warn on resolution of short prefixes
596 test_env.add_config("revsets.short-prefixes = 'missing'");
597 let output = work_dir.run_jj(["log", "-Tcommit_id.shortest()"]);
598 insta::assert_snapshot!(output, @"
599 @ e
600 ◆ 0
601 [EOF]
602 ------- stderr -------
603 Warning: In template expression
604 --> 1:11
605 |
606 1 | commit_id.shortest()
607 | ^------^
608 |
609 = Failed to load short-prefixes index
610 Failed to resolve short-prefixes disambiguation revset
611 Revision `missing` doesn't exist
612 [EOF]
613 ");
614
615 // Error on resolution of short prefixes
616 test_env.add_config("revsets.short-prefixes = 'missing'");
617 let output = work_dir.run_jj(["log", "-r0"]);
618 insta::assert_snapshot!(output, @"
619 ------- stderr -------
620 Error: Failed to resolve short-prefixes disambiguation revset
621 Caused by: Revision `missing` doesn't exist
622 [EOF]
623 [exit status: 1]
624 ");
625 }
626
627 #[test]
628 fn test_log_prefix_highlight_styled() {
629 let test_env = TestEnvironment::default();
630 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
631 let work_dir = test_env.work_dir("repo");
632
633 fn prefix_format(len: Option<usize>) -> String {
634 format!(
635 r###"
636 separate(" ",
637 "Change",
638 change_id.shortest({0}),
639 description.first_line(),
640 commit_id.shortest({0}),
641 bookmarks,
642 )
643 "###,
644 len.map(|l| l.to_string()).unwrap_or_default()
645 )
646 }
647
648 work_dir.write_file("file", "original file\n");
649 work_dir.run_jj(["describe", "-m", "initial"]).success();
650 work_dir
651 .run_jj(["bookmark", "c", "-r@", "original"])
652 .success();
653 insta::assert_snapshot!(
654 work_dir.run_jj(["log", "-r", "original", "-T", &prefix_format(Some(12))]), @"
655 @ Change qpvuntsmwlqt initial 8216f646c36d original
656 │
657 ~
658 [EOF]
659 ");
660
661 // Create a chain of 10 commits
662 for i in 1..10 {
663 work_dir
664 .run_jj(["new", "-m", &format!("commit{i}")])
665 .success();
666 work_dir.write_file("file", format!("file {i}\n"));
667 }
668 // Create 2^3 duplicates of the chain
669 for _ in 0..3 {
670 work_dir.run_jj(["duplicate", "subject(commit*)"]).success();
671 }
672
673 insta::assert_snapshot!(
674 work_dir.run_jj(["log", "-r", "original", "-T", &prefix_format(Some(12))]), @"
675 ○ Change qpvuntsmwlqt initial 8216f646c36d original
676 │
677 ~
678 [EOF]
679 ");
680 let output = work_dir.run_jj([
681 "--color=always",
682 "log",
683 "-r",
684 "@-----------..@",
685 "-T",
686 &prefix_format(Some(12)),
687 ]);
688 insta::assert_snapshot!(output, @"
689 @ Change wqnwkozpkust commit9 c2b4c0bb3362
690 ○ Change kmkuslswpqwq commit8 74fcd50c0643
691 ○ Change kpqxywonksrl commit7 97dcaada9b8d
692 ○ Change znkkpsqqskkl commit6 78c03ab2235b
693 ○ Change yostqsxwqrlt commit5 401119280761
694 ○ Change vruxwmqvtpmx commit4 bc9e8942b459
695 ○ Change yqosqzytrlsw commit3 28edbc9658ef
696 ○ Change royxmykxtrkr commit2 af3e6a27a1d0
697 ○ Change mzvwutvlkqwt commit1 046c6a1df762
698 ○ Change qpvuntsmwlqt initial 8216f646c36d original
699 ◆ Change zzzzzzzzzzzz 000000000000
700 [EOF]
701 ");
702 let output = work_dir.run_jj([
703 "--color=always",
704 "log",
705 "-r",
706 "@-----------..@",
707 "-T",
708 &prefix_format(Some(3)),
709 ]);
710 insta::assert_snapshot!(output, @"
711 @ Change wqn commit9 c2b
712 ○ Change kmk commit8 74f
713 ○ Change kpq commit7 97d
714 ○ Change znk commit6 78c
715 ○ Change yos commit5 401
716 ○ Change vru commit4 bc9
717 ○ Change yqo commit3 28e
718 ○ Change roy commit2 af3
719 ○ Change mzv commit1 046
720 ○ Change qpv initial 821 original
721 ◆ Change zzz 000
722 [EOF]
723 ");
724 let output = work_dir.run_jj([
725 "--color=always",
726 "log",
727 "-r",
728 "@-----------..@",
729 "-T",
730 &prefix_format(None),
731 ]);
732 insta::assert_snapshot!(output, @"
733 @ Change wq commit9 c2
734 ○ Change km commit8 74
735 ○ Change kp commit7 97
736 ○ Change zn commit6 78
737 ○ Change yo commit5 40
738 ○ Change vr commit4 bc9
739 ○ Change yq commit3 28
740 ○ Change ro commit2 af
741 ○ Change mz commit1 04
742 ○ Change qpv initial 82 original
743 ◆ Change zzz 00
744 [EOF]
745 ");
746 }
747
748 #[test]
749 fn test_log_prefix_highlight_counts_hidden_commits() {
750 let test_env = TestEnvironment::default();
751 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
752 let work_dir = test_env.work_dir("repo");
753 test_env.add_config(
754 r#"
755 [revsets]
756 short-prefixes = "" # Disable short prefixes
757 [template-aliases]
758 'format_id(id)' = 'id.shortest(12).prefix() ++ "[" ++ id.shortest(12).rest() ++ "]"'
759 "#,
760 );
761
762 let prefix_format = r#"
763 separate(" ",
764 "Change",
765 format_id(change_id),
766 description.first_line(),
767 format_id(commit_id),
768 bookmarks,
769 )
770 "#;
771
772 work_dir.write_file("file", "original file\n");
773 work_dir.run_jj(["describe", "-m", "initial"]).success();
774 work_dir
775 .run_jj(["bookmark", "c", "-r@", "original"])
776 .success();
777 insta::assert_snapshot!(work_dir.run_jj(["log", "-r", "all()", "-T", prefix_format]), @"
778 @ Change q[pvuntsmwlqt] initial 8[216f646c36d] original
779 ◆ Change z[zzzzzzzzzzz] 00[0000000000]
780 [EOF]
781 ");
782
783 // Create 2^7 hidden commits
784 work_dir.run_jj(["new", "root()", "-m", "extra"]).success();
785 for _ in 0..7 {
786 work_dir.run_jj(["duplicate", "subject(extra)"]).success();
787 }
788 work_dir.run_jj(["abandon", "subject(extra)"]).success();
789
790 // The unique prefixes became longer.
791 insta::assert_snapshot!(work_dir.run_jj(["log", "-T", prefix_format]), @"
792 @ Change wq[nwkozpkust] 88[e8407a4f0a]
793 │ ○ Change qpv[untsmwlqt] initial 82[16f646c36d] original
794 ├─╯
795 ◆ Change zzz[zzzzzzzzz] 00[0000000000]
796 [EOF]
797 ");
798 insta::assert_snapshot!(work_dir.run_jj(["log", "-r", "8", "-T", prefix_format]), @"
799 ------- stderr -------
800 Error: Commit ID prefix `8` is ambiguous
801 [EOF]
802 [exit status: 1]
803 ");
804 insta::assert_snapshot!(work_dir.run_jj(["log", "-r", "88", "-T", prefix_format]), @"
805 @ Change wq[nwkozpkust] 88[e8407a4f0a]
806 │
807 ~
808 [EOF]
809 ");
810 }
811
812 #[test]
813 fn test_log_graph_prioritize_hidden_commits() {
814 let test_env = TestEnvironment::default();
815 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
816 let work_dir = test_env.work_dir("repo");
817
818 work_dir.run_jj(["describe", "-m1"]).success();
819 work_dir.run_jj(["describe", "-m2"]).success();
820
821 // Sanity check: the revision "1" should be displayed first
822 let output = work_dir.run_jj([
823 "log",
824 "--config=revsets.log-graph-prioritize=at_operation(@-, @)",
825 "-r::(@|at_operation(@-, @))",
826 ]);
827 insta::assert_snapshot!(output, @"
828 ○ qpvuntsm/1 [email protected] 2001-02-03 08:05:08 884fe9b9 (hidden)
829 │ (empty) 1
830 │ @ qpvuntsm [email protected] 2001-02-03 08:05:09 4e123bae
831 ├─╯ (empty) 2
832 ◆ zzzzzzzz root() 00000000
833 [EOF]
834 ");
835
836 // The revision "1" shouldn't be prioritized because it isn't included in
837 // the query.
838 let output = work_dir.run_jj([
839 "log",
840 "--config=revsets.log-graph-prioritize=at_operation(@-, @ | subject(1))",
841 "-rall()",
842 ]);
843 insta::assert_snapshot!(output, @"
844 @ qpvuntsm [email protected] 2001-02-03 08:05:09 4e123bae
845 │ (empty) 2
846 ◆ zzzzzzzz root() 00000000
847 [EOF]
848 ");
849
850 // The revision "2" shouldn't be prioritized because it isn't included in
851 // the query.
852 let output = work_dir.run_jj([
853 "log",
854 "--config=revsets.log-graph-prioritize=@ | subject(2)",
855 "-rat_operation(@-, all())",
856 ]);
857 insta::assert_snapshot!(output, @"
858 ○ qpvuntsm/1 [email protected] 2001-02-03 08:05:08 884fe9b9 (hidden)
859 │ (empty) 1
860 ◆ zzzzzzzz root() 00000000
861 [EOF]
862 ");
863 }
864
865 #[test]
866 fn test_log_author_format() {
867 let test_env = TestEnvironment::default();
868 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
869 let work_dir = test_env.work_dir("repo");
870
871 insta::assert_snapshot!(work_dir.run_jj(["log", "--revisions=@"]), @"
872 @ qpvuntsm [email protected] 2001-02-03 08:05:07 e8849ae1
873 │ (empty) (no description set)
874 ~
875 [EOF]
876 ");
877
878 let decl = "template-aliases.'format_short_signature(signature)'";
879 insta::assert_snapshot!(work_dir.run_jj([
880 "--config",
881 &format!("{decl}='signature.email().local()'"),
882 "log",
883 "--revisions=@",
884 ]), @"
885 @ qpvuntsm test.user 2001-02-03 08:05:07 e8849ae1
886 │ (empty) (no description set)
887 ~
888 [EOF]
889 ");
890 }
891
892 #[test]
893 fn test_log_divergence() {
894 let test_env = TestEnvironment::default();
895 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
896 let work_dir = test_env.work_dir("repo");
897 let template = r#"description.first_line() ++ if(divergent, " !divergence!")"#;
898
899 work_dir.write_file("file", "foo\n");
900 work_dir
901 .run_jj(["describe", "-m", "description 1"])
902 .success();
903 // No divergence
904 let output = work_dir.run_jj(["log", "-T", template]);
905 insta::assert_snapshot!(output, @"
906 @ description 1
907 ◆
908 [EOF]
909 ");
910
911 // Create divergence
912 work_dir
913 .run_jj(["describe", "-m", "description 2", "--at-operation", "@-"])
914 .success();
915 let output = work_dir.run_jj(["log", "-T", template]);
916 insta::assert_snapshot!(output, @"
917 @ description 1 !divergence!
918 │ ○ description 2 !divergence!
919 ├─╯
920 ◆
921 [EOF]
922 ------- stderr -------
923 Concurrent modification detected, resolving automatically.
924 [EOF]
925 ");
926 }
927
928 #[test]
929 fn test_log_reversed() {
930 let test_env = TestEnvironment::default();
931 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
932 let work_dir = test_env.work_dir("repo");
933
934 work_dir.run_jj(["describe", "-m", "first"]).success();
935 work_dir.run_jj(["new", "-m", "second"]).success();
936
937 let output = work_dir.run_jj(["log", "-T", "description", "--reversed"]);
938 insta::assert_snapshot!(output, @"
939 ◆
940 ○ first
941 @ second
942 [EOF]
943 ");
944
945 let output = work_dir.run_jj(["log", "-T", "description", "--reversed", "--no-graph"]);
946 insta::assert_snapshot!(output, @"
947 first
948 second
949 [EOF]
950 ");
951 }
952
953 #[test]
954 fn test_log_filtered_by_path() {
955 let test_env = TestEnvironment::default();
956 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
957 let work_dir = test_env.work_dir("repo");
958
959 work_dir.write_file("file1", "foo\n");
960 work_dir.run_jj(["describe", "-m", "first"]).success();
961 work_dir.run_jj(["new", "-m", "second"]).success();
962 work_dir.write_file("file1", "foo\nbar\n");
963 work_dir.write_file("file2", "baz\n");
964
965 // The output filtered to a non-existent file should display a warning.
966 let output = work_dir.run_jj(["log", "-r", "@-", "-T", "description", "nonexistent"]);
967 insta::assert_snapshot!(output, @"
968 ------- stderr -------
969 Warning: No matching entries for paths: nonexistent
970 [EOF]
971 ");
972
973 // The output filtered to a non-existent file should display a warning.
974 // The warning should be displayed at the beginning of the output.
975 let output = work_dir.run_jj(["log", "-T", "description", "nonexistent"]);
976 insta::assert_snapshot!(output, @r#"
977 ------- stderr -------
978 Warning: No matching entries for paths: nonexistent
979 Warning: The argument "nonexistent" is being interpreted as a fileset expression. To specify a revset, pass -r "nonexistent" instead.
980 [EOF]
981 "#);
982
983 let output = work_dir.run_jj(["log", "-T", "description", "file1"]);
984 insta::assert_snapshot!(output, @"
985 @ second
986 ○ first
987 │
988 ~
989 [EOF]
990 ");
991
992 let output = work_dir.run_jj(["log", "-T", "description", "file2"]);
993 insta::assert_snapshot!(output, @"
994 @ second
995 │
996 ~
997 [EOF]
998 ");
999
1000 let output = work_dir.run_jj(["log", "-T", "description", "-s", "file1"]);
1001 insta::assert_snapshot!(output, @"
1002 @ second
1003 │ M file1
1004 ○ first
1005 │ A file1
1006 ~
1007 [EOF]
1008 ");
1009
1010 let output = work_dir.run_jj(["log", "-T", "description", "-s", "file2", "--no-graph"]);
1011 insta::assert_snapshot!(output, @"
1012 second
1013 A file2
1014 [EOF]
1015 ");
1016
1017 // empty revisions are filtered out by "all()" fileset.
1018 let output = work_dir.run_jj(["log", "-Tdescription", "-s", "all()"]);
1019 insta::assert_snapshot!(output, @"
1020 @ second
1021 │ M file1
1022 │ A file2
1023 ○ first
1024 │ A file1
1025 ~
1026 [EOF]
1027 ");
1028
1029 // "root:<path>" is resolved relative to the workspace root.
1030 let output = test_env.run_jj_in(
1031 ".",
1032 [
1033 "log",
1034 "-R",
1035 work_dir.root().to_str().unwrap(),
1036 "-Tdescription",
1037 "-s",
1038 "root:file1",
1039 ],
1040 );
1041 insta::assert_snapshot!(output.normalize_backslash(), @"
1042 @ second
1043 │ M repo/file1
1044 ○ first
1045 │ A repo/file1
1046 ~
1047 [EOF]
1048 ");
1049
1050 // files() revset doesn't filter the diff.
1051 let output = work_dir.run_jj([
1052 "log",
1053 "-T",
1054 "description",
1055 "-s",
1056 "-rfiles(file2)",
1057 "--no-graph",
1058 ]);
1059 insta::assert_snapshot!(output, @"
1060 second
1061 M file1
1062 A file2
1063 [EOF]
1064 ");
1065 }
1066
1067 #[test]
1068 fn test_log_limit() {
1069 let test_env = TestEnvironment::default();
1070 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
1071 let work_dir = test_env.work_dir("repo");
1072
1073 work_dir.run_jj(["describe", "-m", "a"]).success();
1074 work_dir.write_file("a", "");
1075 work_dir.run_jj(["new", "-m", "b"]).success();
1076 work_dir.write_file("b", "");
1077 work_dir.run_jj(["new", "-m", "c", "subject(a)"]).success();
1078 work_dir.write_file("c", "");
1079 work_dir
1080 .run_jj(["new", "-m", "d", "subject(c)", "subject(b)"])
1081 .success();
1082
1083 let output = work_dir.run_jj(["log", "-T", "description", "--limit=3"]);
1084 insta::assert_snapshot!(output, @"
1085 @ d
1086 ├─╮
1087 │ ○ b
1088 ○ │ c
1089 ├─╯
1090 [EOF]
1091 ");
1092
1093 // Applied on sorted DAG
1094 let output = work_dir.run_jj(["log", "-T", "description", "--limit=2"]);
1095 insta::assert_snapshot!(output, @"
1096 @ d
1097 ├─╮
1098 │ ○ b
1099 [EOF]
1100 ");
1101
1102 let output = work_dir.run_jj(["log", "-T", "description", "--limit=2", "--no-graph"]);
1103 insta::assert_snapshot!(output, @"
1104 d
1105 c
1106 [EOF]
1107 ");
1108
1109 // Applied on reversed DAG: Because the node "a" is omitted, "b" and "c" are
1110 // rendered as roots.
1111 let output = work_dir.run_jj(["log", "-T", "description", "--limit=3", "--reversed"]);
1112 insta::assert_snapshot!(output, @"
1113 ○ c
1114 │ ○ b
1115 ├─╯
1116 @ d
1117 [EOF]
1118 ");
1119 let output = work_dir.run_jj([
1120 "log",
1121 "-T",
1122 "description",
1123 "--limit=3",
1124 "--reversed",
1125 "--no-graph",
1126 ]);
1127 insta::assert_snapshot!(output, @"
1128 b
1129 c
1130 d
1131 [EOF]
1132 ");
1133
1134 // Applied on filtered commits
1135 let output = work_dir.run_jj(["log", "-T", "description", "--limit=1", "b", "c"]);
1136 insta::assert_snapshot!(output, @"
1137 ○ c
1138 │
1139 ~
1140 [EOF]
1141 ------- stderr -------
1142 Warning: No matching entries for paths: b
1143 [EOF]
1144 ");
1145 }
1146
1147 #[test]
1148 fn test_log_warn_path_might_be_revset() {
1149 let test_env = TestEnvironment::default();
1150 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
1151 let work_dir = test_env.work_dir("repo");
1152
1153 work_dir.write_file("file1", "foo\n");
1154
1155 // Don't warn if the file actually exists.
1156 let output = work_dir.run_jj(["log", "file1", "-T", "description"]);
1157 insta::assert_snapshot!(output, @"
1158 @
1159 │
1160 ~
1161 [EOF]
1162 ");
1163
1164 // Warn for `jj log .` specifically, for former Mercurial users.
1165 let output = work_dir.run_jj(["log", ".", "-T", "description"]);
1166 insta::assert_snapshot!(output, @r#"
1167 @
1168 │
1169 ~
1170 [EOF]
1171 ------- stderr -------
1172 Warning: The argument "." is being interpreted as a fileset expression, but this is often not useful because all non-empty commits touch '.'. If you meant to show the working copy commit, pass -r '@' instead.
1173 [EOF]
1174 "#);
1175
1176 // warn when checking `jj log .` in a subdirectory because this folder hasn't
1177 // been added to the working copy, yet.
1178 let sub_dir = work_dir.create_dir_all("dir");
1179 let output = sub_dir.run_jj(["log", "."]);
1180 insta::assert_snapshot!(output, @"
1181 ------- stderr -------
1182 Warning: No matching entries for paths: .
1183 [EOF]
1184 ");
1185
1186 // Warn for `jj log @` instead of `jj log -r @`.
1187 let output = work_dir.run_jj(["log", "@", "-T", "description"]);
1188 insta::assert_snapshot!(output, @r#"
1189 ------- stderr -------
1190 Warning: No matching entries for paths: @
1191 Warning: The argument "@" is being interpreted as a fileset expression. To specify a revset, pass -r "@" instead.
1192 [EOF]
1193 "#);
1194
1195 // Warn when there's no path with the provided name.
1196 let output = work_dir.run_jj(["log", "file2", "-T", "description"]);
1197 insta::assert_snapshot!(output, @r#"
1198 ------- stderr -------
1199 Warning: No matching entries for paths: file2
1200 Warning: The argument "file2" is being interpreted as a fileset expression. To specify a revset, pass -r "file2" instead.
1201 [EOF]
1202 "#);
1203
1204 // If an explicit revision is provided, then suppress the warning.
1205 let output = work_dir.run_jj(["log", "@", "-r", "@", "-T", "description"]);
1206 insta::assert_snapshot!(output, @"
1207 ------- stderr -------
1208 Warning: No matching entries for paths: @
1209 [EOF]
1210 ");
1211 }
1212
1213 #[test]
1214 fn test_default_revset() {
1215 let test_env = TestEnvironment::default();
1216 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
1217 let work_dir = test_env.work_dir("repo");
1218
1219 work_dir.write_file("file1", "foo\n");
1220 work_dir.run_jj(["describe", "-m", "add a file"]).success();
1221
1222 // The built-in default log revset can be composed with other revsets.
1223 insta::assert_snapshot!(
1224 work_dir.run_jj(["log", "-r", "builtin_log() & @", "-T", "description"]), @"
1225 @ add a file
1226 │
1227 ~
1228 [EOF]
1229 ");
1230
1231 // Set configuration to only show the root commit.
1232 test_env.add_config(r#"revsets.log = "root()""#);
1233
1234 // Log should only contain one line (for the root commit), and not show the
1235 // commit created above.
1236 insta::assert_snapshot!(work_dir.run_jj(["log", "-T", "commit_id"]), @"
1237 ◆ 0000000000000000000000000000000000000000
1238 [EOF]
1239 ");
1240
1241 // The default revset is not used if a path is specified
1242 insta::assert_snapshot!(work_dir.run_jj(["log", "file1", "-T", "description"]), @"
1243 @ add a file
1244 │
1245 ~
1246 [EOF]
1247 ");
1248 }
1249
1250 #[test]
1251 fn test_default_revset_per_repo() {
1252 let test_env = TestEnvironment::default();
1253 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
1254 let work_dir = test_env.work_dir("repo");
1255
1256 work_dir.write_file("file1", "foo\n");
1257 work_dir.run_jj(["describe", "-m", "add a file"]).success();
1258 work_dir
1259 .run_jj(["config", "set", "--repo", "revsets.log", "root()"])
1260 .success();
1261
1262 // Log should only contain one line (for the root commit), and not show the
1263 // commit created above.
1264 insta::assert_snapshot!(work_dir.run_jj(["log", "-T", "commit_id"]), @"
1265 ◆ 0000000000000000000000000000000000000000
1266 [EOF]
1267 ");
1268 }
1269
1270 #[test]
1271 fn test_multiple_revsets() {
1272 let test_env = TestEnvironment::default();
1273 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
1274 let work_dir = test_env.work_dir("repo");
1275 for name in ["foo", "bar", "baz"] {
1276 work_dir.run_jj(["new", "-m", name]).success();
1277 work_dir
1278 .run_jj(["bookmark", "create", "-r@", name])
1279 .success();
1280 }
1281
1282 // Default revset should be overridden if one or more -r options are specified.
1283 test_env.add_config(r#"revsets.log = "root()""#);
1284
1285 insta::assert_snapshot!(
1286 work_dir.run_jj(["log", "-T", "bookmarks", "-rfoo"]), @"
1287 ○ foo
1288 │
1289 ~
1290 [EOF]
1291 ");
1292 insta::assert_snapshot!(
1293 work_dir.run_jj(["log", "-T", "bookmarks", "-rfoo", "-rbar", "-rbaz"]), @"
1294 @ baz
1295 ○ bar
1296 ○ foo
1297 │
1298 ~
1299 [EOF]
1300 ");
1301 insta::assert_snapshot!(
1302 work_dir.run_jj(["log", "-T", "bookmarks", "-rfoo", "-rfoo"]), @"
1303 ○ foo
1304 │
1305 ~
1306 [EOF]
1307 ");
1308 }
1309
1310 #[test]
1311 fn test_graph_template_color() {
1312 // Test that color codes from a multi-line template don't span the graph lines.
1313 let test_env = TestEnvironment::default();
1314 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
1315 let work_dir = test_env.work_dir("repo");
1316
1317 work_dir
1318 .run_jj(["describe", "-m", "first line\nsecond line\nthird line"])
1319 .success();
1320 work_dir.run_jj(["new", "-m", "single line"]).success();
1321
1322 test_env.add_config(
1323 r#"[colors]
1324 description = "red"
1325 "working_copy description" = "green"
1326 "#,
1327 );
1328
1329 // First test without color for comparison
1330 let template = r#"label(if(current_working_copy, "working_copy"), description)"#;
1331 let output = work_dir.run_jj(["log", "-T", template]);
1332 insta::assert_snapshot!(output, @"
1333 @ single line
1334 ○ first line
1335 │ second line
1336 │ third line
1337 ◆
1338 [EOF]
1339 ");
1340 let output = work_dir.run_jj(["--color=always", "log", "-T", template]);
1341 insta::assert_snapshot!(output, @"
1342 @ single line
1343 ○ first line
1344 │ second line
1345 │ third line
1346 ◆
1347 [EOF]
1348 ");
1349 let output = work_dir.run_jj(["--color=debug", "log", "-T", template]);
1350 insta::assert_snapshot!(output, @"
1351 <<log commit node working_copy mutable::@>> <<log commit working_copy description::single line>>
1352 <<log commit node mutable::○>> <<log commit description::first line>>
1353 │ <<log commit description::second line>>
1354 │ <<log commit description::third line>>
1355 <<log commit node immutable::◆>>
1356 [EOF]
1357 ");
1358 }
1359
1360 #[test]
1361 fn test_graph_styles() {
1362 // Test that different graph styles are available.
1363 let test_env = TestEnvironment::default();
1364 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
1365 let work_dir = test_env.work_dir("repo");
1366
1367 work_dir.run_jj(["commit", "-m", "initial"]).success();
1368 work_dir
1369 .run_jj(["commit", "-m", "main bookmark 1"])
1370 .success();
1371 work_dir
1372 .run_jj(["describe", "-m", "main bookmark 2"])
1373 .success();
1374 work_dir
1375 .run_jj(["new", "-m", "side bookmark\nwith\nlong\ndescription"])
1376 .success();
1377 work_dir
1378 .run_jj(["new", "-m", "merge", "subject('main bookmark 1')", "@"])
1379 .success();
1380
1381 // Default (curved) style
1382 let output = work_dir.run_jj(["log", "-T=description"]);
1383 insta::assert_snapshot!(output, @"
1384 @ merge
1385 ├─╮
1386 │ ○ side bookmark
1387 │ │ with
1388 │ │ long
1389 │ │ description
1390 │ ○ main bookmark 2
1391 ├─╯
1392 ○ main bookmark 1
1393 ○ initial
1394 ◆
1395 [EOF]
1396 ");
1397
1398 // ASCII style
1399 test_env.add_config(r#"ui.graph.style = "ascii""#);
1400 let output = work_dir.run_jj(["log", "-T=description"]);
1401 insta::assert_snapshot!(output, @r"
1402 @ merge
1403 |\
1404 | o side bookmark
1405 | | with
1406 | | long
1407 | | description
1408 | o main bookmark 2
1409 |/
1410 o main bookmark 1
1411 o initial
1412 +
1413 [EOF]
1414 ");
1415
1416 // Large ASCII style
1417 test_env.add_config(r#"ui.graph.style = "ascii-large""#);
1418 let output = work_dir.run_jj(["log", "-T=description"]);
1419 insta::assert_snapshot!(output, @r"
1420 @ merge
1421 |\
1422 | \
1423 | o side bookmark
1424 | | with
1425 | | long
1426 | | description
1427 | o main bookmark 2
1428 | /
1429 |/
1430 o main bookmark 1
1431 o initial
1432 +
1433 [EOF]
1434 ");
1435
1436 // Curved style
1437 test_env.add_config(r#"ui.graph.style = "curved""#);
1438 let output = work_dir.run_jj(["log", "-T=description"]);
1439 insta::assert_snapshot!(output, @"
1440 @ merge
1441 ├─╮
1442 │ ○ side bookmark
1443 │ │ with
1444 │ │ long
1445 │ │ description
1446 │ ○ main bookmark 2
1447 ├─╯
1448 ○ main bookmark 1
1449 ○ initial
1450 ◆
1451 [EOF]
1452 ");
1453
1454 // Square style
1455 test_env.add_config(r#"ui.graph.style = "square""#);
1456 let output = work_dir.run_jj(["log", "-T=description"]);
1457 insta::assert_snapshot!(output, @"
1458 @ merge
1459 ├─┐
1460 │ ○ side bookmark
1461 │ │ with
1462 │ │ long
1463 │ │ description
1464 │ ○ main bookmark 2
1465 ├─┘
1466 ○ main bookmark 1
1467 ○ initial
1468 ◆
1469 [EOF]
1470 ");
1471
1472 // Invalid style name
1473 let output = work_dir.run_jj(["log", "--config=ui.graph.style=unknown"]);
1474 insta::assert_snapshot!(output, @"
1475 ------- stderr -------
1476 Config error: Invalid type or value for ui.graph.style
1477 Caused by: unknown variant `unknown`, expected one of `ascii`, `ascii-large`, `curved`, `square`
1478
1479 For help, see https://docs.jj-vcs.dev/latest/config/ or use `jj help -k config`.
1480 [EOF]
1481 [exit status: 1]
1482 ");
1483 }
1484
1485 #[test]
1486 fn test_log_word_wrap() {
1487 let test_env = TestEnvironment::default();
1488 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
1489 let work_dir = test_env.work_dir("repo");
1490 let render = |args: &[&str], columns: u32, word_wrap: bool| {
1491 let word_wrap = to_toml_value(word_wrap);
1492 work_dir.run_jj_with(|cmd| {
1493 cmd.args(args)
1494 .arg(format!("--config=ui.log-word-wrap={word_wrap}"))
1495 .env("COLUMNS", columns.to_string())
1496 })
1497 };
1498
1499 work_dir
1500 .run_jj(["commit", "-m", "main bookmark 1"])
1501 .success();
1502 work_dir
1503 .run_jj(["describe", "-m", "main bookmark 2"])
1504 .success();
1505 work_dir.run_jj(["new", "-m", "side"]).success();
1506 work_dir
1507 .run_jj(["new", "-m", "merge", "@--", "@"])
1508 .success();
1509
1510 // ui.log-word-wrap option applies to both graph/no-graph outputs
1511 insta::assert_snapshot!(render(&["log", "-r@"], 40, false), @"
1512 @ mzvwutvl [email protected] 2001-02-03 08:05:11 bafb1ee5
1513 │ (empty) merge
1514 ~
1515 [EOF]
1516 ");
1517 insta::assert_snapshot!(render(&["log", "-r@"], 40, true), @"
1518 @ mzvwutvl [email protected]
1519 │ 2001-02-03 08:05:11 bafb1ee5
1520 ~ (empty) merge
1521 [EOF]
1522 ");
1523 insta::assert_snapshot!(render(&["log", "--no-graph", "-r@"], 40, false), @"
1524 mzvwutvl [email protected] 2001-02-03 08:05:11 bafb1ee5
1525 (empty) merge
1526 [EOF]
1527 ");
1528 insta::assert_snapshot!(render(&["log", "--no-graph", "-r@"], 40, true), @"
1529 mzvwutvl [email protected]
1530 2001-02-03 08:05:11 bafb1ee5
1531 (empty) merge
1532 [EOF]
1533 ");
1534
1535 // Color labels should be preserved
1536 insta::assert_snapshot!(render(&["log", "-r@", "--color=always"], 40, true), @"
1537 @ mzvwutvl [38;5;[email protected]
1538 │ 2001-02-03 08:05:11 bafb1ee5
1539 ~ (empty) merge
1540 [EOF]
1541 ");
1542
1543 // Graph width should be subtracted from the term width
1544 let template = r#""0 1 2 3 4 5 6 7 8 9""#;
1545 insta::assert_snapshot!(render(&["log", "-T", template], 10, true), @"
1546 @ 0 1 2
1547 ├─╮ 3 4 5
1548 │ │ 6 7 8
1549 │ │ 9
1550 │ ○ 0 1 2
1551 │ │ 3 4 5
1552 │ │ 6 7 8
1553 │ │ 9
1554 │ ○ 0 1 2
1555 ├─╯ 3 4 5
1556 │ 6 7 8
1557 │ 9
1558 ○ 0 1 2 3
1559 │ 4 5 6 7
1560 │ 8 9
1561 ◆ 0 1 2 3
1562 4 5 6 7
1563 8 9
1564 [EOF]
1565 ");
1566
1567 // Shouldn't panic with $COLUMNS < graph_width
1568 insta::assert_snapshot!(render(&["log", "-r@"], 0, true), @"
1569 @ mzvwutvl
1570 │ [email protected]
1571 ~ 2001-02-03
1572 08:05:11
1573 bafb1ee5
1574 (empty)
1575 merge
1576 [EOF]
1577 ");
1578 insta::assert_snapshot!(render(&["log", "-r@"], 1, true), @"
1579 @ mzvwutvl
1580 │ [email protected]
1581 ~ 2001-02-03
1582 08:05:11
1583 bafb1ee5
1584 (empty)
1585 merge
1586 [EOF]
1587 ");
1588 }
1589
1590 #[test]
1591 fn test_log_word_wrap_with_hyperlinks() {
1592 let test_env = TestEnvironment::default();
1593 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
1594 let work_dir = test_env.work_dir("repo");
1595
1596 let template = r#"hyperlink("http://example.com", "long line to force wrapping")"#;
1597 let output = work_dir.run_jj_with(|cmd| {
1598 cmd.args(["log", "-r@", "-T", template, "--color=always"])
1599 .arg("--config=ui.log-word-wrap=true")
1600 .env("COLUMNS", "10")
1601 });
1602 insta::assert_snapshot!(output, @r"
1603 @ ]8;;http://example.com\long
1604 │ line to
1605 ~ force
1606 wrapping]8;;\
1607 [EOF]
1608 ");
1609 }
1610
1611 #[test]
1612 fn test_log_diff_stat_width() {
1613 let test_env = TestEnvironment::default();
1614 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
1615 let work_dir = test_env.work_dir("repo");
1616 let render = |args: &[&str], columns: u32| {
1617 work_dir.run_jj_with(|cmd| cmd.args(args).env("COLUMNS", columns.to_string()))
1618 };
1619
1620 work_dir.write_file("file1", "foo\n".repeat(100));
1621 work_dir.run_jj(["new", "root()"]).success();
1622 work_dir.write_file("file2", "foo\n".repeat(100));
1623
1624 insta::assert_snapshot!(render(&["log", "--stat", "--no-graph"], 30), @"
1625 rlvkpnrz [email protected] 2001-02-03 08:05:09 9490cfd3
1626 (no description set)
1627 file2 | 100 ++++++++++++++++++
1628 1 file changed, 100 insertions(+), 0 deletions(-)
1629 qpvuntsm [email protected] 2001-02-03 08:05:08 79f0968d
1630 (no description set)
1631 file1 | 100 ++++++++++++++++++
1632 1 file changed, 100 insertions(+), 0 deletions(-)
1633 zzzzzzzz root() 00000000
1634 0 files changed, 0 insertions(+), 0 deletions(-)
1635 [EOF]
1636 ");
1637
1638 // Graph width should be subtracted
1639 insta::assert_snapshot!(render(&["log", "--stat"], 30), @"
1640 @ rlvkpnrz [email protected] 2001-02-03 08:05:09 9490cfd3
1641 │ (no description set)
1642 │ file2 | 100 +++++++++++++++
1643 │ 1 file changed, 100 insertions(+), 0 deletions(-)
1644 │ ○ qpvuntsm [email protected] 2001-02-03 08:05:08 79f0968d
1645 ├─╯ (no description set)
1646 │ file1 | 100 +++++++++++++
1647 │ 1 file changed, 100 insertions(+), 0 deletions(-)
1648 ◆ zzzzzzzz root() 00000000
1649 0 files changed, 0 insertions(+), 0 deletions(-)
1650 [EOF]
1651 ");
1652 }
1653
1654 #[test]
1655 fn test_elided() {
1656 // Test that elided commits are shown as synthetic nodes.
1657 let test_env = TestEnvironment::default();
1658 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
1659 let work_dir = test_env.work_dir("repo");
1660
1661 work_dir.run_jj(["describe", "-m", "initial"]).success();
1662 work_dir.run_jj(["new", "-m", "main bookmark 1"]).success();
1663 work_dir.run_jj(["new", "-m", "main bookmark 2"]).success();
1664 work_dir
1665 .run_jj(["new", "@--", "-m", "side bookmark 1"])
1666 .success();
1667 work_dir.run_jj(["new", "-m", "side bookmark 2"]).success();
1668 work_dir
1669 .run_jj(["new", "-m", "merge", "subject('main bookmark 2')", "@"])
1670 .success();
1671
1672 let get_log = |revs: &str| work_dir.run_jj(["log", "-T", r#"description ++ "\n""#, "-r", revs]);
1673
1674 // Test the setup
1675 insta::assert_snapshot!(get_log("::"), @"
1676 @ merge
1677 ├─╮
1678 │ ○ side bookmark 2
1679 │ │
1680 │ ○ side bookmark 1
1681 │ │
1682 ○ │ main bookmark 2
1683 │ │
1684 ○ │ main bookmark 1
1685 ├─╯
1686 ○ initial
1687 │
1688 ◆
1689 [EOF]
1690 ");
1691
1692 // Elide some commits from each side of the merge. It's unclear that a revision
1693 // was skipped on the left side.
1694 test_env.add_config("ui.log-synthetic-elided-nodes = false");
1695 insta::assert_snapshot!(get_log("@ | @- | subject(initial)"), @"
1696 @ merge
1697 ├─╮
1698 │ ○ side bookmark 2
1699 │ ╷
1700 ○ ╷ main bookmark 2
1701 ├─╯
1702 ○ initial
1703 │
1704 ~
1705 [EOF]
1706 ");
1707
1708 // Elide shared commits. It's unclear that a revision was skipped on the right
1709 // side (#1252).
1710 insta::assert_snapshot!(get_log("@-- | root()"), @"
1711 ○ side bookmark 1
1712 ╷
1713 ╷ ○ main bookmark 1
1714 ╭─╯
1715 ◆
1716 [EOF]
1717 ");
1718
1719 // Now test the same thing with synthetic nodes for elided commits
1720
1721 // Elide some commits from each side of the merge
1722 test_env.add_config("ui.log-synthetic-elided-nodes = true");
1723 insta::assert_snapshot!(get_log("@ | @- | subject(initial)"), @"
1724 @ merge
1725 ├─╮
1726 │ ○ side bookmark 2
1727 │ │
1728 │ ~ (elided revisions)
1729 ○ │ main bookmark 2
1730 │ │
1731 ~ │ (elided revisions)
1732 ├─╯
1733 ○ initial
1734 │
1735 ~
1736 [EOF]
1737 ");
1738
1739 // Elide shared commits. To keep the implementation simple, it still gets
1740 // rendered as two synthetic nodes.
1741 insta::assert_snapshot!(get_log("@-- | root()"), @"
1742 ○ side bookmark 1
1743 │
1744 ~ (elided revisions)
1745 │ ○ main bookmark 1
1746 │ │
1747 │ ~ (elided revisions)
1748 ├─╯
1749 ◆
1750 [EOF]
1751 ");
1752 }
1753
1754 #[test]
1755 fn test_log_with_custom_symbols() {
1756 // Test that elided commits are shown as synthetic nodes.
1757 let test_env = TestEnvironment::default();
1758 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
1759 let work_dir = test_env.work_dir("repo");
1760
1761 work_dir.run_jj(["describe", "-m", "initial"]).success();
1762 work_dir.run_jj(["new", "-m", "main bookmark 1"]).success();
1763 work_dir.run_jj(["new", "-m", "main bookmark 2"]).success();
1764 work_dir
1765 .run_jj(["new", "@--", "-m", "side bookmark 1"])
1766 .success();
1767 work_dir.run_jj(["new", "-m", "side bookmark 2"]).success();
1768 work_dir
1769 .run_jj(["new", "-m", "merge", "subject('main bookmark 2')", "@"])
1770 .success();
1771
1772 let get_log = |revs: &str| work_dir.run_jj(["log", "-T", r#"description ++ "\n""#, "-r", revs]);
1773
1774 // Simple test with showing default and elided nodes.
1775 test_env.add_config(
1776 r###"
1777 ui.log-synthetic-elided-nodes = true
1778 templates.log_node = 'if(self, if(current_working_copy, "$", if(root, "┴", "┝")), "🮀")'
1779 "###,
1780 );
1781 insta::assert_snapshot!(get_log("@ | @- | subject(initial) | root()"), @"
1782 $ merge
1783 ├─╮
1784 │ ┝ side bookmark 2
1785 │ │
1786 │ 🮀 (elided revisions)
1787 ┝ │ main bookmark 2
1788 │ │
1789 🮀 │ (elided revisions)
1790 ├─╯
1791 ┝ initial
1792 │
1793 ┴
1794 [EOF]
1795 ");
1796
1797 // Simple test with showing default and elided nodes, ascii style.
1798 test_env.add_config(
1799 r###"
1800 ui.log-synthetic-elided-nodes = true
1801 ui.graph.style = 'ascii'
1802 templates.log_node = 'if(self, if(current_working_copy, "$", if(root, "^", "*")), ":")'
1803 "###,
1804 );
1805 insta::assert_snapshot!(get_log("@ | @- | subject(initial) | root()"), @r"
1806 $ merge
1807 |\
1808 | * side bookmark 2
1809 | |
1810 | : (elided revisions)
1811 * | main bookmark 2
1812 | |
1813 : | (elided revisions)
1814 |/
1815 * initial
1816 |
1817 ^
1818 [EOF]
1819 ");
1820 }
1821
1822 #[test]
1823 fn test_log_full_description_template() {
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 work_dir
1829 .run_jj([
1830 "commit",
1831 "-m",
1832 "this is commit with a multiline description\n\n<full description>",
1833 ])
1834 .success();
1835
1836 let output = work_dir.run_jj(["log", "-T", "builtin_log_compact_full_description"]);
1837 insta::assert_snapshot!(output, @"
1838 @ rlvkpnrz [email protected] 2001-02-03 08:05:08 3a70504b
1839 │ (empty) (no description set)
1840 │
1841 ○ qpvuntsm [email protected] 2001-02-03 08:05:08 37b69cda
1842 │ (empty) this is commit with a multiline description
1843 │
1844 │ <full description>
1845 │
1846 ◆ zzzzzzzz root() 00000000
1847
1848 [EOF]
1849 ");
1850 }
1851
1852 #[test]
1853 fn test_log_anonymize() {
1854 let test_env = TestEnvironment::default();
1855
1856 test_env.run_jj_in(".", ["git", "init", "origin"]).success();
1857 let origin_dir = test_env.work_dir("origin");
1858 let origin_git_repo = origin_dir.root().join(".jj/repo/store/git");
1859 let origin_git_repo = origin_git_repo.to_str().unwrap();
1860 origin_dir
1861 .run_jj([
1862 "describe",
1863 "-m",
1864 "this is commit with a multiline description\n\n<full description>",
1865 ])
1866 .success();
1867 origin_dir
1868 .run_jj(["bookmark", "create", "-r@", "b1", "b2", "b3"])
1869 .success();
1870 origin_dir.run_jj(["git", "export"]).success();
1871
1872 test_env
1873 .run_jj_in(".", ["git", "clone", origin_git_repo, "local"])
1874 .success();
1875 let work_dir = test_env.work_dir("local");
1876 work_dir.run_jj(["bookmark", "track", "b1 | b2"]).success();
1877 work_dir.run_jj(["new", "b1"]).success();
1878 work_dir.run_jj(["bookmark", "move", "b1", "-t@"]).success();
1879
1880 let output = work_dir.run_jj(["log", "-r::", "-Tbuiltin_log_redacted"]);
1881 insta::assert_snapshot!(output, @"
1882 @ yqosqzyt user-78cd 2001-02-03 08:05:13 bookmark-dc8b* de3c47af
1883 │ (empty) (redacted)
1884 ◆ qpvuntsm user-78cd 2001-02-03 08:05:08 bookmark-dc8b@remote-86e9 bookmark-56f1 bookmark-ff9e@remote-86e9 37b69cda
1885 │ (empty) (redacted)
1886 ◆ zzzzzzzz root() 00000000
1887 [EOF]
1888 ");
1889 }
1890
1891 #[test]
1892 fn test_log_count() {
1893 let test_env = TestEnvironment::default();
1894 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
1895 let work_dir = test_env.work_dir("repo");
1896
1897 work_dir.write_file("file1", "foo\n");
1898 work_dir.run_jj(["describe", "-m", "first"]).success();
1899 work_dir.run_jj(["new", "-m", "second"]).success();
1900 work_dir.write_file("file2", "bar\n");
1901 work_dir.run_jj(["new", "-m", "third"]).success();
1902
1903 let output = work_dir.run_jj(["log", "--count"]);
1904 insta::assert_snapshot!(output, @"
1905 4
1906 [EOF]
1907 ");
1908
1909 let output = work_dir.run_jj(["log", "--count", "-r", "all() ~ root()"]);
1910 insta::assert_snapshot!(output, @"
1911 3
1912 [EOF]
1913 ");
1914
1915 let output = work_dir.run_jj(["log", "--count", "--limit", "2"]);
1916 insta::assert_snapshot!(output, @"
1917 2
1918 [EOF]
1919 ");
1920
1921 // count the number of revisions directly
1922 // inexact revset size estimates (jj-lib testing-only) require 10+ revisions
1923 for i in 0..10 {
1924 work_dir
1925 .run_jj(["commit", "-m", &format!("extra {i}")])
1926 .success();
1927 }
1928 let output = work_dir.run_jj(["log", "--count"]);
1929 insta::assert_snapshot!(output, @"
1930 14
1931 [EOF]
1932 ");
1933 }