@@ -10,9 +10,40 @@ REPO_INFO_KEYS='
1010 layout.bare
1111 layout.shallow
1212 object.format
13+ path.common-dir
14+ path.config-file
15+ path.git-dir
16+ path.git-prefix
17+ path.grafts-file
18+ path.hooks-directory
19+ path.index-file
20+ path.logs-directory
21+ path.objects-directory
22+ path.packed-refs-file
23+ path.refs-directory
24+ path.shallow-file
25+ path.superproject-working-tree
26+ path.toplevel
1327 references.format
1428'
1529
30+ REPO_INFO_PATH_KEYS='
31+ path.common-dir
32+ path.config-file
33+ path.git-dir
34+ path.git-prefix
35+ path.grafts-file
36+ path.hooks-directory
37+ path.index-file
38+ path.logs-directory
39+ path.objects-directory
40+ path.packed-refs-file
41+ path.refs-directory
42+ path.shallow-file
43+ path.superproject-working-tree
44+ path.toplevel
45+ '
46+
1647# Test whether a key-value pair is correctly returned
1748#
1849# Usage: test_repo_info <label> <init command> <repo_name> <key> <expected value>
@@ -89,6 +120,171 @@ test_expect_success 'values returned in order requested' '
89120 test_cmp expect actual
90121'
91122
123+ test_expect_success ' category key returns all matching keys' '
124+ cat >expect <<-\EOF &&
125+ layout.bare=false
126+ layout.shallow=false
127+ EOF
128+ git init category-layout &&
129+ git -C category-layout repo info layout >actual &&
130+ test_cmp expect actual
131+ '
132+
133+ test_expect_success ' mixed key/category requests preserve request order' '
134+ cat >expect <<-EOF &&
135+ object.format=$(test_oid algo)
136+ layout.bare=false
137+ layout.shallow=false
138+ EOF
139+ git init mixed-order &&
140+ git -C mixed-order repo info object.format layout >actual &&
141+ test_cmp expect actual
142+ '
143+
144+ test_expect_success ' path.git-dir matches rev-parse --absolute-git-dir' '
145+ git init path-git-dir &&
146+ expected_value=$(git -C path-git-dir rev-parse --absolute-git-dir) &&
147+ echo "path.git-dir=$expected_value" >expect &&
148+ git -C path-git-dir repo info path.git-dir >actual &&
149+ test_cmp expect actual
150+ '
151+
152+ test_expect_success ' path.common-dir matches rev-parse --git-common-dir' '
153+ git init path-common-dir &&
154+ expected_value=$(git -C path-common-dir rev-parse --path-format=absolute --git-common-dir) &&
155+ echo "path.common-dir=$expected_value" >expect &&
156+ git -C path-common-dir repo info path.common-dir >actual &&
157+ test_cmp expect actual
158+ '
159+
160+ test_expect_success ' path.toplevel matches rev-parse --show-toplevel' '
161+ git init path-toplevel &&
162+ expected_value=$(git -C path-toplevel rev-parse --show-toplevel) &&
163+ echo "path.toplevel=$expected_value" >expect &&
164+ git -C path-toplevel repo info path.toplevel >actual &&
165+ test_cmp expect actual
166+ '
167+
168+ test_expect_success ' path.toplevel is empty in bare repository' '
169+ git init --bare bare-path-toplevel &&
170+ echo "path.toplevel=" >expect &&
171+ git -C bare-path-toplevel repo info path.toplevel >actual &&
172+ test_cmp expect actual
173+ '
174+
175+ test_expect_success ' path.git-prefix matches rev-parse --show-prefix' '
176+ git init path-prefix &&
177+ mkdir -p path-prefix/a/b &&
178+ expected_value=$(git -C path-prefix/a/b rev-parse --show-prefix) &&
179+ echo "path.git-prefix=$expected_value" >expect &&
180+ git -C path-prefix/a/b repo info path.git-prefix >actual &&
181+ test_cmp expect actual
182+ '
183+
184+ test_expect_success ' git-path style keys match rev-parse --git-path' '
185+ git init path-git-path &&
186+
187+ expected_value=$(git -C path-git-path rev-parse --path-format=absolute --git-path info/grafts) &&
188+ echo "path.grafts-file=$expected_value" >expect &&
189+ git -C path-git-path repo info path.grafts-file >actual &&
190+ test_cmp expect actual &&
191+
192+ expected_value=$(git -C path-git-path rev-parse --path-format=absolute --git-path index) &&
193+ echo "path.index-file=$expected_value" >expect &&
194+ git -C path-git-path repo info path.index-file >actual &&
195+ test_cmp expect actual &&
196+
197+ expected_value=$(git -C path-git-path rev-parse --path-format=absolute --git-path objects) &&
198+ echo "path.objects-directory=$expected_value" >expect &&
199+ git -C path-git-path repo info path.objects-directory >actual &&
200+ test_cmp expect actual &&
201+
202+ expected_value=$(git -C path-git-path rev-parse --path-format=absolute --git-path hooks) &&
203+ echo "path.hooks-directory=$expected_value" >expect &&
204+ git -C path-git-path repo info path.hooks-directory >actual &&
205+ test_cmp expect actual &&
206+
207+ expected_value=$(git -C path-git-path rev-parse --path-format=absolute --git-path config) &&
208+ echo "path.config-file=$expected_value" >expect &&
209+ git -C path-git-path repo info path.config-file >actual &&
210+ test_cmp expect actual &&
211+
212+ expected_value=$(git -C path-git-path rev-parse --path-format=absolute --git-path logs) &&
213+ echo "path.logs-directory=$expected_value" >expect &&
214+ git -C path-git-path repo info path.logs-directory >actual &&
215+ test_cmp expect actual &&
216+
217+ expected_value=$(git -C path-git-path rev-parse --path-format=absolute --git-path packed-refs) &&
218+ echo "path.packed-refs-file=$expected_value" >expect &&
219+ git -C path-git-path repo info path.packed-refs-file >actual &&
220+ test_cmp expect actual &&
221+
222+ expected_value=$(git -C path-git-path rev-parse --path-format=absolute --git-path refs) &&
223+ echo "path.refs-directory=$expected_value" >expect &&
224+ git -C path-git-path repo info path.refs-directory >actual &&
225+ test_cmp expect actual &&
226+
227+ expected_value=$(git -C path-git-path rev-parse --path-format=absolute --git-path shallow) &&
228+ echo "path.shallow-file=$expected_value" >expect &&
229+ git -C path-git-path repo info path.shallow-file >actual &&
230+ test_cmp expect actual
231+ '
232+
233+ test_expect_success ' path.superproject-working-tree is empty when not a submodule' '
234+ git init path-superproject &&
235+ echo "path.superproject-working-tree=" >expect &&
236+ git -C path-superproject repo info path.superproject-working-tree >actual &&
237+ test_cmp expect actual
238+ '
239+
240+ test_expect_success ' path.superproject-working-tree matches rev-parse in submodule' '
241+ git init path-superproject-origin &&
242+ echo x >path-superproject-origin/x &&
243+ git -C path-superproject-origin add x &&
244+ git -C path-superproject-origin commit -m x &&
245+
246+ git init path-superproject-parent &&
247+ git -C path-superproject-parent -c protocol.file.allow=always submodule add ../path-superproject-origin sm &&
248+
249+ expected_value=$(git -C path-superproject-parent/sm rev-parse --show-superproject-working-tree) &&
250+ echo "path.superproject-working-tree=$expected_value" >expect &&
251+ git -C path-superproject-parent/sm repo info path.superproject-working-tree >actual &&
252+ test_cmp expect actual
253+ '
254+
255+ test_expect_success ' path category returns all path keys' '
256+ git init path-category &&
257+ >expect &&
258+ for key in $REPO_INFO_PATH_KEYS
259+ do
260+ git -C path-category repo info "$key" >>expect || return 1
261+ done &&
262+ git -C path-category repo info path >actual &&
263+ test_cmp expect actual
264+ '
265+
266+ test_expect_success ' path-format=relative matches rev-parse for git-dir' '
267+ git init path-format-relative &&
268+ expected_value=$(git -C path-format-relative rev-parse --path-format=relative --git-dir) &&
269+ echo "path.git-dir=$expected_value" >expect &&
270+ git -C path-format-relative repo info --path-format=relative path.git-dir >actual &&
271+ test_cmp expect actual
272+ '
273+
274+ test_expect_success ' git repo info uses the last requested path format' '
275+ git init path-format-last &&
276+ expected_value=$(git -C path-format-last rev-parse --path-format=relative --git-dir) &&
277+ echo "path.git-dir=$expected_value" >expect &&
278+ git -C path-format-last repo info --path-format=absolute --path-format=relative path.git-dir >actual &&
279+ test_cmp expect actual
280+ '
281+
282+ test_expect_success ' git-repo-info aborts when requesting an invalid path format' '
283+ echo "fatal: invalid path format ${SQ}foo${SQ}" >expect &&
284+ test_must_fail git repo info --path-format=foo path.git-dir 2>actual &&
285+ test_cmp expect actual
286+ '
287+
92288test_expect_success ' git-repo-info fails if an invalid key is requested' '
93289 echo "error: key ${SQ}foo${SQ} not found" >expect &&
94290 test_must_fail git repo info foo 2>actual &&
0 commit comments