builtin/rev-parse: introduce `--show-ref-format` flag
Introduce a new `--show-ref-format` to git-rev-parse(1) that causes it to print the ref format used by a repository. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Dec 29, 2023 at 08:27 UTC
3c4a5318afb4978a037c83ccd9bbeb870b3f0543
3 files changed
+24
Documentation/git-rev-parse.txt
+3
@@ -307,6 +307,9 @@ The following options are unaffected by `--path-format`:
307
input, multiple algorithms may be printed, space-separated.
308
If not specified, the default is "storage".
309
310
+--show-ref-format::
311
+ Show the reference storage format used for the repository.
312
+
313
314
Other Options
315
~~~~~~~~~~~~~
builtin/rev-parse.c
+4
@@ -1062,6 +1062,10 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
1062
puts(the_hash_algo->name);
1063
continue;
1064
}
1065
+ if (!strcmp(arg, "--show-ref-format")) {
1066
+ puts(ref_storage_format_to_name(the_repository->ref_storage_format));
1067
+ continue;
1068
+ }
1069
if (!strcmp(arg, "--end-of-options")) {
1070
seen_end_of_options = 1;
1071
if (filter & (DO_FLAGS | DO_REVS))
t/t1500-rev-parse.sh
+17
@@ -208,6 +208,23 @@ test_expect_success 'rev-parse --show-object-format in repo' '
208
grep "unknown mode for --show-object-format: squeamish-ossifrage" err
209
'
210
211
+test_expect_success 'rev-parse --show-ref-format' '
212
+ test_detect_ref_format >expect &&
213
+ git rev-parse --show-ref-format >actual &&
214
+ test_cmp expect actual
215
+'
216
+
217
+test_expect_success 'rev-parse --show-ref-format with invalid storage' '
218
+ test_when_finished "rm -rf repo" &&
219
+ git init repo &&
220
+ (
221
+ cd repo &&
222
+ git config extensions.refstorage broken &&
223
+ test_must_fail git rev-parse --show-ref-format 2>err &&
224
+ grep "error: invalid value for ${SQ}extensions.refstorage${SQ}: ${SQ}broken${SQ}" err
225
+ )
226
+'
227
+
228
test_expect_success '--show-toplevel from subdir of working tree' '
229
pwd >expect &&
230
git -C sub/dir rev-parse --show-toplevel >actual &&