From 17b8a2d6cdfc359b1a7de6dd215dc3c32ab1dbfe Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 18 May 2018 15:27:04 -0700 Subject: [PATCH] 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 Signed-off-by: Junio C Hamano --- builtin/config.c | 3 +++ t/t1307-config-blob.sh | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/builtin/config.c b/builtin/config.c index 01169dd628..d00439769e 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -513,6 +513,9 @@ int cmd_config(int argc, const char **argv, const char *prefix) if (use_local_config && nongit) die(_("--local can only be used inside a git repository")); + if (given_config_source.blob && nongit) + die(_("--blob can only be used inside a git repository")); + if (given_config_source.file && !strcmp(given_config_source.file, "-")) { given_config_source.file = NULL; diff --git a/t/t1307-config-blob.sh b/t/t1307-config-blob.sh index eed31ffa30..37dc689d8c 100755 --- a/t/t1307-config-blob.sh +++ b/t/t1307-config-blob.sh @@ -73,4 +73,8 @@ test_expect_success 'can parse blob ending with CR' ' test_cmp expect actual ' +test_expect_success 'config --blob outside of a repository is an error' ' + test_must_fail nongit git config --blob=foo --list +' + test_done