Skip to content

Commit 3c4a531

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 58aaf59 commit 3c4a531

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

Documentation/git-rev-parse.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,9 @@ The following options are unaffected by `--path-format`:
307307
input, multiple algorithms may be printed, space-separated.
308308
If not specified, the default is "storage".
309309

310+
--show-ref-format::
311+
Show the reference storage format used for the repository.
312+
310313

311314
Other Options
312315
~~~~~~~~~~~~~

builtin/rev-parse.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,10 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
10621062
puts(the_hash_algo->name);
10631063
continue;
10641064
}
1065+
if (!strcmp(arg, "--show-ref-format")) {
1066+
puts(ref_storage_format_to_name(the_repository->ref_storage_format));
1067+
continue;
1068+
}
10651069
if (!strcmp(arg, "--end-of-options")) {
10661070
seen_end_of_options = 1;
10671071
if (filter & (DO_FLAGS | DO_REVS))

t/t1500-rev-parse.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,23 @@ test_expect_success 'rev-parse --show-object-format in repo' '
208208
grep "unknown mode for --show-object-format: squeamish-ossifrage" err
209209
'
210210

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+
211228
test_expect_success '--show-toplevel from subdir of working tree' '
212229
pwd >expect &&
213230
git -C sub/dir rev-parse --show-toplevel >actual &&

0 commit comments

Comments
 (0)