]> git.ipfire.org Git - thirdparty/git.git/commitdiff
config: die when --blob is used outside a repository
authorJeff King <peff@peff.net>
Fri, 18 May 2018 22:27:04 +0000 (15:27 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 21 May 2018 00:47:13 +0000 (09:47 +0900)
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 <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/config.c
t/t1307-config-blob.sh

index 01169dd628b24a7b5502550a6342ab73cb8154c5..d00439769ea7a6e9b62f0e1e61c370ff064c9baf 100644 (file)
@@ -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;
index eed31ffa30eebaa994b2fee569eb753e2a6a1477..37dc689d8c98fd776895e1ce6d18faee092001d3 100755 (executable)
@@ -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