git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/2] config: die when --blob is used outside a repository

From
Jeff King <peff@peff.net>
Date
May 18, 2018, 22:27 UTC
Message-ID
<20180518222704.GB9623@sigill.intra.peff.net>
In-Reply-To
<20180518222506.GA9527@sigill.intra.peff.net>

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>
---
 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 69e7270356..4155734f4a 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -602,6 +602,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
-- 
2.17.0.1052.g7d69f75dbf
Previous: Stefan BellerNext: Taylor Blau
Message 4 of 6 in “fix a segfault in get_main_ref_store()”
  1. 0/2 fix a segfault in get_main_ref_store()Jeff King, May 18, 2018
  2. 1/2 get_main_ref_store: BUG() when outside a repositoryJeff King, May 18, 2018
  3. Stefan BellerMay 18, 2018
  4. 2/2 config: die when --blob is used outside a repositoryJeff King, May 18, 2018
  5. Taylor BlauMay 18, 2018
  6. Johannes SchindelinMay 18, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.