Skip to content

fix: don't apply the caller's GIT_INDEX_FILE or GIT_WORK_TREE to a new clone - #3035

Merged
Sebastian Thiel (Byron) merged 2 commits into
GitoxideLabs:mainfrom
any-victor:fix/clone-ignores-caller-repository-env
Oct 2, 2026
Merged

Sebastian Thiel (Byron) merged 2 commits into
GitoxideLabs:mainfrom
any-victor:fix/clone-ignores-caller-repository-env

Conversation

@any-victor

@any-victor any-victor commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Tasks

  • refackiew

Created by Codex on behalf of Byron. Byron will review before this is ready to merge.

A new clone now ignores the caller's repository-local environment overrides, including GIT_INDEX_FILE and GIT_WORK_TREE. Programs cloning from inside a Git hook therefore keep the new repository's index and checkout inside the clone instead of writing into the hook's repository. This is a documented deviation from git clone.

PrepareFetch reuses open::Options::without_repository_environment_overrides(). Editor and notes preferences (GIT_EDITOR and GIT_NOTES_REF) are still honored, as are authentication, proxy, and protocol settings. Regression coverage uses disposable repositories and checks that repository paths are ignored while these preferences survive.

The original clone fix was contributed by Victor Araújo (@any-victor) with Claude Code assistance. Byron's review update preserves editor and notes settings. Codex amended that review commit with fixes for failures introduced by the Rust 1.99 toolchain update: MSRV-compatible allowances for deprecated atomic operations, scoped lint allowances for generated async code, and stable integer-conversion diagnostic snapshots through the existing test helper.

Validation on Rust 1.99: all four just clippy -D warnings -A unknown-lints --no-deps configurations, both just doc configurations, formatting, and 46 targeted clone, parallel, checkout, allocation, and snapshot tests pass. Five snapshot-related tests also pass on Rust 1.98. GitHub CI is being monitored for the pushed head.

This addresses cloning from hook-launched mise tasks.

…a new clone

`clone::PrepareFetch` opened the repository it creates with the caller's repository-local
environment overrides. When the calling process runs inside a Git hook of another repository,
those variables describe that other repository: Git sets `GIT_INDEX_FILE` for `pre-commit`,
and hook runners may set `GIT_WORK_TREE`. The checkout then wrote the clone's index to the
caller's index file, and with `GIT_WORK_TREE` its files into the caller's worktree.

A new clone is never the repository these variables describe, so open it the way submodules and
worktrees are already opened, with `open::Options::without_repository_environment_overrides()`.
Authentication, proxy and protocol variables still apply.
@Byron

Byron commented Oct 2, 2026

Copy link
Copy Markdown
Member

Thanks!

While Git expects certain variables (in hooks) to be cleared, no matter how I think about it, for this API it seems like the wrong choice to adhere to that.

So let's change it, and declare the 'deviation' instead.

@any-victor

any-victor commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor Author

Sebastian Thiel (@Byron) no problem! Also, I noticed a few issues came up in regards to linting, those seem related to rust's latest stable update rather than my code changes though. Glad to assist on fixing them if you'd like me to.

@Byron
Sebastian Thiel (Byron) force-pushed the fix/clone-ignores-caller-repository-env branch from e770f19 to 0f08c8e Compare October 2, 2026 04:45
@Byron

Byron commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

All good, thanks, I am taking it from here.

- Kind of unrelated, and a pre-existing problem, but still worth seeing it addressed.
  - [P2] Preserve editor and notes overrides when isolating a clone — /Users/byron/dev/github.com/GitoxideLabs/gitoxide.fix-clone-ignores-caller-repository-env/gix/src/clone/mod.rs:120-120
    When `GIT_EDITOR` or `GIT_NOTES_REF` is set, this also suppresses those settings: `apply_environment_overrides()` gates them in the same `core` group as `GIT_WORK_TREE`. The returned clone consequently selects the wrong editor (potentially `None`) and notes reference, while reopening the same repository restores both. Preserve these non-location settings while filtering worktree/index overrides; reference Git retains them, consistent with the [Git-baseline guidance](AGENTS.md#L24).

CI on Rust 1.99 failed after the stable toolchain update, before reaching
all of the clone tests. The `lint` job rejected deprecated `fetch_update`
calls, existing emptiness assertions, and `#[must_use]` attributes generated
by `async_trait`. Rustdoc also flagged links in re-exported documentation.
Keep `fetch_update` for Rust 1.88 compatibility, allow the new emptiness lint
centrally, and scope the generated-code allowances to the affected modules.

The Linux ARM, ARM32, and Windows 32-bit tests failed because Rust 1.99
changed `TryFromIntError` messages. Normalize both new messages through the
existing `gix_testtools::redact_debug_snapshot()` helper, use that helper for
the pack-header snapshot, and check both signed and unsigned conversion failures.
The concrete errors, classifications, and diagnostic context remain asserted.

Validation: all four `just clippy -D warnings -A unknown-lints --no-deps`
configurations pass on Rust 1.99. The 46 targeted clone, parallel, checkout,
allocation, and snapshot tests pass on Rust 1.99; five snapshot-related tests
also pass on Rust 1.98. Formatting is unchanged.

Assisted-by: GPT 6.0 Astra
Co-authored-by: GPT 6.0 Astra <codex@openai.com>
@Byron
Sebastian Thiel (Byron) force-pushed the fix/clone-ignores-caller-repository-env branch from 0f08c8e to 95043b9 Compare October 2, 2026 04:59
@Byron
Sebastian Thiel (Byron) merged commit d2d078f into GitoxideLabs:main Oct 2, 2026
32 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.

2 participants