diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2022-11-18 13:54:49 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-18 13:54:49 +0000 |
commit | ad2d3a06963ebfd13a04deb619e839b1346a4353 (patch) | |
tree | c49e6b3bb7aa79e081b0571dfd3fb5a97ad08124 | |
parent | e45b25eac3e945845b3a54faaa56f1e0f610238c (diff) | |
parent | 93c071ac4072bc0cda56bfef371b4890fec40a89 (diff) | |
download | libgit2-ad2d3a06963ebfd13a04deb619e839b1346a4353.tar.gz |
Merge pull request #6408 from kcsaul/fix-safe-directory-not-found
Ignore missing 'safe.directory' config during ownership checks
-rw-r--r-- | src/libgit2/repository.c | 3 | ||||
-rw-r--r-- | tests/libgit2/repo/open.c | 16 |
2 files changed, 11 insertions, 8 deletions
diff --git a/src/libgit2/repository.c b/src/libgit2/repository.c index 90ac91db9..dd443a630 100644 --- a/src/libgit2/repository.c +++ b/src/libgit2/repository.c @@ -521,6 +521,9 @@ static int validate_ownership_config(bool *is_safe, const char *path) validate_ownership_cb, &ownership_data); + if (error == GIT_ENOTFOUND) + error = 0; + git_config_free(config); git_str_dispose(&ownership_data.tmp); diff --git a/tests/libgit2/repo/open.c b/tests/libgit2/repo/open.c index 634ba59d2..a7e7828ab 100644 --- a/tests/libgit2/repo/open.c +++ b/tests/libgit2/repo/open.c @@ -487,7 +487,7 @@ void test_repo_open__validates_dir_ownership(void) /* When the system user owns the repo config, fail */ git_fs_path__set_owner(GIT_FS_PATH_OWNER_ADMINISTRATOR); - cl_git_fail(git_repository_open(&repo, "empty_standard_repo")); + cl_git_fail_with(GIT_EOWNER, git_repository_open(&repo, "empty_standard_repo")); #ifdef GIT_WIN32 /* When the user is an administrator, succeed on Windows. */ @@ -498,7 +498,7 @@ void test_repo_open__validates_dir_ownership(void) /* When an unknown user owns the repo config, fail */ git_fs_path__set_owner(GIT_FS_PATH_OWNER_OTHER); - cl_git_fail(git_repository_open(&repo, "empty_standard_repo")); + cl_git_fail_with(GIT_EOWNER, git_repository_open(&repo, "empty_standard_repo")); } void test_repo_open__validates_bare_repo_ownership(void) @@ -516,7 +516,7 @@ void test_repo_open__validates_bare_repo_ownership(void) /* When the system user owns the repo config, fail */ git_fs_path__set_owner(GIT_FS_PATH_OWNER_ADMINISTRATOR); - cl_git_fail(git_repository_open(&repo, "testrepo.git")); + cl_git_fail_with(GIT_EOWNER, git_repository_open(&repo, "testrepo.git")); #ifdef GIT_WIN32 /* When the user is an administrator, succeed on Windows. */ @@ -527,7 +527,7 @@ void test_repo_open__validates_bare_repo_ownership(void) /* When an unknown user owns the repo config, fail */ git_fs_path__set_owner(GIT_FS_PATH_OWNER_OTHER); - cl_git_fail(git_repository_open(&repo, "testrepo.git")); + cl_git_fail_with(GIT_EOWNER, git_repository_open(&repo, "testrepo.git")); } void test_repo_open__can_allowlist_dirs_with_problematic_ownership(void) @@ -543,7 +543,7 @@ void test_repo_open__can_allowlist_dirs_with_problematic_ownership(void) cl_git_pass(cl_rename("empty_standard_repo/.gitted", "empty_standard_repo/.git")); git_fs_path__set_owner(GIT_FS_PATH_OWNER_OTHER); - cl_git_fail(git_repository_open(&repo, "empty_standard_repo")); + cl_git_fail_with(GIT_EOWNER, git_repository_open(&repo, "empty_standard_repo")); /* Add safe.directory options to the global configuration */ git_str_joinpath(&config_path, clar_sandbox_path(), "__global_config"); @@ -587,7 +587,7 @@ void test_repo_open__can_allowlist_bare_gitdir(void) cl_fixture_sandbox("testrepo.git"); git_fs_path__set_owner(GIT_FS_PATH_OWNER_OTHER); - cl_git_fail(git_repository_open(&repo, "testrepo.git")); + cl_git_fail_with(GIT_EOWNER, git_repository_open(&repo, "testrepo.git")); /* Add safe.directory options to the global configuration */ git_str_joinpath(&config_path, clar_sandbox_path(), "__global_config"); @@ -632,7 +632,7 @@ void test_repo_open__can_reset_safe_directory_list(void) cl_git_pass(cl_rename("empty_standard_repo/.gitted", "empty_standard_repo/.git")); git_fs_path__set_owner(GIT_FS_PATH_OWNER_OTHER); - cl_git_fail(git_repository_open(&repo, "empty_standard_repo")); + cl_git_fail_with(GIT_EOWNER, git_repository_open(&repo, "empty_standard_repo")); /* Add safe.directory options to the global configuration */ git_str_joinpath(&config_path, clar_sandbox_path(), "__global_config"); @@ -656,7 +656,7 @@ void test_repo_open__can_reset_safe_directory_list(void) clar_sandbox_path(), "empty_standard_repo"); cl_git_rewritefile(config_filename.ptr, config_data.ptr); - cl_git_fail(git_repository_open(&repo, "empty_standard_repo")); + cl_git_fail_with(GIT_EOWNER, git_repository_open(&repo, "empty_standard_repo")); /* The blank resets tmp and allows subsequent declarations to succeed */ |