From 1f2baa78c61bc99fe82bc62fc6d5a8d307984f3d Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 21 Oct 2010 10:45:44 -0400 Subject: config: treat non-existent config files as empty The git_config() function signals error by returning -1 in two instances: 1. An actual error occurs in opening a config file (parse errors cause an immediate die). 2. Of the three possible config files, none was found. However, this second case is often not an error at all; it simply means that the user has no configuration (they are outside a repo, and they have no ~/.gitconfig file). This can lead to confusing errors, such as when the bash completion calls "git config --list" outside of a repo. If the user has a ~/.gitconfig, the command completes succesfully; if they do not, it complains to stderr. This patch allows callers of git_config to distinguish between the two cases. Error is signaled by -1, and otherwise the return value is the number of files parsed. This means that the traditional "git_config(...) < 0" check for error should work, but callers who want to know whether we parsed any files or not can still do so. [jc: with tests from Jonathan] Signed-off-by: Jeff King Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- config.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'config.c') diff --git a/config.c b/config.c index 4b0a82040e..c63d6834e0 100644 --- a/config.c +++ b/config.c @@ -871,9 +871,7 @@ int git_config(config_fn_t fn, void *data) if (config_parameters) found += 1; - if (found == 0) - return -1; - return ret; + return ret == 0 ? found : ret; } /* -- cgit v1.2.3