Skip to content

Commit 1d232d3

Browse files
avargitster
authored andcommitted
ls-tree: test for the regression in 9c4d58f
Add a test for the regression introduced in my 9c4d58f (ls-tree: split up "fast path" callbacks, 2022-03-23) and fixed in 350296c (ls-tree: `-l` should not imply recursive listing, 2022-04-04), and test for the test of ls-tree option/mode combinations to make sure we don't have other blind spots. The setup for these tests can be shared with those added in the 1041d58 (Merge branch 'tl/ls-tree-oid-only', 2022-04-04) topic, so let's create a new t/lib-t3100.sh to help them share data. The existing tests in "t3104-ls-tree-format.sh" didn't deal with a submodule, which they'll now encounter with as the setup_basic_ls_tree_data() sets one up. This extensive testing should give us confidence that there were no further regressions in this area. The lack of testing was noted back in [1], but unfortunately we didn't cover that blind-spot before 9c4d58f. 1. https://lore.kernel.org/git/[email protected]/ Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 350296c commit 1d232d3

File tree

3 files changed

+204
-3
lines changed

3 files changed

+204
-3
lines changed

t/lib-t3100.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
3+
setup_basic_ls_tree_data () {
4+
mkdir dir &&
5+
test_commit dir/sub-file &&
6+
test_commit top-file &&
7+
git clone . submodule &&
8+
git submodule add ./submodule &&
9+
git commit -m"add submodule"
10+
}

t/t3104-ls-tree-format.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ test_description='ls-tree --format'
44

55
TEST_PASSES_SANITIZE_LEAK=true
66
. ./test-lib.sh
7+
. "$TEST_DIRECTORY"/lib-t3100.sh
78

89
test_expect_success 'ls-tree --format usage' '
910
test_expect_code 129 git ls-tree --format=fmt -l HEAD &&
@@ -12,9 +13,7 @@ test_expect_success 'ls-tree --format usage' '
1213
'
1314

1415
test_expect_success 'setup' '
15-
mkdir dir &&
16-
test_commit dir/sub-file &&
17-
test_commit top-file
16+
setup_basic_ls_tree_data
1817
'
1918

2019
test_ls_tree_format () {

t/t3105-ls-tree-output.sh

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
#!/bin/sh
2+
3+
test_description='ls-tree output'
4+
5+
TEST_PASSES_SANITIZE_LEAK=true
6+
. ./test-lib.sh
7+
. "$TEST_DIRECTORY"/lib-t3100.sh
8+
9+
test_expect_success 'ls-tree --format usage' '
10+
test_expect_code 129 git ls-tree --format=fmt -l HEAD &&
11+
test_expect_code 129 git ls-tree --format=fmt --name-only HEAD &&
12+
test_expect_code 129 git ls-tree --format=fmt --name-status HEAD
13+
'
14+
15+
test_expect_success 'setup' '
16+
setup_basic_ls_tree_data
17+
'
18+
19+
test_ls_tree_format_mode_output () {
20+
local opts="$1" &&
21+
shift &&
22+
cat >expect &&
23+
24+
while test $# -gt 0
25+
do
26+
local mode="$1" &&
27+
shift &&
28+
29+
test_expect_success "'ls-tree $opts${mode:+ $mode}' output" '
30+
git ls-tree ${mode:+$mode }$opts HEAD >actual &&
31+
test_cmp expect actual
32+
'
33+
34+
case "$opts" in
35+
--full-tree)
36+
test_expect_success "'ls-tree $opts${mode:+ $mode}' output (via subdir, fails)" '
37+
test_must_fail git -C dir ls-tree --full-name ${mode:+$mode }$opts HEAD -- ../
38+
'
39+
;;
40+
*)
41+
test_expect_success "'ls-tree $opts${mode:+ $mode}' output (via subdir)" '
42+
git -C dir ls-tree --full-name ${mode:+$mode }$opts HEAD -- ../ >actual &&
43+
test_cmp expect actual
44+
'
45+
;;
46+
esac
47+
done
48+
}
49+
50+
# test exact output of option (none, --long, ...) and mode (none and
51+
# -d, -r -t) and combinations
52+
test_expect_success 'setup: HEAD_* variables' '
53+
HEAD_gitmodules=$(git rev-parse HEAD:.gitmodules) &&
54+
HEAD_dir=$(git rev-parse HEAD:dir) &&
55+
HEAD_top_file=$(git rev-parse HEAD:top-file.t) &&
56+
HEAD_submodule=$(git rev-parse HEAD:submodule) &&
57+
HEAD_dir_sub_file=$(git rev-parse HEAD:dir/sub-file.t)
58+
'
59+
## opt =
60+
test_ls_tree_format_mode_output "" "" "-t" <<-EOF
61+
100644 blob $HEAD_gitmodules .gitmodules
62+
040000 tree $HEAD_dir dir
63+
160000 commit $HEAD_submodule submodule
64+
100644 blob $HEAD_top_file top-file.t
65+
EOF
66+
test_ls_tree_format_mode_output "" "-d" <<-EOF
67+
040000 tree $HEAD_dir dir
68+
160000 commit $HEAD_submodule submodule
69+
EOF
70+
test_ls_tree_format_mode_output "" "-r" <<-EOF
71+
100644 blob $HEAD_gitmodules .gitmodules
72+
100644 blob $HEAD_dir_sub_file dir/sub-file.t
73+
160000 commit $HEAD_submodule submodule
74+
100644 blob $HEAD_top_file top-file.t
75+
EOF
76+
## opt = --long
77+
test_ls_tree_format_mode_output "--long" "" "-t" <<-EOF
78+
100644 blob $HEAD_gitmodules 61 .gitmodules
79+
040000 tree $HEAD_dir - dir
80+
160000 commit $HEAD_submodule - submodule
81+
100644 blob $HEAD_top_file 9 top-file.t
82+
EOF
83+
test_ls_tree_format_mode_output "--long" "-d" <<-EOF
84+
040000 tree $HEAD_dir - dir
85+
160000 commit $HEAD_submodule - submodule
86+
EOF
87+
test_ls_tree_format_mode_output "--long" "-r" <<-EOF
88+
100644 blob $HEAD_gitmodules 61 .gitmodules
89+
100644 blob $HEAD_dir_sub_file 13 dir/sub-file.t
90+
160000 commit $HEAD_submodule - submodule
91+
100644 blob $HEAD_top_file 9 top-file.t
92+
EOF
93+
## opt = --name-only
94+
test_ls_tree_format_mode_output "--name-only" "" "-t" <<-EOF
95+
.gitmodules
96+
dir
97+
submodule
98+
top-file.t
99+
EOF
100+
test_ls_tree_format_mode_output "--name-only" "-d" <<-EOF
101+
dir
102+
submodule
103+
EOF
104+
test_ls_tree_format_mode_output "--name-only" "-r" <<-EOF
105+
.gitmodules
106+
dir/sub-file.t
107+
submodule
108+
top-file.t
109+
EOF
110+
## opt = --object-only
111+
test_ls_tree_format_mode_output "--object-only" "" "-t" <<-EOF
112+
$HEAD_gitmodules
113+
$HEAD_dir
114+
$HEAD_submodule
115+
$HEAD_top_file
116+
EOF
117+
test_ls_tree_format_mode_output "--object-only" "-d" <<-EOF
118+
$HEAD_dir
119+
$HEAD_submodule
120+
EOF
121+
test_ls_tree_format_mode_output "--object-only" "-r" <<-EOF
122+
$HEAD_gitmodules
123+
$HEAD_dir_sub_file
124+
$HEAD_submodule
125+
$HEAD_top_file
126+
EOF
127+
## opt = --object-only --abbrev
128+
test_expect_success 'setup: HEAD_short_* variables' '
129+
HEAD_short_gitmodules=$(git rev-parse --short HEAD:.gitmodules) &&
130+
HEAD_short_dir=$(git rev-parse --short HEAD:dir) &&
131+
HEAD_short_top_file=$(git rev-parse --short HEAD:top-file.t) &&
132+
HEAD_short_submodule=$(git rev-parse --short HEAD:submodule) &&
133+
HEAD_short_dir_sub_file=$(git rev-parse --short HEAD:dir/sub-file.t)
134+
'
135+
test_ls_tree_format_mode_output "--object-only --abbrev" "" "-t" <<-EOF
136+
$HEAD_short_gitmodules
137+
$HEAD_short_dir
138+
$HEAD_short_submodule
139+
$HEAD_short_top_file
140+
EOF
141+
test_ls_tree_format_mode_output "--object-only --abbrev" "-d" <<-EOF
142+
$HEAD_short_dir
143+
$HEAD_short_submodule
144+
EOF
145+
test_ls_tree_format_mode_output "--object-only --abbrev" "-r" <<-EOF
146+
$HEAD_short_gitmodules
147+
$HEAD_short_dir_sub_file
148+
$HEAD_short_submodule
149+
$HEAD_short_top_file
150+
EOF
151+
## opt = --full-name
152+
test_ls_tree_format_mode_output "--full-name" "" <<-EOF
153+
100644 blob $HEAD_gitmodules .gitmodules
154+
040000 tree $HEAD_dir dir
155+
160000 commit $HEAD_submodule submodule
156+
100644 blob $HEAD_top_file top-file.t
157+
EOF
158+
test_ls_tree_format_mode_output "--full-name" "-d" <<-EOF
159+
040000 tree $HEAD_dir dir
160+
160000 commit $HEAD_submodule submodule
161+
EOF
162+
test_ls_tree_format_mode_output "--full-name" "-r" <<-EOF
163+
100644 blob $HEAD_gitmodules .gitmodules
164+
100644 blob $HEAD_dir_sub_file dir/sub-file.t
165+
160000 commit $HEAD_submodule submodule
166+
100644 blob $HEAD_top_file top-file.t
167+
EOF
168+
test_ls_tree_format_mode_output "--full-name" "-t" <<-EOF
169+
100644 blob $HEAD_gitmodules .gitmodules
170+
040000 tree $HEAD_dir dir
171+
160000 commit $HEAD_submodule submodule
172+
100644 blob $HEAD_top_file top-file.t
173+
EOF
174+
## opt = --full-tree
175+
test_ls_tree_format_mode_output "--full-tree" "" "-t" <<-EOF
176+
100644 blob $HEAD_gitmodules .gitmodules
177+
040000 tree $HEAD_dir dir
178+
160000 commit $HEAD_submodule submodule
179+
100644 blob $HEAD_top_file top-file.t
180+
EOF
181+
test_ls_tree_format_mode_output "--full-tree" "-d" <<-EOF
182+
040000 tree $HEAD_dir dir
183+
160000 commit $HEAD_submodule submodule
184+
EOF
185+
test_ls_tree_format_mode_output "--full-tree" "-r" <<-EOF
186+
100644 blob $HEAD_gitmodules .gitmodules
187+
100644 blob $HEAD_dir_sub_file dir/sub-file.t
188+
160000 commit $HEAD_submodule submodule
189+
100644 blob $HEAD_top_file top-file.t
190+
EOF
191+
192+
test_done

0 commit comments

Comments
 (0)