Skip to content

version_experiment ignores Git worktrees and can select an outer repository #3097

Open

Description

@Elon-Jiang

[x] I reviewed the experiment versioning API and existing tests.

Describe the bug

version_experiment() with its default repo_path=None cannot discover a linked Git worktree: find_git_root() accepts a .git directory but ignores the .git file Git creates for worktrees. A sibling worktree raises ValueError: No git repository found. A worktree nested under another repository instead discovers the outer repository and versions that checkout, leaving the experiment changes uncommitted in the intended worktree.

Reproduction

With GitPython installed (ragas[git]), create a temporary repository with one committed file, then:

git -C main worktree add -b experiment ../linked
cd linked
python -c 'from ragas.experiment import version_experiment; print(version_experiment("worktree-repro", create_branch=False))'

On current main 298b68274234c060deacab3cf5fb52aa3a20e885, this raises ValueError, although git rev-parse --show-toplevel identifies the worktree and explicitly passing repo_path="." to version_experiment works. Running from a subdirectory has the same failure.

Expected behavior

Detect the nearest Git checkout whether its .git marker is a directory or a gitfile, so default experiment versioning targets the current worktree.

Investigation / contribution

Found while running the existing experiment suite in a real linked worktree, not during a production incident. I have a scoped fix and tests with actual temporary Git repositories and GitPython: ordinary/sibling-worktree/nested-worktree layouts, each from root and subdirectory. Four cases fail before the fix; two ordinary-repository controls pass. The tests check committed file contents, the recorded branch/commit and preservation of the main checkout's HEAD/files. Worktree refs are intentionally shared, so a new branch is visible from both checkouts.

Environment: macOS arm64, Python 3.12.13. No model, external backend or Git mock is used. All 267 current open PR file lists and all-state worktree/gitfile/version_experiment searches were checked; overlapping files contain unrelated NaN/style/concurrency/test-dependency changes.

Codex assisted with investigation, implementation and validation under the contributor's authorization.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions