Skip to content

Commit 17b8a2d

Browse files
peffgitster
authored andcommitted
config: die when --blob is used outside a repository
If you run "config --blob" outside of a repository, then we eventually try to resolve the blob name and hit a BUG(). Let's catch this earlier and provide a useful message. Note that we could also catch this much lower in the stack, in git_config_from_blob_ref(). That might cover other callsites, too, but it's unclear whether those ones would actually be bugs or not. So let's leave the low-level functions to assume the caller knows what it's doing (and BUG() if it turns out it doesn't). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 468165c commit 17b8a2d

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

builtin/config.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,9 @@ int cmd_config(int argc, const char **argv, const char *prefix)
513513
if (use_local_config && nongit)
514514
die(_("--local can only be used inside a git repository"));
515515

516+
if (given_config_source.blob && nongit)
517+
die(_("--blob can only be used inside a git repository"));
518+
516519
if (given_config_source.file &&
517520
!strcmp(given_config_source.file, "-")) {
518521
given_config_source.file = NULL;

t/t1307-config-blob.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,8 @@ test_expect_success 'can parse blob ending with CR' '
7373
test_cmp expect actual
7474
'
7575

76+
test_expect_success 'config --blob outside of a repository is an error' '
77+
test_must_fail nongit git config --blob=foo --list
78+
'
79+
7680
test_done

0 commit comments

Comments
 (0)