summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2023-04-11 10:13:46 +0100
committerEdward Thomson <ethomson@edwardthomson.com>2023-04-12 12:02:03 +0100
commite3ca080794404f563416c4c6f11cd23d54eb113a (patch)
tree0cf1bf3d569aac3fcc198f923d3910b4f37e3208
parentc058aa87dce4c67a3b86b3349beebd64b7bedcd3 (diff)
downloadlibgit2-e3ca080794404f563416c4c6f11cd23d54eb113a.tar.gz
config: return `GIT_ENOTFOUND` for missing programdata
When the programdata path is missing, ensure that we pass down the `GIT_ENOTFOUND` error to the caller instead of converting it to a generic `-1`.
-rw-r--r--src/libgit2/config.c7
-rw-r--r--tests/libgit2/config/find.c11
2 files changed, 16 insertions, 2 deletions
diff --git a/src/libgit2/config.c b/src/libgit2/config.c
index 6d15a8db6..23a8f9ffa 100644
--- a/src/libgit2/config.c
+++ b/src/libgit2/config.c
@@ -1174,9 +1174,12 @@ int git_config__find_programdata(git_str *path)
GIT_FS_PATH_OWNER_CURRENT_USER |
GIT_FS_PATH_OWNER_ADMINISTRATOR;
bool is_safe;
+ int error;
+
+ if ((error = git_sysdir_find_programdata_file(path, GIT_CONFIG_FILENAME_PROGRAMDATA)) < 0)
+ return error;
- if (git_sysdir_find_programdata_file(path, GIT_CONFIG_FILENAME_PROGRAMDATA) < 0 ||
- git_fs_path_owner_is(&is_safe, path->ptr, owner_level) < 0)
+ if (git_fs_path_owner_is(&is_safe, path->ptr, owner_level) < 0)
return -1;
if (!is_safe) {
diff --git a/tests/libgit2/config/find.c b/tests/libgit2/config/find.c
new file mode 100644
index 000000000..7ca8ec767
--- /dev/null
+++ b/tests/libgit2/config/find.c
@@ -0,0 +1,11 @@
+#include "clar_libgit2.h"
+
+void test_config_find__one(void)
+{
+ git_buf buf = GIT_BUF_INIT;
+
+ cl_git_fail_with(GIT_ENOTFOUND, git_config_find_global(&buf));
+ cl_git_fail_with(GIT_ENOTFOUND, git_config_find_xdg(&buf));
+ cl_git_fail_with(GIT_ENOTFOUND, git_config_find_system(&buf));
+ cl_git_fail_with(GIT_ENOTFOUND, git_config_find_programdata(&buf));
+}