Skip to content

Commit ad2d3a0

Browse files
authored
Merge pull request libgit2#6408 from kcsaul/fix-safe-directory-not-found
Ignore missing 'safe.directory' config during ownership checks
2 parents e45b25e + 93c071a commit ad2d3a0

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/libgit2/repository.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,9 @@ static int validate_ownership_config(bool *is_safe, const char *path)
521521
validate_ownership_cb,
522522
&ownership_data);
523523

524+
if (error == GIT_ENOTFOUND)
525+
error = 0;
526+
524527
git_config_free(config);
525528
git_str_dispose(&ownership_data.tmp);
526529

tests/libgit2/repo/open.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ void test_repo_open__validates_dir_ownership(void)
487487

488488
/* When the system user owns the repo config, fail */
489489
git_fs_path__set_owner(GIT_FS_PATH_OWNER_ADMINISTRATOR);
490-
cl_git_fail(git_repository_open(&repo, "empty_standard_repo"));
490+
cl_git_fail_with(GIT_EOWNER, git_repository_open(&repo, "empty_standard_repo"));
491491

492492
#ifdef GIT_WIN32
493493
/* When the user is an administrator, succeed on Windows. */
@@ -498,7 +498,7 @@ void test_repo_open__validates_dir_ownership(void)
498498

499499
/* When an unknown user owns the repo config, fail */
500500
git_fs_path__set_owner(GIT_FS_PATH_OWNER_OTHER);
501-
cl_git_fail(git_repository_open(&repo, "empty_standard_repo"));
501+
cl_git_fail_with(GIT_EOWNER, git_repository_open(&repo, "empty_standard_repo"));
502502
}
503503

504504
void test_repo_open__validates_bare_repo_ownership(void)
@@ -516,7 +516,7 @@ void test_repo_open__validates_bare_repo_ownership(void)
516516

517517
/* When the system user owns the repo config, fail */
518518
git_fs_path__set_owner(GIT_FS_PATH_OWNER_ADMINISTRATOR);
519-
cl_git_fail(git_repository_open(&repo, "testrepo.git"));
519+
cl_git_fail_with(GIT_EOWNER, git_repository_open(&repo, "testrepo.git"));
520520

521521
#ifdef GIT_WIN32
522522
/* When the user is an administrator, succeed on Windows. */
@@ -527,7 +527,7 @@ void test_repo_open__validates_bare_repo_ownership(void)
527527

528528
/* When an unknown user owns the repo config, fail */
529529
git_fs_path__set_owner(GIT_FS_PATH_OWNER_OTHER);
530-
cl_git_fail(git_repository_open(&repo, "testrepo.git"));
530+
cl_git_fail_with(GIT_EOWNER, git_repository_open(&repo, "testrepo.git"));
531531
}
532532

533533
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)
543543
cl_git_pass(cl_rename("empty_standard_repo/.gitted", "empty_standard_repo/.git"));
544544

545545
git_fs_path__set_owner(GIT_FS_PATH_OWNER_OTHER);
546-
cl_git_fail(git_repository_open(&repo, "empty_standard_repo"));
546+
cl_git_fail_with(GIT_EOWNER, git_repository_open(&repo, "empty_standard_repo"));
547547

548548
/* Add safe.directory options to the global configuration */
549549
git_str_joinpath(&config_path, clar_sandbox_path(), "__global_config");
@@ -587,7 +587,7 @@ void test_repo_open__can_allowlist_bare_gitdir(void)
587587
cl_fixture_sandbox("testrepo.git");
588588

589589
git_fs_path__set_owner(GIT_FS_PATH_OWNER_OTHER);
590-
cl_git_fail(git_repository_open(&repo, "testrepo.git"));
590+
cl_git_fail_with(GIT_EOWNER, git_repository_open(&repo, "testrepo.git"));
591591

592592
/* Add safe.directory options to the global configuration */
593593
git_str_joinpath(&config_path, clar_sandbox_path(), "__global_config");
@@ -632,7 +632,7 @@ void test_repo_open__can_reset_safe_directory_list(void)
632632
cl_git_pass(cl_rename("empty_standard_repo/.gitted", "empty_standard_repo/.git"));
633633

634634
git_fs_path__set_owner(GIT_FS_PATH_OWNER_OTHER);
635-
cl_git_fail(git_repository_open(&repo, "empty_standard_repo"));
635+
cl_git_fail_with(GIT_EOWNER, git_repository_open(&repo, "empty_standard_repo"));
636636

637637
/* Add safe.directory options to the global configuration */
638638
git_str_joinpath(&config_path, clar_sandbox_path(), "__global_config");
@@ -656,7 +656,7 @@ void test_repo_open__can_reset_safe_directory_list(void)
656656
clar_sandbox_path(), "empty_standard_repo");
657657
cl_git_rewritefile(config_filename.ptr, config_data.ptr);
658658

659-
cl_git_fail(git_repository_open(&repo, "empty_standard_repo"));
659+
cl_git_fail_with(GIT_EOWNER, git_repository_open(&repo, "empty_standard_repo"));
660660

661661
/* The blank resets tmp and allows subsequent declarations to succeed */
662662

0 commit comments

Comments
 (0)