In the first case, we already correctly return -1 if fopen() fails to open. But we should report something so people know what's wrong. In the second case, config_file == NULL does not necessarily mean "no config file". Bail out if needed. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx> --- config.c | 8 +++++++- t/t1308-config-set.sh | 4 +++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/config.c b/config.c index 1a4d85537b..ac9effa7aa 100644 --- a/config.c +++ b/config.c @@ -1401,7 +1401,8 @@ int git_config_from_file(config_fn_t fn, const char *filename, void *data) ret = do_config_from_file(fn, CONFIG_ORIGIN_FILE, filename, filename, f, data); funlockfile(f); fclose(f); - } + } else if (errno != ENOENT) + warn_on_inaccessible(filename); return ret; } @@ -2601,6 +2602,11 @@ int git_config_rename_section_in_file(const char *config_filename, } if (!(config_file = fopen(config_filename, "rb"))) { + if (errno != ENOENT) { + warn_on_inaccessible(config_filename); + ret = -1; + goto out; + } /* no config file means nothing to rename, no error */ goto commit_and_out; } diff --git a/t/t1308-config-set.sh b/t/t1308-config-set.sh index ff50960cca..13e95561f4 100755 --- a/t/t1308-config-set.sh +++ b/t/t1308-config-set.sh @@ -187,7 +187,9 @@ test_expect_success POSIXPERM,SANITY 'proper error on non-accessible files' ' chmod -r .git/config && test_when_finished "chmod +r .git/config" && echo "Error (-1) reading configuration file .git/config." >expect && - test_expect_code 2 test-config configset_get_value foo.bar .git/config 2>actual && + test_expect_code 2 test-config configset_get_value foo.bar .git/config 2>output && + grep "^warning:" output && + grep "^Error" output >actual && test_cmp expect actual ' -- 2.11.0.157.gd943d85