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

[PATCH amend] git-config: print error message if the config file cannot be read

From
Gerrit Pape <pape@smarden.org>
Date
Oct 12, 2007, 11:40 UTC
Message-ID
<20071012114057.30803.qmail@12f4c67b8560e2.315fe32.mid.smarden.org>
In-Reply-To
<470B8286.5060006@viscovery.net>

Instead of simply exiting with 255, print an error message including the reason why a config file specified through --file cannot be opened or read.

The problem was noticed by Joey Hess, reported through
 http://bugs.debian.org/445208
---
On Tue, Oct 09, 2007 at 02:16:41PM +0100, Johannes Schindelin wrote:
> On Tue, 9 Oct 2007, Gerrit Pape wrote:
> > +           if (git_config(show_all_config) == -1)
> I'd rather check for < 0, just for future proofing.
Okay.
On Tue, Oct 09, 2007 at 03:30:46PM +0200, Johannes Sixt wrote:
Show 13 quoted lines
> Gerrit Pape schrieb:
> >+    if (show_all) {
> >+            if (git_config(show_all_config) == -1)
> >+                    die("unable to read config file %s: %s",
> >+                        getenv(CONFIG_ENVIRONMENT), strerror(errno));
> I don't think that this works well: If there are no config files at
> all, then we don't want to see an error - just as if the config file
> were empty.
>
> Also, I don't think that errno is reliable at this point.
>
> You probably want to see an error message *only* if you have supplied
> a file name with --file.

I changed the patch to die() only if --file was sepcified, and errno is not 0.

Thanks, Gerrit.
 builtin-config.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/builtin-config.c b/builtin-config.c
index 4444d52..e5bf791 100644
--- a/builtin-config.c
+++ b/builtin-config.c
@@ -172,8 +172,12 @@ int cmd_config(int argc, const char **argv, const char *prefix)
 			type = T_INT;
 		else if (!strcmp(argv[1], "--bool"))
 			type = T_BOOL;
-		else if (!strcmp(argv[1], "--list") || !strcmp(argv[1], "-l"))
-			return git_config(show_all_config);
+		else if (!strcmp(argv[1], "--list") || !strcmp(argv[1], "-l")) {
+			if (git_config(show_all_config) < 0 && file && errno)
+				die("unable to read config file %s: %s", file,
+				    strerror(errno));
+			return 0;
+		}
 		else if (!strcmp(argv[1], "--global")) {
 			char *home = getenv("HOME");
 			if (home) {
-- 
1.5.3.4
Previous: Johannes SixtNext: Johannes Sixt
Message 4 of 5 in “git-config: print error message if the config file cannot be read”
  1. git-config: print error message if the config file cannot be readGerrit Pape, Oct 9, 2007
  2. Johannes SchindelinOct 9, 2007
  3. Johannes SixtOct 9, 2007
  4. git-config: print error message if the config file cannot be readGerrit Pape, Oct 12, 2007
  5. Johannes SixtOct 12, 2007

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.