feat(repository): support repository discovery from non-existent subpaths#7217
Open
yassine-safraoui wants to merge 1 commit intolibgit2:mainfrom
Open
feat(repository): support repository discovery from non-existent subpaths#7217yassine-safraoui wants to merge 1 commit intolibgit2:mainfrom
yassine-safraoui wants to merge 1 commit intolibgit2:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes repository discovery when the input path includes non-existent descendants inside an existing repository tree (issue #6383).
Problem
git_repository_discovercurrently fails early whenstart_pathcannot be prettified (for example,/path/to/repo/missing1/missing2), even if a valid repository exists in an ancestor directory.What changed
src/libgit2/repository.cIn
find_repo_traverse:git_fs_path_prettify(&path, start_path, NULL)handling:GIT_ENOTFOUND, discovery now continues using the rawstart_pathinstead of returning immediately.GIT_ENOTFOUNDerrors are still returned."."(when no minimum iterations remain), to avoid walking past the effective root in that case..gitdir/file checks while allowing discovery from non-existent subpaths.git_fs_path_prettify_dir(&out->gitdir, out->gitdir.ptr, NULL)after successful discovery.Why the final
prettify_dircall is neededIf the initial prettify fails because the input path is invalid/non-existent, we may still successfully discover a valid repo by walking ancestors. In that case, we should still normalize the discovered
gitdirbefore returning.That is why
git_fs_path_prettify_diris called at the end with the known-valid discoveredgitdirpath.I considered tracking this with a boolean (set when initial prettify fails) and only calling
prettify_dirconditionally, but the extra call is low-cost and keeping it unconditional keeps control flow simpler.tests/libgit2/repo/discover.cAdded tests covering:
"."as ceiling.Also added test fixture setup for a non-repository folder subtree used by the new cases.
Validation