summaryrefslogtreecommitdiffstats
path: root/t/t3105-ls-tree-output.sh
blob: ce2391e28be6f213aead49ec1315e6f5f08fa25d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/bin/sh

test_description='ls-tree output'

TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-t3100.sh

test_expect_success 'ls-tree --format usage' '
	test_expect_code 129 git ls-tree --format=fmt -l HEAD &&
	test_expect_code 129 git ls-tree --format=fmt --name-only HEAD &&
	test_expect_code 129 git ls-tree --format=fmt --name-status HEAD
'

test_expect_success 'setup' '
	setup_basic_ls_tree_data
'

test_ls_tree_format_mode_output () {
	local opts="$1" &&
	shift &&
	cat >expect &&

	while test $# -gt 0
	do
		local mode="$1" &&
		shift &&

		test_expect_success "'ls-tree $opts${mode:+ $mode}' output" '
			git ls-tree ${mode:+$mode }$opts HEAD >actual &&
			test_cmp expect actual
		'

		case "$opts" in
		--full-tree)
			test_expect_success "'ls-tree $opts${mode:+ $mode}' output (via subdir, fails)" '
				test_must_fail git -C dir ls-tree --full-name ${mode:+$mode }$opts HEAD -- ../
			'
			;;
		*)
			test_expect_success "'ls-tree $opts${mode:+ $mode}' output (via subdir)" '
				git -C dir ls-tree --full-name ${mode:+$mode }$opts HEAD -- ../ >actual &&
				test_cmp expect actual
			'
			;;
		esac
	done
}

# test exact output of option (none, --long, ...) and mode (none and
# -d, -r -t) and combinations
test_expect_success 'setup: HEAD_* variables' '
	HEAD_gitmodules=$(git rev-parse HEAD:.gitmodules) &&
	HEAD_dir=$(git rev-parse HEAD:dir) &&
	HEAD_top_file=$(git rev-parse HEAD:top-file.t) &&
	HEAD_submodule=$(git rev-parse HEAD:submodule) &&
	HEAD_dir_sub_file=$(git rev-parse HEAD:dir/sub-file.t)
'
## opt =
test_ls_tree_format_mode_output "" "" "-t" <<-EOF
	100644 blob $HEAD_gitmodules	.gitmodules
	040000 tree $HEAD_dir	dir
	160000 commit $HEAD_submodule	submodule
	100644 blob $HEAD_top_file	top-file.t
	EOF
test_ls_tree_format_mode_output "" "-d" <<-EOF
	040000 tree $HEAD_dir	dir
	160000 commit $HEAD_submodule	submodule
	EOF
test_ls_tree_format_mode_output "" "-r" <<-EOF
	100644 blob $HEAD_gitmodules	.gitmodules
	100644 blob $HEAD_dir_sub_file	dir/sub-file.t
	160000 commit $HEAD_submodule	submodule
	100644 blob $HEAD_top_file	top-file.t
	EOF
## opt = --long
test_ls_tree_format_mode_output "--long" "" "-t" <<-EOF
	100644 blob $HEAD_gitmodules      61	.gitmodules
	040000 tree $HEAD_dir       -	dir
	160000 commit $HEAD_submodule       -	submodule
	100644 blob $HEAD_top_file       9	top-file.t
	EOF
test_ls_tree_format_mode_output "--long" "-d" <<-EOF
	040000 tree $HEAD_dir       -	dir
	160000 commit $HEAD_submodule       -	submodule
	EOF
test_ls_tree_format_mode_output "--long" "-r" <<-EOF
	100644 blob $HEAD_gitmodules      61	.gitmodules
	100644 blob $HEAD_dir_sub_file      13	dir/sub-file.t
	160000 commit $HEAD_submodule       -	submodule
	100644 blob $HEAD_top_file       9	top-file.t
	EOF
## opt = --name-only
test_ls_tree_format_mode_output "--name-only" "" "-t" <<-EOF
	.gitmodules
	dir
	submodule
	top-file.t
	EOF
test_ls_tree_format_mode_output "--name-only" "-d" <<-EOF
	dir
	submodule
	EOF
test_ls_tree_format_mode_output "--name-only" "-r" <<-EOF
	.gitmodules
	dir/sub-file.t
	submodule
	top-file.t
	EOF
## opt = --object-only
test_ls_tree_format_mode_output "--object-only" "" "-t" <<-EOF
	$HEAD_gitmodules
	$HEAD_dir
	$HEAD_submodule
	$HEAD_top_file
	EOF
test_ls_tree_format_mode_output "--object-only" "-d" <<-EOF
	$HEAD_dir
	$HEAD_submodule
	EOF
test_ls_tree_format_mode_output "--object-only" "-r" <<-EOF
	$HEAD_gitmodules
	$HEAD_dir_sub_file
	$HEAD_submodule
	$HEAD_top_file
	EOF
## opt = --object-only --abbrev
test_expect_success 'setup: HEAD_short_* variables' '
	HEAD_short_gitmodules=$(git rev-parse --short HEAD:.gitmodules) &&
	HEAD_short_dir=$(git rev-parse --short HEAD:dir) &&
	HEAD_short_top_file=$(git rev-parse --short HEAD:top-file.t) &&
	HEAD_short_submodule=$(git rev-parse --short HEAD:submodule) &&
	HEAD_short_dir_sub_file=$(git rev-parse --short HEAD:dir/sub-file.t)
'
test_ls_tree_format_mode_output "--object-only --abbrev" "" "-t" <<-EOF
	$HEAD_short_gitmodules
	$HEAD_short_dir
	$HEAD_short_submodule
	$HEAD_short_top_file
	EOF
test_ls_tree_format_mode_output "--object-only --abbrev" "-d" <<-EOF
	$HEAD_short_dir
	$HEAD_short_submodule
	EOF
test_ls_tree_format_mode_output "--object-only --abbrev" "-r" <<-EOF
	$HEAD_short_gitmodules
	$HEAD_short_dir_sub_file
	$HEAD_short_submodule
	$HEAD_short_top_file
	EOF
## opt = --full-name
test_ls_tree_format_mode_output "--full-name" "" <<-EOF
	100644 blob $HEAD_gitmodules	.gitmodules
	040000 tree $HEAD_dir	dir
	160000 commit $HEAD_submodule	submodule
	100644 blob $HEAD_top_file	top-file.t
	EOF
test_ls_tree_format_mode_output "--full-name" "-d" <<-EOF
	040000 tree $HEAD_dir	dir
	160000 commit $HEAD_submodule	submodule
	EOF
test_ls_tree_format_mode_output "--full-name" "-r" <<-EOF
	100644 blob $HEAD_gitmodules	.gitmodules
	100644 blob $HEAD_dir_sub_file	dir/sub-file.t
	160000 commit $HEAD_submodule	submodule
	100644 blob $HEAD_top_file	top-file.t
	EOF
test_ls_tree_format_mode_output "--full-name" "-t" <<-EOF
	100644 blob $HEAD_gitmodules	.gitmodules
	040000 tree $HEAD_dir	dir
	160000 commit $HEAD_submodule	submodule
	100644 blob $HEAD_top_file	top-file.t
	EOF
## opt = --full-tree
test_ls_tree_format_mode_output "--full-tree" "" "-t" <<-EOF
	100644 blob $HEAD_gitmodules	.gitmodules
	040000 tree $HEAD_dir	dir
	160000 commit $HEAD_submodule	submodule
	100644 blob $HEAD_top_file	top-file.t
	EOF
test_ls_tree_format_mode_output "--full-tree" "-d" <<-EOF
	040000 tree $HEAD_dir	dir
	160000 commit $HEAD_submodule	submodule
	EOF
test_ls_tree_format_mode_output "--full-tree" "-r" <<-EOF
	100644 blob $HEAD_gitmodules	.gitmodules
	100644 blob $HEAD_dir_sub_file	dir/sub-file.t
	160000 commit $HEAD_submodule	submodule
	100644 blob $HEAD_top_file	top-file.t
	EOF

test_done