8000 config: return `GIT_ENOTFOUND` for missing programdata · libgit2/libgit2@e3ca080 · GitHub
[go: up one dir, main page]

Skip to content

Commit e3ca080

Browse files
committed
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`.
1 parent c058aa8 commit e3ca080

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/libgit2/config.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,9 +1174,12 @@ int git_config__find_programdata(git_str *path)
11741174
GIT_FS_PATH_OWNER_CURRENT_USER |
11751175
GIT_FS_PATH_OWNER_ADMINISTRATOR;
11761176
bool is_safe;
1177+
int error;
1178+
1179+
if ((error = git_sysdir_find_programdata_file(path, GIT_CONFIG_FILENAME_PROGRAMDATA)) < 0)
1180+
return error;
11771181

1178-
if (git_sysdir_find_programdata_file(path, GIT_CONFIG_FILENAME_PROGRAMDATA) < 0 ||
1179-
git_fs_path_owner_is(&is_safe, path->ptr, owner_level) < 0)
1182+
if (git_fs_path_owner_is(&is_safe, path->ptr, owner_level) < 0)
11801183
return -1;
11811184

11821185
if (!is_safe) {

tests/libgit2/config/find.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include "clar_libgit2.h"
2+
3+
void test_config_find__one(void)
4+
{
5+
git_buf buf = GIT_BUF_INIT;
6+
7+
cl_git_fail_with(GIT_ENOTFOUND, git_config_find_global(&buf));
8+
cl_git_fail_with(GIT_ENOTFOUND, git_config_find_xdg(&buf));
9+
cl_git_fail_with(GIT_ENOTFOUND, git_config_find_system(&buf));
10+
cl_git_fail_with(GIT_ENOTFOUND, git_config_find_programdata(&buf));
11+
}

0 commit comments

Comments
 (0)
0