Skip to content

fix: let GIT_WORK_TREE override core.bare - #2841

Merged
Sebastian Thiel (Byron) merged 4 commits into
GitoxideLabs:mainfrom
danielcadev:codex/fix-bare-git-work-tree-override
Jul 26, 2026
Merged

fix: let GIT_WORK_TREE override core.bare#2841
Sebastian Thiel (Byron) merged 4 commits into
GitoxideLabs:mainfrom
danielcadev:codex/fix-bare-git-work-tree-override

Conversation

@danielcadev

@danielcadev Daniel Castrillon (danielcadev) commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Description

Honor the GIT_WORK_TREE environment override when opening a repository configured with core.bare=true.

Git treats an explicit GIT_WORK_TREE as an effective worktree and reports the repository as non-bare. gix previously retained workdir: None, which prevented downstream consumers such as Starship from computing repository status.

The override is deliberately limited to GIT_WORK_TREE. A core.worktree CLI override still does not supersede core.bare, matching Git behavior.

Related downstream issue: starship/starship#7609
Supersedes the downstream workaround proposed in starship/starship#7617.

#1985 and #1987 addressed the strict-config error associated with GIT_WORK_TREE, but did not cover its interaction with core.bare.

Tests

  • Added a regression test for a bare repository with an external GIT_WORK_TREE.
  • Confirmed the repository becomes non-bare and status observes files in the external worktree.
  • Added a negative control proving that -c core.worktree=... does not override core.bare.
  • cargo fmt --all -- --check
  • Strict Clippy for gix
  • Complete cargo test -p gix --no-fail-fast: 410 passed

AI assistance

Codex assisted with investigation, implementation, testing, and preparation of this pull request. I reviewed the changes and verified the behavior locally against Git.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codex Review

worktree_dir = gix_path::normalize(wt_path.into(), current_dir).map(Cow::into_owned);

P2 Badge Handle over-root worktree paths before clearing bare

When a relative GIT_WORK_TREE contains more .. components than the current directory's depth, Git and the OS resolve through the root, but gix_path::normalize() returns None here. The subsequent config.is_bare = Some(false) therefore creates a repository with workdir() == None and is_bare() == false, causing index/worktree status to fail with MissingWorkDir instead of using the explicitly requested worktree. Treat normalization failure as an error or normalize this valid environment path with filesystem semantics before marking the repository non-bare.

AGENTS.md reference: AGENTS.md:L16-L18

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".

@danielcadev

Copy link
Copy Markdown
Contributor Author

Oh, okay, good catch. Thanks! I reproduced it with a relative GIT_WORK_TREE that traverses beyond the filesystem root. Git saturates at the root, while my original patch left gix non-bare without a worktree.

I updated the normalization only for the GIT_WORK_TREE environment override and added a regression that verifies both the resolved worktree and status traversal. The full gix suite (410 tests), formatting, and strict Clippy pass.

@Byron Sebastian Thiel (Byron) added the acknowledged an issue is accepted as shortcoming to be fixed label Jul 26, 2026
Signed-off-by: Daniel Castrillon <danielcadev@users.noreply.github.com>
Sebastian Thiel (Byron) and others added 2 commits July 26, 2026 17:18
That way, one can express another way with which Git handles worktrees.

Assisted-by: GPT 5.6
Co-authored-by: GPT 5.6 <codex@openai.com>
Assisted-by: GPT 5.6
Co-authored-by: GPT 5.6 <codex@openai.com>
@Byron
Sebastian Thiel (Byron) force-pushed the codex/fix-bare-git-work-tree-override branch from 67428ef to 8568341 Compare July 26, 2026 16:31
The messiness probably stems from all the little details around opening
a repo, but with enough coverage, it should be possible to find a solution
that is more suited and not messy at all.

Assisted-by: GPT 5.6
Co-authored-by: GPT 5.6 <codex@openai.com>
@Byron
Sebastian Thiel (Byron) force-pushed the codex/fix-bare-git-work-tree-override branch from 8568341 to f03905e Compare July 26, 2026 16:44
@Byron
Sebastian Thiel (Byron) merged commit da71d06 into GitoxideLabs:main Jul 26, 2026
32 checks passed
@danielcadev
Daniel Castrillon (danielcadev) deleted the codex/fix-bare-git-work-tree-override branch July 26, 2026 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

acknowledged an issue is accepted as shortcoming to be fixed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants