3 test_description
='ls-tree output'
5 TEST_PASSES_SANITIZE_LEAK
=true
7 .
"$TEST_DIRECTORY"/lib-t3100.sh
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
15 test_expect_success
'setup' '
16 setup_basic_ls_tree_data
19 test_ls_tree_format_mode_output
() {
29 test_expect_success
"'ls-tree $opts${mode:+ $mode}' output" '
30 git ls-tree ${mode:+$mode }$opts HEAD >actual &&
31 test_cmp expect actual
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 -- ../
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
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)
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
66 test_ls_tree_format_mode_output
"" "-d" <<-EOF
67 040000 tree $HEAD_dir dir
68 160000 commit $HEAD_submodule submodule
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
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
83 test_ls_tree_format_mode_output
"--long" "-d" <<-EOF
84 040000 tree $HEAD_dir - dir
85 160000 commit $HEAD_submodule - submodule
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
94 test_ls_tree_format_mode_output
"--name-only" "" "-t" <<-EOF
100 test_ls_tree_format_mode_output
"--name-only" "-d" <<-EOF
104 test_ls_tree_format_mode_output
"--name-only" "-r" <<-EOF
110 ## opt = --object-only
111 test_ls_tree_format_mode_output
"--object-only" "" "-t" <<-EOF
117 test_ls_tree_format_mode_output
"--object-only" "-d" <<-EOF
121 test_ls_tree_format_mode_output
"--object-only" "-r" <<-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)
135 test_ls_tree_format_mode_output
"--object-only --abbrev" "" "-t" <<-EOF
136 $HEAD_short_gitmodules
138 $HEAD_short_submodule
141 test_ls_tree_format_mode_output
"--object-only --abbrev" "-d" <<-EOF
143 $HEAD_short_submodule
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
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
158 test_ls_tree_format_mode_output
"--full-name" "-d" <<-EOF
159 040000 tree $HEAD_dir dir
160 160000 commit $HEAD_submodule submodule
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
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
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
181 test_ls_tree_format_mode_output
"--full-tree" "-d" <<-EOF
182 040000 tree $HEAD_dir dir
183 160000 commit $HEAD_submodule submodule
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