fix: avoid GIT_DIR environment discovery panic#2648
Merged
Conversation
A Helix user reported that opening a repository with GIT_DIR set could panic in gix while discovering a repository through environment overrides. The reported reproductions used GIT_DIR=.git with Helix or git --git-dir=.git invoking an editor, and the panic came from open_from_paths() expecting git-dir trust to have already been determined. The GIT_DIR override path in open_with_environment_overrides() already determines ownership trust for the effective git directory and selects options from the trust mapping, but it did not store that trust in the Options passed to open_from_paths(). Store the determined trust there, matching discover_opts(), so configuration loading receives an explicit trust value instead of reaching the internal expect(). Git baseline: `git --git-dir=<repo/.git> --work-tree=<repo> status --short` exits successfully. Co-authored-by: Sebastian Thiel <[email protected]>
Sebastian Thiel (Byron)
force-pushed
the
investigate-git-dir-panic
branch
from
June 18, 2026 06:26
b3e8376 to
3b4a6bc
Compare
Sebastian Thiel (Byron)
marked this pull request as ready for review
June 18, 2026 06:28
There was a problem hiding this comment.
Pull request overview
This PR fixes a panic in gix repository discovery when GIT_DIR is set by ensuring the already-computed trust level for the effective git directory is propagated into open_from_paths(), avoiding an internal expect() on missing trust.
Changes:
- Preserve the computed
git_dir_trustinopen_with_environment_overrides()before callingopen_from_paths(). - Add a regression test covering repository discovery with a
GIT_DIRenvironment override.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
gix/src/open/repository.rs |
Sets options.git_dir_trust based on ownership-derived trust before opening from paths, preventing a panic when GIT_DIR overrides discovery. |
gix/tests/gix/repository/open.rs |
Adds a serial regression test verifying discovery with GIT_DIR works without panicking and opens the expected git directory. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Sebastian Thiel (Byron)
enabled auto-merge
June 18, 2026 06:32
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.
Tasks
Created by Codex on behalf of Byron. Byron will review before this is ready to merge.
Summary
Avoid a panic when repository discovery uses a
GIT_DIRenvironment override by preserving the trust value already derived for the effective git directory before callingopen_from_paths().Reported issue
I ran into a panic while using this. You can reproduce by running
or
This panics at
gitoxide/gix/src/open/repository.rs
Line 184 in eac50e1
For context, I use the
--git-diroption for tracking my dotfiles in a bare git repo.Change
open_with_environment_overrides()already computes ownership trust for the effective git directory and chooses the mapped options from that trust level. This change stores the computed trust inOptionsbefore opening, matchingdiscover_opts()and preventing the internalexpect()from being reached with unset trust.Git baseline
git --git-dir=<repo/.git> --work-tree=<repo> status --shortexits successfully.Validation
cargo test -p gix --test gix repository::open::discover_with_git_dir_environment_override_sets_trustcargo test -p gix --test gix repository::opencodex review --commit b3e83763562408cb99c8d860ea823607195119b8