Debian Codegraph @

cli/tests/test_show_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 regex::Regex;
16 use testutils::TestResult;
17
18 use crate::common::TestEnvironment;
19
20 #[test]
21 fn test_show() {
22 let test_env = TestEnvironment::default();
23 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
24 let work_dir = test_env.work_dir("repo");
25
26 // Show @ by default
27 let output = work_dir.run_jj(["show"]);
28 let output = output.normalize_stdout_with(|s| s.split_inclusive('\n').skip(2).collect());
29
30 insta::assert_snapshot!(output, @"
31 Author : Test User <[email protected]> (2001-02-03 08:05:07)
32 Committer: Test User <[email protected]> (2001-02-03 08:05:07)
33
34 (no description set)
35
36 [EOF]
37 ");
38
39 // Specify revision with -r
40 let output = work_dir.run_jj(["show", "-r@-"]);
41 insta::assert_snapshot!(output, @"
42 Commit ID: 0000000000000000000000000000000000000000
43 Change ID: zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
44 Author : (no name set) <(no email set)> (1970-01-01 11:00:00)
45 Committer: (no name set) <(no email set)> (1970-01-01 11:00:00)
46
47 (no description set)
48
49 [EOF]
50 ");
51
52 // Specify both positional and -r args
53 let output = work_dir.run_jj(["show", "@", "-r@-"]);
54 insta::assert_snapshot!(output, @"
55 Commit ID: e8849ae12c709f2321908879bc724fdb2ab8a781
56 Change ID: qpvuntsmwlqtpsluzzsnyyzlmlwvmlnu
57 Author : Test User <[email protected]> (2001-02-03 08:05:07)
58 Committer: Test User <[email protected]> (2001-02-03 08:05:07)
59
60 (no description set)
61
62 Commit ID: 0000000000000000000000000000000000000000
63 Change ID: zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
64 Author : (no name set) <(no email set)> (1970-01-01 11:00:00)
65 Committer: (no name set) <(no email set)> (1970-01-01 11:00:00)
66
67 (no description set)
68
69 [EOF]
70 ");
71
72 // Specify empty revisions
73 let output = work_dir.run_jj(["show", "none()"]);
74 insta::assert_snapshot!(output, @"");
75 }
76
77 #[test]
78 fn test_show_basic() {
79 let test_env = TestEnvironment::default();
80 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
81 let work_dir = test_env.work_dir("repo");
82
83 work_dir.write_file("file1", "foo\n");
84 work_dir.write_file("file2", "foo\nbaz qux\n");
85 work_dir.run_jj(["new"]).success();
86 work_dir.remove_file("file1");
87 work_dir.write_file("file2", "foo\nbar\nbaz quux\n");
88 work_dir.write_file("file3", "foo\n");
89
90 let output = work_dir.run_jj(["show"]);
91 insta::assert_snapshot!(output, @"
92 Commit ID: 92e687faa4e5b681937f5a9c47feaa33e6b4892c
93 Change ID: rlvkpnrzqnoowoytxnquwvuryrwnrmlp
94 Author : Test User <[email protected]> (2001-02-03 08:05:09)
95 Committer: Test User <[email protected]> (2001-02-03 08:05:09)
96
97 (no description set)
98
99 Modified regular file file2:
100 1 1: foo
101 2 : baz qux
102 2: bar
103 3: baz quux
104 Modified regular file file3 (file1 => file3):
105 [EOF]
106 ");
107
108 let output = work_dir.run_jj(["show", "--context=0"]);
109 insta::assert_snapshot!(output, @"
110 Commit ID: 92e687faa4e5b681937f5a9c47feaa33e6b4892c
111 Change ID: rlvkpnrzqnoowoytxnquwvuryrwnrmlp
112 Author : Test User <[email protected]> (2001-02-03 08:05:09)
113 Committer: Test User <[email protected]> (2001-02-03 08:05:09)
114
115 (no description set)
116
117 Modified regular file file2:
118 1 1: foo
119 2 : baz qux
120 2: bar
121 3: baz quux
122 Modified regular file file3 (file1 => file3):
123 [EOF]
124 ");
125
126 let output = work_dir.run_jj(["show", "--color=debug"]);
127 insta::assert_snapshot!(output, @"
128 <<show commit::Commit ID: >><<show commit commit_id::92e687faa4e5b681937f5a9c47feaa33e6b4892c>><<show commit::>>
129 <<show commit::Change ID: >><<show commit change_id::rlvkpnrzqnoowoytxnquwvuryrwnrmlp>><<show commit::>>
130 <<show commit::Author : >><<show commit author name::Test User>><<show commit:: <>><<show commit author email local::test.user>><<show commit author email::@>><<show commit author email domain::example.com>><<show commit::> (>><<show commit author timestamp local format::2001-02-03 08:05:09>><<show commit::)>>
131 <<show commit::Committer: >><<show commit committer name::Test User>><<show commit:: <>><<show commit committer email local::test.user>><<show commit committer email::@>><<show commit committer email domain::example.com>><<show commit::> (>><<show commit committer timestamp local format::2001-02-03 08:05:09>><<show commit::)>>
132 <<show commit::>>
133 <<show commit description placeholder:: (no description set)>><<show commit::>>
134 <<show commit::>>
135 <<diff color_words header::Modified regular file file2:>>
136 <<diff color_words context removed line_number:: 1>><<diff color_words context:: >><<diff color_words context added line_number:: 1>><<diff color_words context::: foo>>
137 <<diff color_words:: >><<diff color_words added line_number:: 2>><<diff color_words::: >><<diff color_words added token::bar>>
138 <<diff color_words removed line_number:: 2>><<diff color_words:: >><<diff color_words added line_number:: 3>><<diff color_words::: baz >><<diff color_words removed token::qux>><<diff color_words added token::quux>><<diff color_words::>>
139 <<diff color_words header::Modified regular file file3 (file1 => file3):>>
140 [EOF]
141 ");
142
143 let output = work_dir.run_jj(["show", "-s"]);
144 insta::assert_snapshot!(output, @"
145 Commit ID: 92e687faa4e5b681937f5a9c47feaa33e6b4892c
146 Change ID: rlvkpnrzqnoowoytxnquwvuryrwnrmlp
147 Author : Test User <[email protected]> (2001-02-03 08:05:09)
148 Committer: Test User <[email protected]> (2001-02-03 08:05:09)
149
150 (no description set)
151
152 M file2
153 R {file1 => file3}
154 [EOF]
155 ");
156
157 let output = work_dir.run_jj(["show", "--types"]);
158 insta::assert_snapshot!(output, @"
159 Commit ID: 92e687faa4e5b681937f5a9c47feaa33e6b4892c
160 Change ID: rlvkpnrzqnoowoytxnquwvuryrwnrmlp
161 Author : Test User <[email protected]> (2001-02-03 08:05:09)
162 Committer: Test User <[email protected]> (2001-02-03 08:05:09)
163
164 (no description set)
165
166 FF file2
167 FF {file1 => file3}
168 [EOF]
169 ");
170
171 let output = work_dir.run_jj(["show", "--git"]);
172 insta::assert_snapshot!(output, @"
173 Commit ID: 92e687faa4e5b681937f5a9c47feaa33e6b4892c
174 Change ID: rlvkpnrzqnoowoytxnquwvuryrwnrmlp
175 Author : Test User <[email protected]> (2001-02-03 08:05:09)
176 Committer: Test User <[email protected]> (2001-02-03 08:05:09)
177
178 (no description set)
179
180 diff --git a/file2 b/file2
181 index 523a4a9de8..485b56a572 100644
182 --- a/file2
183 +++ b/file2
184 @@ -1,2 +1,3 @@
185 foo
186 -baz qux
187 +bar
188 +baz quux
189 diff --git a/file1 b/file3
190 rename from file1
191 rename to file3
192 [EOF]
193 ");
194
195 let output = work_dir.run_jj(["show", "--git", "--context=0"]);
196 insta::assert_snapshot!(output, @"
197 Commit ID: 92e687faa4e5b681937f5a9c47feaa33e6b4892c
198 Change ID: rlvkpnrzqnoowoytxnquwvuryrwnrmlp
199 Author : Test User <[email protected]> (2001-02-03 08:05:09)
200 Committer: Test User <[email protected]> (2001-02-03 08:05:09)
201
202 (no description set)
203
204 diff --git a/file2 b/file2
205 index 523a4a9de8..485b56a572 100644
206 --- a/file2
207 +++ b/file2
208 @@ -2,1 +2,2 @@
209 -baz qux
210 +bar
211 +baz quux
212 diff --git a/file1 b/file3
213 rename from file1
214 rename to file3
215 [EOF]
216 ");
217
218 let output = work_dir.run_jj(["show", "--git", "--color=debug"]);
219 insta::assert_snapshot!(output, @"
220 <<show commit::Commit ID: >><<show commit commit_id::92e687faa4e5b681937f5a9c47feaa33e6b4892c>><<show commit::>>
221 <<show commit::Change ID: >><<show commit change_id::rlvkpnrzqnoowoytxnquwvuryrwnrmlp>><<show commit::>>
222 <<show commit::Author : >><<show commit author name::Test User>><<show commit:: <>><<show commit author email local::test.user>><<show commit author email::@>><<show commit author email domain::example.com>><<show commit::> (>><<show commit author timestamp local format::2001-02-03 08:05:09>><<show commit::)>>
223 <<show commit::Committer: >><<show commit committer name::Test User>><<show commit:: <>><<show commit committer email local::test.user>><<show commit committer email::@>><<show commit committer email domain::example.com>><<show commit::> (>><<show commit committer timestamp local format::2001-02-03 08:05:09>><<show commit::)>>
224 <<show commit::>>
225 <<show commit description placeholder:: (no description set)>><<show commit::>>
226 <<show commit::>>
227 <<diff git file_header::diff --git a/file2 b/file2>>
228 <<diff git file_header::index 523a4a9de8..485b56a572 100644>>
229 <<diff git file_header::--- a/file2>>
230 <<diff git file_header::+++ b/file2>>
231 <<diff git hunk_header::@@ -1,2 +1,3 @@>>
232 <<diff git context:: foo>>
233 <<diff git removed::-baz >><<diff git removed token::qux>><<diff git removed::>>
234 <<diff git added::+>><<diff git added token::bar>>
235 <<diff git added::+baz >><<diff git added token::quux>><<diff git added::>>
236 <<diff git file_header::diff --git a/file1 b/file3>>
237 <<diff git file_header::rename from file1>>
238 <<diff git file_header::rename to file3>>
239 [EOF]
240 ");
241
242 let output = work_dir.run_jj(["show", "-s", "--git"]);
243 insta::assert_snapshot!(output, @"
244 Commit ID: 92e687faa4e5b681937f5a9c47feaa33e6b4892c
245 Change ID: rlvkpnrzqnoowoytxnquwvuryrwnrmlp
246 Author : Test User <[email protected]> (2001-02-03 08:05:09)
247 Committer: Test User <[email protected]> (2001-02-03 08:05:09)
248
249 (no description set)
250
251 M file2
252 R {file1 => file3}
253 diff --git a/file2 b/file2
254 index 523a4a9de8..485b56a572 100644
255 --- a/file2
256 +++ b/file2
257 @@ -1,2 +1,3 @@
258 foo
259 -baz qux
260 +bar
261 +baz quux
262 diff --git a/file1 b/file3
263 rename from file1
264 rename to file3
265 [EOF]
266 ");
267
268 let output = work_dir.run_jj(["show", "--stat"]);
269 insta::assert_snapshot!(output, @"
270 Commit ID: 92e687faa4e5b681937f5a9c47feaa33e6b4892c
271 Change ID: rlvkpnrzqnoowoytxnquwvuryrwnrmlp
272 Author : Test User <[email protected]> (2001-02-03 08:05:09)
273 Committer: Test User <[email protected]> (2001-02-03 08:05:09)
274
275 (no description set)
276
277 file2 | 3 ++-
278 {file1 => file3} | 0
279 2 files changed, 2 insertions(+), 1 deletion(-)
280 [EOF]
281 ");
282 }
283
284 #[test]
285 fn test_show_with_template() {
286 let test_env = TestEnvironment::default();
287 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
288 let work_dir = test_env.work_dir("repo");
289 work_dir.run_jj(["new", "-m", "a new commit"]).success();
290
291 let output = work_dir.run_jj(["show", "-T", "description"]);
292
293 insta::assert_snapshot!(output, @"
294 a new commit
295 [EOF]
296 ");
297 }
298
299 #[test]
300 fn test_show_with_template_no_patch() {
301 let test_env = TestEnvironment::default();
302 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
303 let work_dir = test_env.work_dir("repo");
304 work_dir.run_jj(["new", "-m", "a new commit"]).success();
305 work_dir.write_file("file1", "foo\n");
306
307 let output = work_dir.run_jj(["show", "--no-patch", "-T", "description"]);
308
309 insta::assert_snapshot!(output, @"
310 a new commit
311 [EOF]
312 ");
313 }
314
315 #[test]
316 fn test_show_with_no_patch() {
317 let test_env = TestEnvironment::default();
318 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
319 let work_dir = test_env.work_dir("repo");
320 work_dir.run_jj(["new", "-m", "a new commit"]).success();
321 work_dir.write_file("file1", "foo\n");
322
323 let output = work_dir.run_jj(["show", "--no-patch"]);
324
325 insta::assert_snapshot!(output, @"
326 Commit ID: 86d5fa72f4ecc6d51478941ee9160db9c52b842e
327 Change ID: rlvkpnrzqnoowoytxnquwvuryrwnrmlp
328 Author : Test User <[email protected]> (2001-02-03 08:05:08)
329 Committer: Test User <[email protected]> (2001-02-03 08:05:09)
330
331 a new commit
332
333 [EOF]
334 ");
335 }
336
337 #[test]
338 fn test_show_with_no_template() {
339 let test_env = TestEnvironment::default();
340 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
341 let work_dir = test_env.work_dir("repo");
342
343 let output = work_dir.run_jj(["show", "-T"]);
344 insta::assert_snapshot!(output, @"
345 ------- stderr -------
346 error: a value is required for '--template <TEMPLATE>' but none was supplied
347
348 For more information, try '--help'.
349 Hint: The following template aliases are defined:
350 - builtin_config_list
351 - builtin_config_list_detailed
352 - builtin_draft_commit_description
353 - builtin_draft_commit_description_with_diff
354 - builtin_evolog_compact
355 - builtin_log_comfortable
356 - builtin_log_compact
357 - builtin_log_compact_full_description
358 - builtin_log_detailed
359 - builtin_log_node
360 - builtin_log_node_ascii
361 - builtin_log_oneline
362 - builtin_log_redacted
363 - builtin_op_log_comfortable
364 - builtin_op_log_compact
365 - builtin_op_log_node
366 - builtin_op_log_node_ascii
367 - builtin_op_log_oneline
368 - builtin_op_log_redacted
369 - builtin_workspace_list
370 - commit_summary_separator
371 - default_commit_description
372 - description_placeholder
373 - email_placeholder
374 - empty_commit_marker
375 - git_format_patch_email_headers
376 - name_placeholder
377 [EOF]
378 [exit status: 2]
379 ");
380 }
381
382 #[test]
383 fn test_show_relative_timestamps() -> TestResult {
384 let test_env = TestEnvironment::default();
385 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
386 let work_dir = test_env.work_dir("repo");
387
388 test_env.add_config(
389 r#"
390 [template-aliases]
391 'format_timestamp(timestamp)' = 'timestamp.ago()'
392 "#,
393 );
394
395 let output = work_dir.run_jj(["show"]);
396 let timestamp_re = Regex::new(r"\([0-9]+ years ago\)")?;
397 let output = output.normalize_stdout_with(|s| {
398 s.split_inclusive('\n')
399 .skip(2)
400 .map(|x| timestamp_re.replace_all(x, "(...timestamp...)"))
401 .collect()
402 });
403
404 insta::assert_snapshot!(output, @"
405 Author : Test User <[email protected]> (...timestamp...)
406 Committer: Test User <[email protected]> (...timestamp...)
407
408 (no description set)
409
410 [EOF]
411 ");
412 Ok(())
413 }
414
415 #[test]
416 fn test_show_multiple_revisions() {
417 let test_env = TestEnvironment::default();
418 test_env.run_jj_in(".", ["git", "init", "repo"]).success();
419 let work_dir = test_env.work_dir("repo");
420
421 work_dir.write_file("file1", "a");
422 work_dir.run_jj(["commit", "-m", "add file1"]).success();
423
424 work_dir.write_file("file2", "b");
425 work_dir.run_jj(["commit", "-m", "add file2"]).success();
426
427 work_dir.write_file("file1", "c");
428 work_dir
429 .run_jj(["describe", "-m", "modify file1"])
430 .success();
431
432 let output = work_dir.run_jj(["show", "root()..@"]);
433 let output = output.normalize_stdout_with(|s| {
434 s.split_inclusive('\n')
435 .filter(|line| !line.starts_with("Change ID") && !line.starts_with("Commit ID"))
436 .collect()
437 });
438
439 insta::assert_snapshot!(output, @"
440 Author : Test User <[email protected]> (2001-02-03 08:05:10)
441 Committer: Test User <[email protected]> (2001-02-03 08:05:10)
442
443 modify file1
444
445 Modified regular file file1:
446 1 : a
447 1: c
448 Author : Test User <[email protected]> (2001-02-03 08:05:09)
449 Committer: Test User <[email protected]> (2001-02-03 08:05:09)
450
451 add file2
452
453 Added regular file file2:
454 1: b
455 Author : Test User <[email protected]> (2001-02-03 08:05:08)
456 Committer: Test User <[email protected]> (2001-02-03 08:05:08)
457
458 add file1
459
460 Added regular file file1:
461 1: a
462 [EOF]
463 ");
464
465 // Specify revision with -r
466 let output = work_dir.run_jj(["show", "-r", "root()..@"]);
467 let output = output.normalize_stdout_with(|s| {
468 s.split_inclusive('\n')
469 .filter(|line| !line.starts_with("Change ID") && !line.starts_with("Commit ID"))
470 .collect()
471 });
472
473 insta::assert_snapshot!(output, @"
474 Author : Test User <[email protected]> (2001-02-03 08:05:10)
475 Committer: Test User <[email protected]> (2001-02-03 08:05:10)
476
477 modify file1
478
479 Modified regular file file1:
480 1 : a
481 1: c
482 Author : Test User <[email protected]> (2001-02-03 08:05:09)
483 Committer: Test User <[email protected]> (2001-02-03 08:05:09)
484
485 add file2
486
487 Added regular file file2:
488 1: b
489 Author : Test User <[email protected]> (2001-02-03 08:05:08)
490 Committer: Test User <[email protected]> (2001-02-03 08:05:08)
491
492 add file1
493
494 Added regular file file1:
495 1: a
496 [EOF]
497 ");
498
499 // Older revisions first
500 let output = work_dir.run_jj(["show", "--reversed", "--no-patch", ".."]);
501 insta::assert_snapshot!(output, @"
502 Commit ID: 456f4073ef89a8fbee17002de8cd8429f35e7dc9
503 Change ID: qpvuntsmwlqtpsluzzsnyyzlmlwvmlnu
504 Author : Test User <[email protected]> (2001-02-03 08:05:08)
505 Committer: Test User <[email protected]> (2001-02-03 08:05:08)
506
507 add file1
508
509 Commit ID: 9155a29f167b8735506b1c10858a4abb9ef80e21
510 Change ID: rlvkpnrzqnoowoytxnquwvuryrwnrmlp
511 Author : Test User <[email protected]> (2001-02-03 08:05:09)
512 Committer: Test User <[email protected]> (2001-02-03 08:05:09)
513
514 add file2
515
516 Commit ID: 997b28cbf801ff095e70f203f75731c955688350
517 Change ID: kkmpptxzrspxrzommnulwmwkkqwworpl
518 Author : Test User <[email protected]> (2001-02-03 08:05:10)
519 Committer: Test User <[email protected]> (2001-02-03 08:05:10)
520
521 modify file1
522
523 [EOF]
524 ");
525
526 let output = work_dir.run_jj(["show", "--no-patch", "root()..@"]);
527 let output = output.normalize_stdout_with(|s| {
528 s.split_inclusive('\n')
529 .filter(|line| !line.starts_with("Change ID") && !line.starts_with("Commit ID"))
530 .collect()
531 });
532
533 insta::assert_snapshot!(output, @"
534 Author : Test User <[email protected]> (2001-02-03 08:05:10)
535 Committer: Test User <[email protected]> (2001-02-03 08:05:10)
536
537 modify file1
538
539 Author : Test User <[email protected]> (2001-02-03 08:05:09)
540 Committer: Test User <[email protected]> (2001-02-03 08:05:09)
541
542 add file2
543
544 Author : Test User <[email protected]> (2001-02-03 08:05:08)
545 Committer: Test User <[email protected]> (2001-02-03 08:05:08)
546
547 add file1
548
549 [EOF]
550 ");
551
552 let output = work_dir.run_jj(["show", "--git", "root()..@"]);
553 let output = output.normalize_stdout_with(|s| {
554 s.split_inclusive('\n')
555 .filter(|line| {
556 !line.starts_with("Change ID")
557 && !line.starts_with("Commit ID")
558 && !line.starts_with("index")
559 })
560 .collect()
561 });
562
563 insta::assert_snapshot!(output, @"
564 Author : Test User <[email protected]> (2001-02-03 08:05:10)
565 Committer: Test User <[email protected]> (2001-02-03 08:05:10)
566
567 modify file1
568
569 diff --git a/file1 b/file1
570 --- a/file1
571 +++ b/file1
572 @@ -1,1 +1,1 @@
573 -a
574 \\ No newline at end of file
575 +c
576 \\ No newline at end of file
577 Author : Test User <[email protected]> (2001-02-03 08:05:09)
578 Committer: Test User <[email protected]> (2001-02-03 08:05:09)
579
580 add file2
581
582 diff --git a/file2 b/file2
583 new file mode 100644
584 --- /dev/null
585 +++ b/file2
586 @@ -0,0 +1,1 @@
587 +b
588 \\ No newline at end of file
589 Author : Test User <[email protected]> (2001-02-03 08:05:08)
590 Committer: Test User <[email protected]> (2001-02-03 08:05:08)
591
592 add file1
593
594 diff --git a/file1 b/file1
595 new file mode 100644
596 --- /dev/null
597 +++ b/file1
598 @@ -0,0 +1,1 @@
599 +a
600 \\ No newline at end of file
601 [EOF]
602 ");
603 }