mirror of
https://git.proxmox.com/git/libgit2
synced 2025-12-31 13:07:34 +00:00
repository: ensure git_repository_discover() returns ENOTFOUND when unable to find a repository given the constraints
This commit is contained in:
parent
0b0957a661
commit
464cf248fd
@ -397,13 +397,14 @@ int git_repository_discover(
|
||||
{
|
||||
git_buf path = GIT_BUF_INIT;
|
||||
uint32_t flags = across_fs ? GIT_REPOSITORY_OPEN_CROSS_FS : 0;
|
||||
int error;
|
||||
|
||||
assert(start_path && repository_path && size > 0);
|
||||
|
||||
*repository_path = '\0';
|
||||
|
||||
if (find_repo(&path, NULL, start_path, flags, ceiling_dirs) < 0)
|
||||
return -1;
|
||||
if ((error = find_repo(&path, NULL, start_path, flags, ceiling_dirs)) < 0)
|
||||
return error != GIT_ENOTFOUND ? -1 : error;
|
||||
|
||||
if (size < (size_t)(path.size + 1)) {
|
||||
giterr_set(GITERR_REPOSITORY,
|
||||
|
||||
@ -82,7 +82,7 @@ void test_repo_discover__0(void)
|
||||
append_ceiling_dir(&ceiling_dirs_buf, TEMP_REPO_FOLDER);
|
||||
ceiling_dirs = git_buf_cstr(&ceiling_dirs_buf);
|
||||
|
||||
cl_git_fail(git_repository_discover(repository_path, sizeof(repository_path), DISCOVER_FOLDER, 0, ceiling_dirs));
|
||||
cl_assert_equal_i(GIT_ENOTFOUND, git_repository_discover(repository_path, sizeof(repository_path), DISCOVER_FOLDER, 0, ceiling_dirs));
|
||||
|
||||
cl_git_pass(git_repository_init(&repo, DISCOVER_FOLDER, 1));
|
||||
cl_git_pass(git_repository_discover(repository_path, sizeof(repository_path), DISCOVER_FOLDER, 0, ceiling_dirs));
|
||||
@ -117,7 +117,7 @@ void test_repo_discover__0(void)
|
||||
cl_git_fail(git_repository_discover(found_path, sizeof(found_path), ALTERNATE_MALFORMED_FOLDER1, 0, ceiling_dirs));
|
||||
cl_git_fail(git_repository_discover(found_path, sizeof(found_path), ALTERNATE_MALFORMED_FOLDER2, 0, ceiling_dirs));
|
||||
cl_git_fail(git_repository_discover(found_path, sizeof(found_path), ALTERNATE_MALFORMED_FOLDER3, 0, ceiling_dirs));
|
||||
cl_git_fail(git_repository_discover(found_path, sizeof(found_path), ALTERNATE_NOT_FOUND_FOLDER, 0, ceiling_dirs));
|
||||
cl_assert_equal_i(GIT_ENOTFOUND, git_repository_discover(found_path, sizeof(found_path), ALTERNATE_NOT_FOUND_FOLDER, 0, ceiling_dirs));
|
||||
|
||||
append_ceiling_dir(&ceiling_dirs_buf, SUB_REPOSITORY_FOLDER);
|
||||
ceiling_dirs = git_buf_cstr(&ceiling_dirs_buf);
|
||||
@ -125,9 +125,9 @@ void test_repo_discover__0(void)
|
||||
//this must pass as ceiling_directories cannot predent the current
|
||||
//working directory to be checked
|
||||
cl_git_pass(git_repository_discover(found_path, sizeof(found_path), SUB_REPOSITORY_FOLDER, 0, ceiling_dirs));
|
||||
cl_git_fail(git_repository_discover(found_path, sizeof(found_path), SUB_REPOSITORY_FOLDER_SUB, 0, ceiling_dirs));
|
||||
cl_git_fail(git_repository_discover(found_path, sizeof(found_path), SUB_REPOSITORY_FOLDER_SUB_SUB, 0, ceiling_dirs));
|
||||
cl_git_fail(git_repository_discover(found_path, sizeof(found_path), SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, 0, ceiling_dirs));
|
||||
cl_assert_equal_i(GIT_ENOTFOUND, git_repository_discover(found_path, sizeof(found_path), SUB_REPOSITORY_FOLDER_SUB, 0, ceiling_dirs));
|
||||
cl_assert_equal_i(GIT_ENOTFOUND, git_repository_discover(found_path, sizeof(found_path), SUB_REPOSITORY_FOLDER_SUB_SUB, 0, ceiling_dirs));
|
||||
cl_assert_equal_i(GIT_ENOTFOUND, git_repository_discover(found_path, sizeof(found_path), SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, 0, ceiling_dirs));
|
||||
|
||||
//.gitfile redirection should not be affected by ceiling directories
|
||||
ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER, ceiling_dirs, sub_repository_path);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user