fix: recognize git worktree root in find_vcs_root()#4640
Draft
evadeflow wants to merge 1 commit into
Draft
Conversation
In a git worktree (or a submodule) the ".git" entry is a file containing a "gitdir: <path>" pointer rather than a directory. `_is_valid_vcs_dir()` only accepted directories, so `find_vcs_root()` walked past the worktree root and failed to locate the project root, breaking `molecule.yml` discovery for users working inside a worktree. Treat a ".git" file as a valid VCS root marker when it contains a "gitdir:" pointer, while still rejecting unrelated stray ".git" files. Refs: ansible#4142
Contributor
|
@evadeflow We can't merge PRs with unsigned commits, please sign your commit and rebase the PR. Moving this to draft until then. Thanks! |
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.
Issue
Partially addresses #4142.
When Molecule is run from inside a git worktree, it fails to locate the project root, so
molecule.yml(and other project-root config) discovery breaks.Root cause
find_vcs_root()walks up the directory tree looking for a.gitentry, validated by_is_valid_vcs_dir(). That helper rejected anything that wasn't a directory:In a git worktree (and in a submodule), the
.gitentry is a file containing agitdir: <path>pointer, not a directory. So the worktree root was skipped andfind_vcs_root()either found an unrelated ancestor repo or fell back to the default.Fix
Treat a
.gitfile as a valid VCS root marker when its contents start withgitdir:. Stray, unrelated.gitfiles are still rejected, and the existing directory-based validation (a real.gitdir contains aHEAD) is unchanged.A stale comment that claimed worktrees have a
.gitdirectory with aHEADfile was also corrected.Tests
Added two unit tests in tests/unit/test_util.py:
test_find_vcs_root_in_git_worktree— a worktree whose.gitis agitdir:pointer file is recognized as the root.test_find_vcs_root_skips_bogus_git_file— a.gitfile without agitdir: pointeris ignored.Scope
This PR covers only worktree project-root detection. It uses Refs rather than Closes so #4142 stays open for any other aspects.