2022-11-26 23:57:50 +00:00
// Copyright 2022 The Jujutsu Authors
2022-03-28 09:12:08 +00:00
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
2022-11-18 23:41:35 +00:00
use common ::{ get_stderr_string , get_stdout_string , TestEnvironment } ;
2022-03-30 17:47:11 +00:00
pub mod common ;
2022-03-28 09:12:08 +00:00
2022-11-28 14:32:44 +00:00
#[ test ]
fn test_log_with_empty_revision ( ) {
let test_env = TestEnvironment ::default ( ) ;
test_env . jj_cmd_success ( test_env . env_root ( ) , & [ " init " , " repo " , " --git " ] ) ;
let repo_path = test_env . env_root ( ) . join ( " repo " ) ;
let stderr = test_env . jj_cmd_cli_error ( & repo_path , & [ " log " , " -r= " ] ) ;
insta ::assert_snapshot! ( stderr , @ r ###"
2023-03-17 23:14:20 +00:00
error : a value is required for ' - - revisions < REVISIONS > ' but none was supplied
2022-11-28 14:32:44 +00:00
2023-03-17 23:14:20 +00:00
For more information , try ' - - help ' .
2022-11-28 14:32:44 +00:00
" ###);
}
2022-03-28 09:12:08 +00:00
#[ test ]
fn test_log_with_or_without_diff ( ) {
let test_env = TestEnvironment ::default ( ) ;
test_env . jj_cmd_success ( test_env . env_root ( ) , & [ " init " , " repo " , " --git " ] ) ;
let repo_path = test_env . env_root ( ) . join ( " repo " ) ;
std ::fs ::write ( repo_path . join ( " file1 " ) , " foo \n " ) . unwrap ( ) ;
test_env . jj_cmd_success ( & repo_path , & [ " describe " , " -m " , " add a file " ] ) ;
test_env . jj_cmd_success ( & repo_path , & [ " new " , " -m " , " a new commit " ] ) ;
std ::fs ::write ( repo_path . join ( " file1 " ) , " foo \n bar \n " ) . unwrap ( ) ;
let stdout = test_env . jj_cmd_success ( & repo_path , & [ " log " , " -T " , " description " ] ) ;
insta ::assert_snapshot! ( stdout , @ r ###"
2023-02-09 02:53:47 +00:00
@ a new commit
2023-03-15 03:37:56 +00:00
◉ add a file
◉
2022-03-28 09:12:08 +00:00
" ###);
let stdout = test_env . jj_cmd_success ( & repo_path , & [ " log " , " -T " , " description " , " -p " ] ) ;
insta ::assert_snapshot! ( stdout , @ r ###"
2023-02-09 02:53:47 +00:00
@ a new commit
│ Modified regular file file1 :
│ 1 1 : foo
│ 2 : bar
2023-03-15 03:37:56 +00:00
◉ add a file
2023-02-09 02:53:47 +00:00
│ Added regular file file1 :
│ 1 : foo
2023-03-15 03:37:56 +00:00
◉
2022-03-28 09:12:08 +00:00
" ###);
let stdout = test_env . jj_cmd_success ( & repo_path , & [ " log " , " -T " , " description " , " --no-graph " ] ) ;
insta ::assert_snapshot! ( stdout , @ r ###"
a new commit
add a file
" ###);
2022-12-13 12:24:24 +00:00
// `-p` for default diff output, `-s` for summary
let stdout = test_env . jj_cmd_success ( & repo_path , & [ " log " , " -T " , " description " , " -p " , " -s " ] ) ;
insta ::assert_snapshot! ( stdout , @ r ###"
2023-02-09 02:53:47 +00:00
@ a new commit
│ M file1
│ Modified regular file file1 :
│ 1 1 : foo
│ 2 : bar
2023-03-15 03:37:56 +00:00
◉ add a file
2023-02-09 02:53:47 +00:00
│ A file1
│ Added regular file file1 :
│ 1 : foo
2023-03-15 03:37:56 +00:00
◉
2022-12-13 12:24:24 +00:00
" ###);
// `-s` for summary, `--git` for git diff (which implies `-p`)
let stdout = test_env . jj_cmd_success ( & repo_path , & [ " log " , " -T " , " description " , " -s " , " --git " ] ) ;
insta ::assert_snapshot! ( stdout , @ r ###"
2023-02-09 02:53:47 +00:00
@ a new commit
│ M file1
│ diff - - git a / file1 b / file1
│ index 257 cc5642c .. . 3 bd1f0e297 100644
│ - - - a / file1
│ + + + b / file1
│ @ @ - 1 , 1 + 1 , 2 @ @
│ foo
│ + bar
2023-03-15 03:37:56 +00:00
◉ add a file
2023-02-09 02:53:47 +00:00
│ A file1
│ diff - - git a / file1 b / file1
│ new file mode 100644
│ index 0000000000 .. 257 cc5642c
│ - - - / dev / null
│ + + + b / file1
│ @ @ - 1 , 0 + 1 , 1 @ @
│ + foo
2023-03-15 03:37:56 +00:00
◉
2022-12-13 12:24:24 +00:00
" ###);
// `-p` enables default "summary" output, so `-s` is noop
let stdout = test_env . jj_cmd_success (
& repo_path ,
& [
" log " ,
" -T " ,
" description " ,
" -p " ,
" -s " ,
2023-02-06 06:42:27 +00:00
" --config-toml=ui.diff.format='summary' " ,
2022-12-13 12:24:24 +00:00
] ,
) ;
insta ::assert_snapshot! ( stdout , @ r ###"
2023-02-09 02:53:47 +00:00
@ a new commit
│ M file1
2023-03-15 03:37:56 +00:00
◉ add a file
2023-02-09 02:53:47 +00:00
│ A file1
2023-03-15 03:37:56 +00:00
◉
2022-12-13 12:24:24 +00:00
" ###);
// `-p` enables default "color-words" diff output, so `--color-words` is noop
let stdout = test_env . jj_cmd_success (
& repo_path ,
& [ " log " , " -T " , " description " , " -p " , " --color-words " ] ,
) ;
insta ::assert_snapshot! ( stdout , @ r ###"
2023-02-09 02:53:47 +00:00
@ a new commit
│ Modified regular file file1 :
│ 1 1 : foo
│ 2 : bar
2023-03-15 03:37:56 +00:00
◉ add a file
2023-02-09 02:53:47 +00:00
│ Added regular file file1 :
│ 1 : foo
2023-03-15 03:37:56 +00:00
◉
2022-12-13 12:24:24 +00:00
" ###);
// `--git` enables git diff, so `-p` is noop
2022-03-28 09:12:08 +00:00
let stdout = test_env . jj_cmd_success (
& repo_path ,
& [ " log " , " -T " , " description " , " --no-graph " , " -p " , " --git " ] ,
) ;
insta ::assert_snapshot! ( stdout , @ r ###"
a new commit
diff - - git a / file1 b / file1
index 257 cc5642c .. . 3 bd1f0e297 100644
- - - a / file1
+ + + b / file1
@ @ - 1 , 1 + 1 , 2 @ @
foo
+ bar
add a file
diff - - git a / file1 b / file1
new file mode 100644
index 0000000000 .. 257 cc5642c
- - - / dev / null
+ + + b / file1
@ @ - 1 , 0 + 1 , 1 @ @
+ foo
" ###);
2022-05-13 05:20:10 +00:00
2023-03-11 04:11:58 +00:00
// Cannot use both `--git` and `--color-words`
let stderr = test_env . jj_cmd_cli_error (
2022-12-13 12:24:24 +00:00
& repo_path ,
& [
" log " ,
" -T " ,
" description " ,
" --no-graph " ,
" -p " ,
" --git " ,
" --color-words " ,
] ,
) ;
2023-03-11 04:11:58 +00:00
insta ::assert_snapshot! ( stderr , @ r ###"
2023-03-17 23:14:20 +00:00
error : the argument ' - - git ' cannot be used with ' - - color - words '
2023-03-11 04:11:58 +00:00
Usage : jj log - - template < TEMPLATE > - - no - graph - - patch - - git [ PATHS ] .. .
2023-03-17 23:14:20 +00:00
For more information , try ' - - help ' .
2022-12-13 12:24:24 +00:00
" ###);
// `-s` with or without graph
2022-05-13 05:20:10 +00:00
let stdout = test_env . jj_cmd_success ( & repo_path , & [ " log " , " -T " , " description " , " -s " ] ) ;
insta ::assert_snapshot! ( stdout , @ r ###"
2023-02-09 02:53:47 +00:00
@ a new commit
│ M file1
2023-03-15 03:37:56 +00:00
◉ add a file
2023-02-09 02:53:47 +00:00
│ A file1
2023-03-15 03:37:56 +00:00
◉
2022-05-13 05:20:10 +00:00
" ###);
let stdout = test_env . jj_cmd_success (
& repo_path ,
& [ " log " , " -T " , " description " , " --no-graph " , " -s " ] ,
) ;
insta ::assert_snapshot! ( stdout , @ r ###"
a new commit
M file1
add a file
A file1
" ###);
// `--git` implies `-p`, with or without graph
let stdout = test_env . jj_cmd_success (
& repo_path ,
& [ " log " , " -T " , " description " , " -r " , " @ " , " --git " ] ,
) ;
insta ::assert_snapshot! ( stdout , @ r ###"
2023-02-09 02:53:47 +00:00
@ a new commit
│ diff - - git a / file1 b / file1
~ index 257 cc5642c .. . 3 bd1f0e297 100644
- - - a / file1
+ + + b / file1
@ @ - 1 , 1 + 1 , 2 @ @
foo
+ bar
2022-05-13 05:20:10 +00:00
" ###);
let stdout = test_env . jj_cmd_success (
& repo_path ,
& [ " log " , " -T " , " description " , " -r " , " @ " , " --no-graph " , " --git " ] ,
) ;
insta ::assert_snapshot! ( stdout , @ r ###"
a new commit
diff - - git a / file1 b / file1
index 257 cc5642c .. . 3 bd1f0e297 100644
- - - a / file1
+ + + b / file1
@ @ - 1 , 1 + 1 , 2 @ @
foo
+ bar
" ###);
2022-12-14 10:48:53 +00:00
// `--color-words` implies `-p`, with or without graph
let stdout = test_env . jj_cmd_success (
& repo_path ,
& [ " log " , " -T " , " description " , " -r " , " @ " , " --color-words " ] ,
) ;
insta ::assert_snapshot! ( stdout , @ r ###"
2023-02-09 02:53:47 +00:00
@ a new commit
│ Modified regular file file1 :
~ 1 1 : foo
2 : bar
2022-12-14 10:48:53 +00:00
" ###);
let stdout = test_env . jj_cmd_success (
& repo_path ,
& [
" log " ,
" -T " ,
" description " ,
" -r " ,
" @ " ,
" --no-graph " ,
" --color-words " ,
] ,
) ;
insta ::assert_snapshot! ( stdout , @ r ###"
a new commit
Modified regular file file1 :
1 1 : foo
2 : bar
" ###);
2022-03-28 09:12:08 +00:00
}
2022-05-09 17:38:23 +00:00
2023-01-03 00:24:00 +00:00
#[ test ]
2023-02-14 13:48:49 +00:00
fn test_log_shortest_accessors ( ) {
2023-01-03 00:24:00 +00:00
let test_env = TestEnvironment ::default ( ) ;
test_env . jj_cmd_success ( test_env . env_root ( ) , & [ " init " , " repo " , " --git " ] ) ;
let repo_path = test_env . env_root ( ) . join ( " repo " ) ;
2023-02-14 13:36:48 +00:00
let render = | rev , template | {
test_env . jj_cmd_success (
& repo_path ,
& [ " log " , " --no-graph " , " -r " , rev , " -T " , template ] ,
)
} ;
test_env . add_config (
r ###"
[ template - aliases ]
2023-02-28 11:30:57 +00:00
' format_id ( id ) ' = ' id . shortest ( 12 ) . prefix ( ) + + " [ " + + id . shortest ( 12 ) . rest ( ) + + " ] " '
2023-02-14 13:36:48 +00:00
" ###,
) ;
2023-01-03 00:24:00 +00:00
std ::fs ::write ( repo_path . join ( " file " ) , " original file \n " ) . unwrap ( ) ;
test_env . jj_cmd_success ( & repo_path , & [ " describe " , " -m " , " initial " ] ) ;
test_env . jj_cmd_success ( & repo_path , & [ " branch " , " c " , " original " ] ) ;
insta ::assert_snapshot! (
2023-02-28 11:30:57 +00:00
render ( " original " , r # "format_id(change_id) ++ " " ++ format_id(commit_id)"# ) ,
2023-02-14 13:48:49 +00:00
@ " q[pvuntsmwlqt] b[a1a30916d29] " ) ;
2023-02-06 07:06:44 +00:00
// Create a chain of 10 commits
for i in 1 .. 10 {
2023-01-03 00:24:00 +00:00
test_env . jj_cmd_success ( & repo_path , & [ " new " , " -m " , & format! ( " commit {i} " ) ] ) ;
std ::fs ::write ( repo_path . join ( " file " ) , format! ( " file {i} \n " ) ) . unwrap ( ) ;
}
2023-02-06 07:06:44 +00:00
// Create 2^3 duplicates of the chain
for _ in 0 .. 3 {
test_env . jj_cmd_success ( & repo_path , & [ " duplicate " , " description(commit) " ] ) ;
}
2023-01-03 00:24:00 +00:00
insta ::assert_snapshot! (
2023-02-28 11:30:57 +00:00
render ( " original " , r # "format_id(change_id) ++ " " ++ format_id(commit_id)"# ) ,
2023-02-14 13:48:49 +00:00
@ " qpv[untsmwlqt] ba1[a30916d29] " ) ;
2023-01-21 04:56:34 +00:00
insta ::assert_snapshot! (
2023-02-28 11:30:57 +00:00
render ( " :@ " , r # "change_id.shortest() ++ " " ++ commit_id.shortest() ++ "\n""# ) ,
2023-01-21 04:56:34 +00:00
@ r ###"
2023-02-14 13:48:49 +00:00
wq 03
km f7
kp e7
zn 38
yo 0 cf
vr 9 e
2023-05-06 00:12:08 +00:00
yq 06
2023-02-14 13:48:49 +00:00
ro 1 f
mz 7 b
qpv ba1
zzz 00
" ###);
2023-02-14 13:36:48 +00:00
2023-05-06 00:12:08 +00:00
insta ::assert_snapshot! (
render ( " :@ " , r # "format_id(change_id) ++ " " ++ format_id(commit_id) ++ "\n""# ) ,
@ r ###"
wq [ nwkozpkust ] 03 [ f51310b83e ]
km [ kuslswpqwq ] f7 [ 7 fb1909080 ]
kp [ qxywonksrl ] e7 [ 15 ad5db646 ]
zn [ kkpsqqskkl ] 38 [ 622e54 e2e5 ]
yo [ stqsxwqrlt ] 0 cf [ 42 f60199c ]
vr [ uxwmqvtpmx ] 9 e [ 6015e4 e622 ]
yq [ osqzytrlsw ] 06 [ f34d9b1475 ]
ro [ yxmykxtrkr ] 1 f [ 99 a5e19891 ]
mz [ vwutvlkqwt ] 7 b [ 1 f7dee65b4 ]
qpv [ untsmwlqt ] ba1 [ a30916d29 ]
zzz [ zzzzzzzzz ] 00 [ 0000000000 ]
" ###);
// Can get shorter prefixes in configured revset
test_env . add_config ( r # "revsets.short-prefixes = "(@----):""# ) ;
insta ::assert_snapshot! (
render ( " :@ " , r # "format_id(change_id) ++ " " ++ format_id(commit_id) ++ "\n""# ) ,
@ r ###"
w [ qnwkozpkust ] 03 [ f51310b83e ]
km [ kuslswpqwq ] f [ 77 fb1909080 ]
kp [ qxywonksrl ] e [ 715 ad5db646 ]
z [ nkkpsqqskkl ] 3 [ 8622e54 e2e5 ]
y [ ostqsxwqrlt ] 0 c [ f42f60199c ]
vr [ uxwmqvtpmx ] 9 e [ 6015e4 e622 ]
yq [ osqzytrlsw ] 06 f [ 34 d9b1475 ]
ro [ yxmykxtrkr ] 1 f [ 99 a5e19891 ]
mz [ vwutvlkqwt ] 7 b [ 1 f7dee65b4 ]
qpv [ untsmwlqt ] ba1 [ a30916d29 ]
zzz [ zzzzzzzzz ] 00 [ 0000000000 ]
" ###);
// Can disable short prefixes by setting to empty string
test_env . add_config ( r # "revsets.short-prefixes = """# ) ;
2023-02-14 13:36:48 +00:00
insta ::assert_snapshot! (
2023-02-28 11:30:57 +00:00
render ( " :@ " , r # "format_id(change_id) ++ " " ++ format_id(commit_id) ++ "\n""# ) ,
2023-02-14 13:36:48 +00:00
@ r ###"
wq [ nwkozpkust ] 03 [ f51310b83e ]
km [ kuslswpqwq ] f7 [ 7 fb1909080 ]
kp [ qxywonksrl ] e7 [ 15 ad5db646 ]
zn [ kkpsqqskkl ] 38 [ 622e54 e2e5 ]
yo [ stqsxwqrlt ] 0 cf [ 42 f60199c ]
vr [ uxwmqvtpmx ] 9 e [ 6015e4 e622 ]
yq [ osqzytrlsw ] 06 f [ 34 d9b1475 ]
ro [ yxmykxtrkr ] 1 f [ 99 a5e19891 ]
mz [ vwutvlkqwt ] 7 b [ 1 f7dee65b4 ]
qpv [ untsmwlqt ] ba1 [ a30916d29 ]
zzz [ zzzzzzzzz ] 00 [ 0000000000 ]
" ###);
2023-01-21 04:56:34 +00:00
}
#[ test ]
fn test_log_prefix_highlight_styled ( ) {
let test_env = TestEnvironment ::default ( ) ;
test_env . jj_cmd_success ( test_env . env_root ( ) , & [ " init " , " repo " , " --git " ] ) ;
let repo_path = test_env . env_root ( ) . join ( " repo " ) ;
fn prefix_format ( len : Option < usize > ) -> String {
format! (
2023-02-28 10:43:14 +00:00
r ###"
separate ( " " ,
" Change " ,
change_id . shortest ( { 0 } ) ,
description . first_line ( ) ,
commit_id . shortest ( { 0 } ) ,
branches ,
)
" ###,
2023-01-21 04:56:34 +00:00
len . map ( | l | l . to_string ( ) ) . unwrap_or ( String ::default ( ) )
)
}
std ::fs ::write ( repo_path . join ( " file " ) , " original file \n " ) . unwrap ( ) ;
test_env . jj_cmd_success ( & repo_path , & [ " describe " , " -m " , " initial " ] ) ;
test_env . jj_cmd_success ( & repo_path , & [ " branch " , " c " , " original " ] ) ;
insta ::assert_snapshot! (
2023-02-06 05:38:54 +00:00
test_env . jj_cmd_success ( & repo_path , & [ " log " , " -r " , " original " , " -T " , & prefix_format ( Some ( 12 ) ) ] ) ,
2023-01-21 04:56:34 +00:00
@ r ###"
2023-02-12 20:07:28 +00:00
@ Change qpvuntsmwlqt initial ba1a30916d29 original
2023-02-09 02:53:47 +00:00
│
~
2023-01-21 04:56:34 +00:00
" ###
) ;
2023-02-06 07:06:44 +00:00
// Create a chain of 10 commits
for i in 1 .. 10 {
2023-01-21 04:56:34 +00:00
test_env . jj_cmd_success ( & repo_path , & [ " new " , " -m " , & format! ( " commit {i} " ) ] ) ;
std ::fs ::write ( repo_path . join ( " file " ) , format! ( " file {i} \n " ) ) . unwrap ( ) ;
}
2023-02-06 07:06:44 +00:00
// Create 2^3 duplicates of the chain
for _ in 0 .. 3 {
test_env . jj_cmd_success ( & repo_path , & [ " duplicate " , " description(commit) " ] ) ;
}
2023-01-21 04:56:34 +00:00
insta ::assert_snapshot! (
2023-02-06 05:38:54 +00:00
test_env . jj_cmd_success ( & repo_path , & [ " log " , " -r " , " original " , " -T " , & prefix_format ( Some ( 12 ) ) ] ) ,
2023-01-21 04:56:34 +00:00
@ r ###"
2023-03-15 03:37:56 +00:00
◉ Change qpvuntsmwlqt initial ba1a30916d29 original
2023-02-09 02:53:47 +00:00
│
~
2023-01-21 04:56:34 +00:00
" ###
) ;
let stdout = test_env . jj_cmd_success (
& repo_path ,
& [
" --color=always " ,
" log " ,
" -r " ,
" @-----------..@ " ,
" -T " ,
2023-02-06 05:38:54 +00:00
& prefix_format ( Some ( 12 ) ) ,
2023-01-21 04:56:34 +00:00
] ,
) ;
insta ::assert_snapshot! ( stdout ,
@ r ###"
2023-02-13 04:53:04 +00:00
@ Change [ 1 m [ 38 ; 5 ; 5 mwq [ 0 m [ 38 ; 5 ; 8 mnwkozpkust [ 39 m commit9 [ 1 m [ 38 ; 5 ; 4 m03 [ 0 m [ 38 ; 5 ; 8 mf51310b83e [ 39 m
2023-03-15 03:37:56 +00:00
◉ Change [ 1 m [ 38 ; 5 ; 5 mkm [ 0 m [ 38 ; 5 ; 8 mkuslswpqwq [ 39 m commit8 [ 1 m [ 38 ; 5 ; 4 mf7 [ 0 m [ 38 ; 5 ; 8 m7fb1909080 [ 39 m
◉ Change [ 1 m [ 38 ; 5 ; 5 mkp [ 0 m [ 38 ; 5 ; 8 mqxywonksrl [ 39 m commit7 [ 1 m [ 38 ; 5 ; 4 me7 [ 0 m [ 38 ; 5 ; 8 m15ad5db646 [ 39 m
◉ Change [ 1 m [ 38 ; 5 ; 5 mzn [ 0 m [ 38 ; 5 ; 8 mkkpsqqskkl [ 39 m commit6 [ 1 m [ 38 ; 5 ; 4 m38 [ 0 m [ 38 ; 5 ; 8 m622e54e2e5 [ 39 m
◉ Change [ 1 m [ 38 ; 5 ; 5 myo [ 0 m [ 38 ; 5 ; 8 mstqsxwqrlt [ 39 m commit5 [ 1 m [ 38 ; 5 ; 4 m0cf [ 0 m [ 38 ; 5 ; 8 m42f60199c [ 39 m
◉ Change [ 1 m [ 38 ; 5 ; 5 mvr [ 0 m [ 38 ; 5 ; 8 muxwmqvtpmx [ 39 m commit4 [ 1 m [ 38 ; 5 ; 4 m9e [ 0 m [ 38 ; 5 ; 8 m6015e4e622 [ 39 m
2023-05-06 00:12:08 +00:00
◉ Change [ 1 m [ 38 ; 5 ; 5 myq [ 0 m [ 38 ; 5 ; 8 mosqzytrlsw [ 39 m commit3 [ 1 m [ 38 ; 5 ; 4 m06 [ 0 m [ 38 ; 5 ; 8 mf34d9b1475 [ 39 m
2023-03-15 03:37:56 +00:00
◉ Change [ 1 m [ 38 ; 5 ; 5 mro [ 0 m [ 38 ; 5 ; 8 myxmykxtrkr [ 39 m commit2 [ 1 m [ 38 ; 5 ; 4 m1f [ 0 m [ 38 ; 5 ; 8 m99a5e19891 [ 39 m
◉ Change [ 1 m [ 38 ; 5 ; 5 mmz [ 0 m [ 38 ; 5 ; 8 mvwutvlkqwt [ 39 m commit1 [ 1 m [ 38 ; 5 ; 4 m7b [ 0 m [ 38 ; 5 ; 8 m1f7dee65b4 [ 39 m
◉ Change [ 1 m [ 38 ; 5 ; 5 mqpv [ 0 m [ 38 ; 5 ; 8 muntsmwlqt [ 39 m initial [ 1 m [ 38 ; 5 ; 4 mba1 [ 0 m [ 38 ; 5 ; 8 ma30916d29 [ 39 m [ 38 ; 5 ; 5 moriginal [ 39 m
◉ Change [ 1 m [ 38 ; 5 ; 5 mzzz [ 0 m [ 38 ; 5 ; 8 mzzzzzzzzz [ 39 m [ 1 m [ 38 ; 5 ; 4 m00 [ 0 m [ 38 ; 5 ; 8 m0000000000 [ 39 m
2023-01-21 04:56:34 +00:00
" ###
) ;
let stdout = test_env . jj_cmd_success (
& repo_path ,
& [
" --color=always " ,
" log " ,
" -r " ,
" @-----------..@ " ,
" -T " ,
& prefix_format ( Some ( 3 ) ) ,
] ,
) ;
insta ::assert_snapshot! ( stdout ,
@ r ###"
2023-02-13 04:53:04 +00:00
@ Change [ 1 m [ 38 ; 5 ; 5 mwq [ 0 m [ 38 ; 5 ; 8 mn [ 39 m commit9 [ 1 m [ 38 ; 5 ; 4 m03 [ 0 m [ 38 ; 5 ; 8 mf [ 39 m
2023-03-15 03:37:56 +00:00
◉ Change [ 1 m [ 38 ; 5 ; 5 mkm [ 0 m [ 38 ; 5 ; 8 mk [ 39 m commit8 [ 1 m [ 38 ; 5 ; 4 mf7 [ 0 m [ 38 ; 5 ; 8 m7 [ 39 m
◉ Change [ 1 m [ 38 ; 5 ; 5 mkp [ 0 m [ 38 ; 5 ; 8 mq [ 39 m commit7 [ 1 m [ 38 ; 5 ; 4 me7 [ 0 m [ 38 ; 5 ; 8 m1 [ 39 m
◉ Change [ 1 m [ 38 ; 5 ; 5 mzn [ 0 m [ 38 ; 5 ; 8 mk [ 39 m commit6 [ 1 m [ 38 ; 5 ; 4 m38 [ 0 m [ 38 ; 5 ; 8 m6 [ 39 m
◉ Change [ 1 m [ 38 ; 5 ; 5 myo [ 0 m [ 38 ; 5 ; 8 ms [ 39 m commit5 [ 1 m [ 38 ; 5 ; 4 m0cf [ 0 m
◉ Change [ 1 m [ 38 ; 5 ; 5 mvr [ 0 m [ 38 ; 5 ; 8 mu [ 39 m commit4 [ 1 m [ 38 ; 5 ; 4 m9e [ 0 m [ 38 ; 5 ; 8 m6 [ 39 m
2023-05-06 00:12:08 +00:00
◉ Change [ 1 m [ 38 ; 5 ; 5 myq [ 0 m [ 38 ; 5 ; 8 mo [ 39 m commit3 [ 1 m [ 38 ; 5 ; 4 m06 [ 0 m [ 38 ; 5 ; 8 mf [ 39 m
2023-03-15 03:37:56 +00:00
◉ Change [ 1 m [ 38 ; 5 ; 5 mro [ 0 m [ 38 ; 5 ; 8 my [ 39 m commit2 [ 1 m [ 38 ; 5 ; 4 m1f [ 0 m [ 38 ; 5 ; 8 m9 [ 39 m
◉ Change [ 1 m [ 38 ; 5 ; 5 mmz [ 0 m [ 38 ; 5 ; 8 mv [ 39 m commit1 [ 1 m [ 38 ; 5 ; 4 m7b [ 0 m [ 38 ; 5 ; 8 m1 [ 39 m
◉ Change [ 1 m [ 38 ; 5 ; 5 mqpv [ 0 m initial [ 1 m [ 38 ; 5 ; 4 mba1 [ 0 m [ 38 ; 5 ; 5 moriginal [ 39 m
◉ Change [ 1 m [ 38 ; 5 ; 5 mzzz [ 0 m [ 1 m [ 38 ; 5 ; 4 m00 [ 0 m [ 38 ; 5 ; 8 m0 [ 39 m
2023-01-21 04:56:34 +00:00
" ###
) ;
let stdout = test_env . jj_cmd_success (
& repo_path ,
& [
" --color=always " ,
" log " ,
" -r " ,
" @-----------..@ " ,
" -T " ,
2023-02-06 05:38:54 +00:00
& prefix_format ( None ) ,
2023-01-21 04:56:34 +00:00
] ,
) ;
insta ::assert_snapshot! ( stdout ,
2023-01-03 00:24:00 +00:00
@ r ###"
2023-02-13 04:53:04 +00:00
@ Change [ 1 m [ 38 ; 5 ; 5 mwq [ 0 m commit9 [ 1 m [ 38 ; 5 ; 4 m03 [ 0 m
2023-03-15 03:37:56 +00:00
◉ Change [ 1 m [ 38 ; 5 ; 5 mkm [ 0 m commit8 [ 1 m [ 38 ; 5 ; 4 mf7 [ 0 m
◉ Change [ 1 m [ 38 ; 5 ; 5 mkp [ 0 m commit7 [ 1 m [ 38 ; 5 ; 4 me7 [ 0 m
◉ Change [ 1 m [ 38 ; 5 ; 5 mzn [ 0 m commit6 [ 1 m [ 38 ; 5 ; 4 m38 [ 0 m
◉ Change [ 1 m [ 38 ; 5 ; 5 myo [ 0 m commit5 [ 1 m [ 38 ; 5 ; 4 m0cf [ 0 m
◉ Change [ 1 m [ 38 ; 5 ; 5 mvr [ 0 m commit4 [ 1 m [ 38 ; 5 ; 4 m9e [ 0 m
2023-05-06 00:12:08 +00:00
◉ Change [ 1 m [ 38 ; 5 ; 5 myq [ 0 m commit3 [ 1 m [ 38 ; 5 ; 4 m06 [ 0 m
2023-03-15 03:37:56 +00:00
◉ Change [ 1 m [ 38 ; 5 ; 5 mro [ 0 m commit2 [ 1 m [ 38 ; 5 ; 4 m1f [ 0 m
◉ Change [ 1 m [ 38 ; 5 ; 5 mmz [ 0 m commit1 [ 1 m [ 38 ; 5 ; 4 m7b [ 0 m
◉ Change [ 1 m [ 38 ; 5 ; 5 mqpv [ 0 m initial [ 1 m [ 38 ; 5 ; 4 mba1 [ 0 m [ 38 ; 5 ; 5 moriginal [ 39 m
◉ Change [ 1 m [ 38 ; 5 ; 5 mzzz [ 0 m [ 1 m [ 38 ; 5 ; 4 m00 [ 0 m
2023-01-03 00:24:00 +00:00
" ###
) ;
}
#[ test ]
fn test_log_prefix_highlight_counts_hidden_commits ( ) {
let test_env = TestEnvironment ::default ( ) ;
test_env . jj_cmd_success ( test_env . env_root ( ) , & [ " init " , " repo " , " --git " ] ) ;
let repo_path = test_env . env_root ( ) . join ( " repo " ) ;
2023-02-14 13:48:49 +00:00
test_env . add_config (
r ###"
2023-05-22 03:27:03 +00:00
[ revsets ]
short - prefixes = " " # Disable short prefixes
2023-02-14 13:48:49 +00:00
[ template - aliases ]
2023-02-28 11:30:57 +00:00
' format_id ( id ) ' = ' id . shortest ( 12 ) . prefix ( ) + + " [ " + + id . shortest ( 12 ) . rest ( ) + + " ] " '
2023-02-14 13:48:49 +00:00
" ###,
) ;
2023-01-03 00:24:00 +00:00
2023-02-28 10:43:14 +00:00
let prefix_format = r ###"
separate ( " " ,
" Change " ,
format_id ( change_id ) ,
description . first_line ( ) ,
format_id ( commit_id ) ,
branches ,
)
" ###;
2023-01-03 00:24:00 +00:00
std ::fs ::write ( repo_path . join ( " file " ) , " original file \n " ) . unwrap ( ) ;
test_env . jj_cmd_success ( & repo_path , & [ " describe " , " -m " , " initial " ] ) ;
test_env . jj_cmd_success ( & repo_path , & [ " branch " , " c " , " original " ] ) ;
insta ::assert_snapshot! (
test_env . jj_cmd_success ( & repo_path , & [ " log " , " -r " , " all() " , " -T " , prefix_format ] ) ,
@ r ###"
2023-02-12 20:07:28 +00:00
@ Change q [ pvuntsmwlqt ] initial b [ a1a30916d29 ] original
2023-03-15 03:37:56 +00:00
◉ Change z [ zzzzzzzzzzz ] 0 [ 00000000000 ]
2023-01-03 00:24:00 +00:00
" ###
) ;
2023-02-06 07:06:44 +00:00
// Create 2^7 hidden commits
test_env . jj_cmd_success ( & repo_path , & [ " new " , " root " , " -m " , " extra " ] ) ;
for _ in 0 .. 7 {
test_env . jj_cmd_success ( & repo_path , & [ " duplicate " , " description(extra) " ] ) ;
2023-01-03 00:24:00 +00:00
}
2023-02-06 07:06:44 +00:00
test_env . jj_cmd_success ( & repo_path , & [ " abandon " , " description(extra) " ] ) ;
2023-05-22 03:27:03 +00:00
// The unique prefixes became longer.
2023-01-03 00:24:00 +00:00
insta ::assert_snapshot! (
2023-02-06 07:06:44 +00:00
test_env . jj_cmd_success ( & repo_path , & [ " log " , " -T " , prefix_format ] ) ,
2023-01-03 00:24:00 +00:00
@ r ###"
2023-05-22 03:27:03 +00:00
@ Change w [ qnwkozpkust ] 44 [ 4 c3c5066d3 ]
│ ◉ Change q [ pvuntsmwlqt ] initial ba [ 1 a30916d29 ] original
2023-02-09 02:53:47 +00:00
├ ─ ╯
2023-05-22 03:27:03 +00:00
◉ Change z [ zzzzzzzzzzz ] 00 [ 0000000000 ]
2023-01-03 00:24:00 +00:00
" ###
) ;
insta ::assert_snapshot! (
2023-05-22 03:46:55 +00:00
test_env . jj_cmd_failure ( & repo_path , & [ " log " , " -r " , " 4 " , " -T " , prefix_format ] ) ,
2023-01-03 00:24:00 +00:00
@ r ###"
2023-05-22 03:46:55 +00:00
Error : Commit or change id prefix " 4 " is ambiguous
2023-01-03 00:24:00 +00:00
" ###
) ;
insta ::assert_snapshot! (
2023-05-22 03:46:55 +00:00
test_env . jj_cmd_success ( & repo_path , & [ " log " , " -r " , " 44 " , " -T " , prefix_format ] ) ,
2023-01-03 00:24:00 +00:00
@ r ###"
2023-05-22 03:46:55 +00:00
@ Change w [ qnwkozpkust ] 44 [ 4 c3c5066d3 ]
2023-02-09 02:53:47 +00:00
│
~
2023-01-03 00:24:00 +00:00
" ###
) ;
}
2023-02-06 06:52:16 +00:00
#[ test ]
fn test_log_shortest_length_parameter ( ) {
let test_env = TestEnvironment ::default ( ) ;
test_env . jj_cmd_success ( test_env . env_root ( ) , & [ " init " , " repo " , " --git " ] ) ;
let repo_path = test_env . env_root ( ) . join ( " repo " ) ;
insta ::assert_snapshot! (
test_env . jj_cmd_success ( & repo_path , & [ " log " , " -T " , " commit_id.shortest(0) " ] ) , @ r ###"
2023-02-09 02:53:47 +00:00
@ 2
2023-03-15 03:37:56 +00:00
◉ 0
2023-02-06 06:52:16 +00:00
" ###);
insta ::assert_snapshot! (
test_env . jj_cmd_success ( & repo_path , & [ " log " , " -T " , " commit_id.shortest(100) " ] ) , @ r ###"
2023-02-09 02:53:47 +00:00
@ 230 dd059e1b059aefc0da06a2e5a7dbf22362f22
2023-03-15 03:37:56 +00:00
◉ 0000000000000000000000000000000000000000
2023-02-06 06:52:16 +00:00
" ###);
}
2023-02-11 11:07:58 +00:00
#[ test ]
2023-02-15 10:58:18 +00:00
fn test_log_author_format ( ) {
2023-02-11 11:07:58 +00:00
let test_env = TestEnvironment ::default ( ) ;
test_env . jj_cmd_success ( test_env . env_root ( ) , & [ " init " , " repo " , " --git " ] ) ;
let repo_path = test_env . env_root ( ) . join ( " repo " ) ;
insta ::assert_snapshot! (
test_env . jj_cmd_success ( & repo_path , & [ " log " , " --revisions=@ " ] ) ,
@ r ###"
2023-02-12 20:07:28 +00:00
@ qpvuntsmwlqt test . user @ example . com 2001 - 02 - 03 04 :05 :07.000 + 07 :00 230 dd059e1b0
2023-02-09 02:53:47 +00:00
│ ( empty ) ( no description set )
~
" ###
2023-02-11 11:07:58 +00:00
) ;
2023-02-15 10:58:18 +00:00
let decl = " template-aliases.'format_short_signature(signature)' " ;
2023-02-11 11:07:58 +00:00
insta ::assert_snapshot! (
test_env . jj_cmd_success (
& repo_path ,
& [
2023-02-15 10:58:18 +00:00
" --config-toml " ,
& format! ( " {decl} ='signature.username()' " ) ,
2023-02-11 11:07:58 +00:00
" log " ,
" --revisions=@ " ,
] ,
) ,
@ r ###"
2023-02-12 20:07:28 +00:00
@ qpvuntsmwlqt test . user 2001 - 02 - 03 04 :05 :07.000 + 07 :00 230 dd059e1b0
2023-02-09 02:53:47 +00:00
│ ( empty ) ( no description set )
~
" ###
2023-02-11 11:07:58 +00:00
) ;
}
2023-01-02 07:09:38 +00:00
#[ test ]
fn test_log_divergence ( ) {
let test_env = TestEnvironment ::default ( ) ;
test_env . jj_cmd_success ( test_env . env_root ( ) , & [ " init " , " repo " , " --git " ] ) ;
let repo_path = test_env . env_root ( ) . join ( " repo " ) ;
2023-02-28 11:30:57 +00:00
let template = r # "description.first_line() ++ if(divergent, " !divergence!")"# ;
2023-01-02 07:09:38 +00:00
std ::fs ::write ( repo_path . join ( " file " ) , " foo \n " ) . unwrap ( ) ;
test_env . jj_cmd_success ( & repo_path , & [ " describe " , " -m " , " description 1 " ] ) ;
2023-02-28 10:43:14 +00:00
let stdout = test_env . jj_cmd_success ( & repo_path , & [ " log " , " -T " , template ] ) ;
2023-01-02 07:09:38 +00:00
// No divergence
insta ::assert_snapshot! ( stdout , @ r ###"
2023-02-09 02:53:47 +00:00
@ description 1
2023-03-15 03:37:56 +00:00
◉
2023-01-02 07:09:38 +00:00
" ###);
// Create divergence
test_env . jj_cmd_success (
& repo_path ,
& [ " describe " , " -m " , " description 2 " , " --at-operation " , " @- " ] ,
) ;
2023-02-28 10:43:14 +00:00
let stdout = test_env . jj_cmd_success ( & repo_path , & [ " log " , " -T " , template ] ) ;
2023-01-02 07:09:38 +00:00
insta ::assert_snapshot! ( stdout , @ r ###"
Concurrent modification detected , resolving automatically .
2023-03-15 03:37:56 +00:00
◉ description 2 ! divergence !
2023-02-09 02:53:47 +00:00
│ @ description 1 ! divergence !
├ ─ ╯
2023-03-15 03:37:56 +00:00
◉
2023-01-02 07:09:38 +00:00
" ###);
}
2022-05-09 17:38:23 +00:00
#[ test ]
fn test_log_reversed ( ) {
let test_env = TestEnvironment ::default ( ) ;
test_env . jj_cmd_success ( test_env . env_root ( ) , & [ " init " , " repo " , " --git " ] ) ;
let repo_path = test_env . env_root ( ) . join ( " repo " ) ;
test_env . jj_cmd_success ( & repo_path , & [ " describe " , " -m " , " first " ] ) ;
test_env . jj_cmd_success ( & repo_path , & [ " new " , " -m " , " second " ] ) ;
let stdout = test_env . jj_cmd_success ( & repo_path , & [ " log " , " -T " , " description " , " --reversed " ] ) ;
insta ::assert_snapshot! ( stdout , @ r ###"
2023-03-15 03:37:56 +00:00
◉
◉ first
2023-02-09 02:53:47 +00:00
@ second
2022-05-09 17:38:23 +00:00
" ###);
let stdout = test_env . jj_cmd_success (
& repo_path ,
& [ " log " , " -T " , " description " , " --reversed " , " --no-graph " ] ,
) ;
insta ::assert_snapshot! ( stdout , @ r ###"
first
second
" ###);
}
2022-09-13 07:26:23 +00:00
#[ test ]
fn test_log_filtered_by_path ( ) {
let test_env = TestEnvironment ::default ( ) ;
test_env . jj_cmd_success ( test_env . env_root ( ) , & [ " init " , " repo " , " --git " ] ) ;
let repo_path = test_env . env_root ( ) . join ( " repo " ) ;
std ::fs ::write ( repo_path . join ( " file1 " ) , " foo \n " ) . unwrap ( ) ;
test_env . jj_cmd_success ( & repo_path , & [ " describe " , " -m " , " first " ] ) ;
test_env . jj_cmd_success ( & repo_path , & [ " new " , " -m " , " second " ] ) ;
std ::fs ::write ( repo_path . join ( " file1 " ) , " foo \n bar \n " ) . unwrap ( ) ;
std ::fs ::write ( repo_path . join ( " file2 " ) , " baz \n " ) . unwrap ( ) ;
let stdout = test_env . jj_cmd_success ( & repo_path , & [ " log " , " -T " , " description " , " file1 " ] ) ;
insta ::assert_snapshot! ( stdout , @ r ###"
2023-02-09 02:53:47 +00:00
@ second
2023-03-15 03:37:56 +00:00
◉ first
2023-02-09 02:53:47 +00:00
│
~
2022-09-13 07:26:23 +00:00
" ###);
let stdout = test_env . jj_cmd_success ( & repo_path , & [ " log " , " -T " , " description " , " file2 " ] ) ;
insta ::assert_snapshot! ( stdout , @ r ###"
2023-02-09 02:53:47 +00:00
@ second
│
~
2022-09-13 07:26:23 +00:00
" ###);
let stdout = test_env . jj_cmd_success ( & repo_path , & [ " log " , " -T " , " description " , " -s " , " file1 " ] ) ;
insta ::assert_snapshot! ( stdout , @ r ###"
2023-02-09 02:53:47 +00:00
@ second
│ M file1
2023-03-15 03:37:56 +00:00
◉ first
2023-02-09 02:53:47 +00:00
│ A file1
~
2022-09-13 07:26:23 +00:00
" ###);
let stdout = test_env . jj_cmd_success (
& repo_path ,
& [ " log " , " -T " , " description " , " -s " , " file2 " , " --no-graph " ] ,
) ;
insta ::assert_snapshot! ( stdout , @ r ###"
second
A file2
" ###);
2022-10-23 04:14:00 +00:00
// file() revset doesn't filter the diff.
let stdout = test_env . jj_cmd_success (
& repo_path ,
& [
" log " ,
" -T " ,
" description " ,
" -s " ,
" -rfile(file2) " ,
" --no-graph " ,
] ,
) ;
insta ::assert_snapshot! ( stdout , @ r ###"
second
M file1
A file2
" ###);
2022-09-13 07:26:23 +00:00
}
2022-10-01 15:09:32 +00:00
2022-11-18 23:41:35 +00:00
#[ test ]
fn test_log_warn_path_might_be_revset ( ) {
let test_env = TestEnvironment ::default ( ) ;
test_env . jj_cmd_success ( test_env . env_root ( ) , & [ " init " , " repo " , " --git " ] ) ;
let repo_path = test_env . env_root ( ) . join ( " repo " ) ;
std ::fs ::write ( repo_path . join ( " file1 " ) , " foo \n " ) . unwrap ( ) ;
// Don't warn if the file actually exists.
let assert = test_env
. jj_cmd ( & repo_path , & [ " log " , " file1 " , " -T " , " description " ] )
. assert ( )
. success ( ) ;
insta ::assert_snapshot! ( get_stdout_string ( & assert ) , @ r ###"
2023-02-09 02:53:47 +00:00
@
│
~
2022-11-18 23:41:35 +00:00
" ###);
insta ::assert_snapshot! ( get_stderr_string ( & assert ) , @ " " ) ;
// Warn for `jj log .` specifically, for former Mercurial users.
let assert = test_env
. jj_cmd ( & repo_path , & [ " log " , " . " , " -T " , " description " ] )
. assert ( )
. success ( ) ;
insta ::assert_snapshot! ( get_stdout_string ( & assert ) , @ r ###"
2023-02-09 02:53:47 +00:00
@
│
~
2022-11-18 23:41:35 +00:00
" ###);
insta ::assert_snapshot! ( get_stderr_string ( & assert ) , @ r ### "warning: The argument "." is being interpreted as a path, but this is often not useful because all non-empty commits touch '.'. If you meant to show the working copy commit, pass -r '@' instead."### ) ;
// ...but checking `jj log .` makes sense in a subdirectory.
let subdir = repo_path . join ( " dir " ) ;
std ::fs ::create_dir_all ( & subdir ) . unwrap ( ) ;
let assert = test_env . jj_cmd ( & subdir , & [ " log " , " . " ] ) . assert ( ) . success ( ) ;
insta ::assert_snapshot! ( get_stdout_string ( & assert ) , @ " " ) ;
insta ::assert_snapshot! ( get_stderr_string ( & assert ) , @ " " ) ;
// Warn for `jj log @` instead of `jj log -r @`.
let assert = test_env
. jj_cmd ( & repo_path , & [ " log " , " @ " , " -T " , " description " ] )
. assert ( )
. success ( ) ;
insta ::assert_snapshot! ( get_stdout_string ( & assert ) , @ " " ) ;
insta ::assert_snapshot! ( get_stderr_string ( & assert ) , @ r ###"
warning : The argument " @ " is being interpreted as a path . To specify a revset , pass - r " @ " instead .
" ###);
// Warn when there's no path with the provided name.
let assert = test_env
. jj_cmd ( & repo_path , & [ " log " , " file2 " , " -T " , " description " ] )
. assert ( )
. success ( ) ;
insta ::assert_snapshot! ( get_stdout_string ( & assert ) , @ " " ) ;
insta ::assert_snapshot! ( get_stderr_string ( & assert ) , @ r ###"
warning : The argument " file2 " is being interpreted as a path . To specify a revset , pass - r " file2 " instead .
" ###);
// If an explicit revision is provided, then suppress the warning.
let assert = test_env
. jj_cmd ( & repo_path , & [ " log " , " @ " , " -r " , " @ " , " -T " , " description " ] )
. assert ( )
. success ( ) ;
insta ::assert_snapshot! ( get_stdout_string ( & assert ) , @ " " ) ;
insta ::assert_snapshot! ( get_stderr_string ( & assert ) , @ r ###"
" ###);
}
2022-10-01 15:09:32 +00:00
#[ test ]
fn test_default_revset ( ) {
let test_env = TestEnvironment ::default ( ) ;
test_env . jj_cmd_success ( test_env . env_root ( ) , & [ " init " , " repo " , " --git " ] ) ;
let repo_path = test_env . env_root ( ) . join ( " repo " ) ;
std ::fs ::write ( repo_path . join ( " file1 " ) , " foo \n " ) . unwrap ( ) ;
test_env . jj_cmd_success ( & repo_path , & [ " describe " , " -m " , " add a file " ] ) ;
// Set configuration to only show the root commit.
2023-05-11 06:26:23 +00:00
test_env . add_config ( r # "revsets.log = "root""# ) ;
2022-10-01 15:09:32 +00:00
// Log should only contain one line (for the root commit), and not show the
// commit created above.
assert_eq! (
1 ,
test_env
. jj_cmd_success ( & repo_path , & [ " log " , " -T " , " commit_id " ] )
. lines ( )
. count ( )
) ;
}
2022-11-26 01:33:24 +00:00
2023-01-02 05:18:38 +00:00
#[ test ]
fn test_default_revset_per_repo ( ) {
let test_env = TestEnvironment ::default ( ) ;
test_env . jj_cmd_success ( test_env . env_root ( ) , & [ " init " , " repo " , " --git " ] ) ;
let repo_path = test_env . env_root ( ) . join ( " repo " ) ;
std ::fs ::write ( repo_path . join ( " file1 " ) , " foo \n " ) . unwrap ( ) ;
test_env . jj_cmd_success ( & repo_path , & [ " describe " , " -m " , " add a file " ] ) ;
// Set configuration to only show the root commit.
std ::fs ::write (
repo_path . join ( " .jj/repo/config.toml " ) ,
2023-05-11 06:26:23 +00:00
r # "revsets.log = "root""# ,
2023-01-02 05:18:38 +00:00
)
. unwrap ( ) ;
// Log should only contain one line (for the root commit), and not show the
// commit created above.
assert_eq! (
1 ,
test_env
. jj_cmd_success ( & repo_path , & [ " log " , " -T " , " commit_id " ] )
. lines ( )
. count ( )
) ;
}
2023-01-13 07:55:52 +00:00
#[ test ]
fn test_graph_template_color ( ) {
// Test that color codes from a multi-line template don't span the graph lines.
let test_env = TestEnvironment ::default ( ) ;
test_env . jj_cmd_success ( test_env . env_root ( ) , & [ " init " , " repo " , " --git " ] ) ;
let repo_path = test_env . env_root ( ) . join ( " repo " ) ;
test_env . jj_cmd_success (
& repo_path ,
& [ " describe " , " -m " , " first line \n second line \n third line " ] ,
) ;
test_env . jj_cmd_success ( & repo_path , & [ " new " , " -m " , " single line " ] ) ;
test_env . add_config (
2023-01-26 19:26:18 +00:00
r #" [colors]
2023-01-13 07:55:52 +00:00
description = " red "
" working_copy description " = " green "
" #,
) ;
// First test without color for comparison
2023-02-03 03:49:40 +00:00
let template = r # "label(if(current_working_copy, "working_copy"), description)"# ;
let stdout = test_env . jj_cmd_success ( & repo_path , & [ " log " , " -T " , template ] ) ;
2023-01-13 07:55:52 +00:00
insta ::assert_snapshot! ( stdout , @ r ###"
2023-02-09 02:53:47 +00:00
@ single line
2023-03-15 03:37:56 +00:00
◉ first line
2023-02-09 02:53:47 +00:00
│ second line
│ third line
2023-03-15 03:37:56 +00:00
◉
2023-01-13 07:55:52 +00:00
" ###);
2023-02-03 03:49:40 +00:00
let stdout = test_env . jj_cmd_success ( & repo_path , & [ " --color=always " , " log " , " -T " , template ] ) ;
2023-01-13 07:55:52 +00:00
insta ::assert_snapshot! ( stdout , @ r ###"
2023-02-09 02:53:47 +00:00
@ [ 1 m [ 38 ; 5 ; 2 msingle line [ 0 m
2023-03-15 03:37:56 +00:00
◉ [ 38 ; 5 ; 1 mfirst line [ 39 m
2023-02-09 02:53:47 +00:00
│ [ 38 ; 5 ; 1 msecond line [ 39 m
│ [ 38 ; 5 ; 1 mthird line [ 39 m
2023-03-15 03:37:56 +00:00
◉
2023-01-13 07:55:52 +00:00
" ###);
}
2023-01-27 06:33:24 +00:00
#[ test ]
fn test_graph_styles ( ) {
// Test that different graph styles are available.
let test_env = TestEnvironment ::default ( ) ;
test_env . jj_cmd_success ( test_env . env_root ( ) , & [ " init " , " repo " , " --git " ] ) ;
let repo_path = test_env . env_root ( ) . join ( " repo " ) ;
test_env . jj_cmd_success ( & repo_path , & [ " commit " , " -m " , " initial " ] ) ;
test_env . jj_cmd_success ( & repo_path , & [ " commit " , " -m " , " main branch 1 " ] ) ;
test_env . jj_cmd_success ( & repo_path , & [ " describe " , " -m " , " main branch 2 " ] ) ;
test_env . jj_cmd_success (
& repo_path ,
& [ " new " , " -m " , " side branch \n with \n long \n description " ] ,
) ;
test_env . jj_cmd_success (
& repo_path ,
& [ " new " , " -m " , " merge " , r # "description("main branch 1")"# , " @ " ] ,
) ;
// Default (legacy) style
let stdout = test_env . jj_cmd_success ( & repo_path , & [ " log " , " -T=description " ] ) ;
insta ::assert_snapshot! ( stdout , @ r ###"
2023-02-09 02:53:47 +00:00
@ merge
├ ─ ╮
2023-03-15 03:37:56 +00:00
◉ │ side branch
2023-02-09 02:53:47 +00:00
│ │ with
│ │ long
│ │ description
2023-03-15 03:37:56 +00:00
◉ │ main branch 2
2023-02-09 02:53:47 +00:00
├ ─ ╯
2023-03-15 03:37:56 +00:00
◉ main branch 1
◉ initial
◉
2023-01-27 06:33:24 +00:00
" ###);
// ASCII style
2023-01-27 18:15:51 +00:00
test_env . add_config ( r # "ui.graph.style = "ascii""# ) ;
2023-01-27 06:33:24 +00:00
let stdout = test_env . jj_cmd_success ( & repo_path , & [ " log " , " -T=description " ] ) ;
insta ::assert_snapshot! ( stdout , @ r ###"
@ merge
| \
o | side branch
| | with
| | long
| | description
o | main branch 2
| /
o main branch 1
o initial
2023-01-31 09:17:46 +00:00
o
2023-01-27 06:33:24 +00:00
" ###);
// Large ASCII style
2023-01-27 18:15:51 +00:00
test_env . add_config ( r # "ui.graph.style = "ascii-large""# ) ;
2023-01-27 06:33:24 +00:00
let stdout = test_env . jj_cmd_success ( & repo_path , & [ " log " , " -T=description " ] ) ;
insta ::assert_snapshot! ( stdout , @ r ###"
@ merge
| \
| \
o | side branch
| | with
| | long
| | description
o | main branch 2
| /
| /
o main branch 1
o initial
2023-01-31 09:17:46 +00:00
o
2023-01-27 06:33:24 +00:00
" ###);
// Curved style
2023-01-27 18:15:51 +00:00
test_env . add_config ( r # "ui.graph.style = "curved""# ) ;
2023-01-27 06:33:24 +00:00
let stdout = test_env . jj_cmd_success ( & repo_path , & [ " log " , " -T=description " ] ) ;
insta ::assert_snapshot! ( stdout , @ r ###"
@ merge
├ ─ ╮
2023-03-15 03:37:56 +00:00
◉ │ side branch
2023-01-27 06:33:24 +00:00
│ │ with
│ │ long
│ │ description
2023-03-15 03:37:56 +00:00
◉ │ main branch 2
2023-01-27 06:33:24 +00:00
├ ─ ╯
2023-03-15 03:37:56 +00:00
◉ main branch 1
◉ initial
◉
2023-01-27 06:33:24 +00:00
" ###);
// Square style
2023-01-27 18:15:51 +00:00
test_env . add_config ( r # "ui.graph.style = "square""# ) ;
2023-01-27 06:33:24 +00:00
let stdout = test_env . jj_cmd_success ( & repo_path , & [ " log " , " -T=description " ] ) ;
insta ::assert_snapshot! ( stdout , @ r ###"
@ merge
├ ─ ┐
2023-03-15 03:37:56 +00:00
◉ │ side branch
2023-01-27 06:33:24 +00:00
│ │ with
│ │ long
│ │ description
2023-03-15 03:37:56 +00:00
◉ │ main branch 2
2023-01-27 06:33:24 +00:00
├ ─ ┘
2023-03-15 03:37:56 +00:00
◉ main branch 1
◉ initial
◉
2023-01-27 06:33:24 +00:00
" ###);
}
2023-03-05 04:10:02 +00:00
#[ test ]
fn test_log_word_wrap ( ) {
let test_env = TestEnvironment ::default ( ) ;
test_env . jj_cmd_success ( test_env . env_root ( ) , & [ " init " , " repo " , " --git " ] ) ;
let repo_path = test_env . env_root ( ) . join ( " repo " ) ;
let render = | args : & [ & str ] , columns : u32 , word_wrap : bool | {
let mut args = args . to_vec ( ) ;
if word_wrap {
args . push ( " --config-toml=ui.log-word-wrap=true " ) ;
}
let assert = test_env
. jj_cmd ( & repo_path , & args )
. env ( " COLUMNS " , columns . to_string ( ) )
. assert ( )
. success ( )
. stderr ( " " ) ;
get_stdout_string ( & assert )
} ;
test_env . jj_cmd_success ( & repo_path , & [ " commit " , " -m " , " main branch 1 " ] ) ;
test_env . jj_cmd_success ( & repo_path , & [ " describe " , " -m " , " main branch 2 " ] ) ;
test_env . jj_cmd_success ( & repo_path , & [ " new " , " -m " , " side " ] ) ;
test_env . jj_cmd_success ( & repo_path , & [ " new " , " -m " , " merge " , " @-- " , " @ " ] ) ;
// ui.log-word-wrap option applies to both graph/no-graph outputs
insta ::assert_snapshot! ( render ( & [ " log " , " -r@ " ] , 40 , false ) , @ r ###"
@ mzvwutvlkqwt test . user @ example . com 2001 - 02 - 03 04 :05 :11.000 + 07 :00 68518 a7e6c9e
│ ( empty ) merge
~
" ###);
insta ::assert_snapshot! ( render ( & [ " log " , " -r@ " ] , 40 , true ) , @ r ###"
@ mzvwutvlkqwt test . user @ example . com
│ 2001 - 02 - 03 04 :05 :11.000 + 07 :00
~ 68518 a7e6c9e
( empty ) merge
" ###);
insta ::assert_snapshot! ( render ( & [ " log " , " --no-graph " , " -r@ " ] , 40 , false ) , @ r ###"
mzvwutvlkqwt test . user @ example . com 2001 - 02 - 03 04 :05 :11.000 + 07 :00 68518 a7e6c9e
( empty ) merge
" ###);
insta ::assert_snapshot! ( render ( & [ " log " , " --no-graph " , " -r@ " ] , 40 , true ) , @ r ###"
mzvwutvlkqwt test . user @ example . com
2001 - 02 - 03 04 :05 :11.000 + 07 :00
68518 a7e6c9e
( empty ) merge
" ###);
// Color labels should be preserved
insta ::assert_snapshot! ( render ( & [ " log " , " -r@ " , " --color=always " ] , 40 , true ) , @ r ###"
@ [ 1 m [ 38 ; 5 ; 13 mm [ 38 ; 5 ; 8 mzvwutvlkqwt [ 39 m [ 38 ; 5 ; 3 mtest . user @ example . com [ 39 m [ 0 m
│ [ 1 m [ 38 ; 5 ; 14 m2001 - 02 - 03 04 :05 :11.000 + 07 :00 [ 39 m [ 0 m
~ [ 1 m [ 38 ; 5 ; 12 m6 [ 38 ; 5 ; 8 m8518a7e6c9e [ 39 m [ 0 m
[ 1 m [ 38 ; 5 ; 10 m ( empty ) [ 39 m merge [ 0 m
" ###);
// Graph width should be subtracted from the term width
let template = r # ""0 1 2 3 4 5 6 7 8 9""# ;
insta ::assert_snapshot! ( render ( & [ " log " , " -T " , template ] , 10 , true ) , @ r ###"
@ 0 1 2
├ ─ ╮ 3 4 5
│ │ 6 7 8
│ │ 9
2023-03-15 03:37:56 +00:00
◉ │ 0 1 2
2023-03-05 04:10:02 +00:00
│ │ 3 4 5
│ │ 6 7 8
│ │ 9
2023-03-15 03:37:56 +00:00
◉ │ 0 1 2
2023-03-05 04:10:02 +00:00
├ ─ ╯ 3 4 5
│ 6 7 8
│ 9
2023-03-15 03:37:56 +00:00
◉ 0 1 2 3
2023-03-05 04:10:02 +00:00
│ 4 5 6 7
│ 8 9
2023-03-15 03:37:56 +00:00
◉ 0 1 2 3
2023-03-05 04:10:02 +00:00
4 5 6 7
8 9
" ###);
insta ::assert_snapshot! (
render ( & [ " log " , " -T " , template , " --config-toml=ui.graph.style='legacy' " ] , 9 , true ) ,
@ r ###"
@ 0 1 2
| \ 3 4 5
| | 6 7 8
| | 9
o | 0 1 2
| | 3 4 5
| | 6 7 8
| | 9
o | 0 1 2
| / 3 4 5
| 6 7 8
| 9
o 0 1 2 3
| 4 5 6 7
| 8 9
o 0 1 2 3
4 5 6 7
8 9
" ###);
// Shouldn't panic with $COLUMNS < graph_width
insta ::assert_snapshot! ( render ( & [ " log " , " -r@ " ] , 0 , true ) , @ r ###"
@ mzvwutvlkqwt
│ test . user @ example . com
~ 2001 - 02 - 03
04 :05 :11.000
+ 07 :00
68518 a7e6c9e
( empty )
merge
" ###);
insta ::assert_snapshot! ( render ( & [ " log " , " -r@ " ] , 1 , true ) , @ r ###"
@ mzvwutvlkqwt
│ test . user @ example . com
~ 2001 - 02 - 03
04 :05 :11.000
+ 07 :00
68518 a7e6c9e
( empty )
merge
" ###);
}