Skip to content

fix: avoid GIT_DIR environment discovery panic#2648

Merged
Sebastian Thiel (Byron) merged 1 commit into
mainfrom
investigate-git-dir-panic
Jun 18, 2026
Merged

fix: avoid GIT_DIR environment discovery panic#2648
Sebastian Thiel (Byron) merged 1 commit into
mainfrom
investigate-git-dir-panic

Conversation

@Byron

@Byron Sebastian Thiel (Byron) commented Jun 17, 2026

Copy link
Copy Markdown
Member

Tasks

  • refackiew

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_DIR environment override by preserving the trust value already derived for the effective git directory before calling open_from_paths().

Reported issue

I ran into a panic while using this. You can reproduce by running

cd $(mktemp -d)
git init
GIT_DIR=.git hx newfile.txt

or

VISUAL=hx git --git-dir=.git commit --allow-empty

This panics at

let git_dir_trust = git_dir_trust.as_mut().expect("trust must be determined by now");
with the following backtrace:

thread 'main' panicked at ~/.local/share/cargo/registry/src/index.crates.io-1949cf8c6b5b557f/gix-0.84.0/src/open/repository.rs:184:52:
trust must be determined by now
stack backtrace:
   0: __rustc::rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::option::expect_failed
   3: gix::open::repository::<impl gix::types::ThreadSafeRepository>::open_from_paths
   4: gix::discover::<impl gix::types::ThreadSafeRepository>::discover_with_environment_overrides_opts
   5: helix_vcs::git::open_repo
   6: helix_vcs::git::get_diff_base
   7: helix_vcs::DiffProviderRegistry::get_diff_base
   8: helix_view::editor::Editor::open
   9: helix_term::application::Application::new
  10: hx::main_impl::{{closure}}
  11: tokio::runtime::park::CachedParkThread::block_on
  12: tokio::runtime::context::runtime::enter_runtime
  13: tokio::runtime::runtime::Runtime::block_on
  14: hx::main

For context, I use the --git-dir option 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 in Options before opening, matching discover_opts() and preventing the internal expect() from being reached with unset trust.

Git baseline

git --git-dir=<repo/.git> --work-tree=<repo> status --short exits successfully.

Validation

  • cargo test -p gix --test gix repository::open::discover_with_git_dir_environment_override_sets_trust
  • cargo test -p gix --test gix repository::open
  • codex review --commit b3e83763562408cb99c8d860ea823607195119b8

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]>
@Byron
Sebastian Thiel (Byron) marked this pull request as ready for review June 18, 2026 06:28
Copilot AI review requested due to automatic review settings June 18, 2026 06:28

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_trust in open_with_environment_overrides() before calling open_from_paths().
  • Add a regression test covering repository discovery with a GIT_DIR environment 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.

@Byron
Sebastian Thiel (Byron) merged commit 5dfb44d into main Jun 18, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants