Skip to content

fix: write new remote sections to the local config file (#1951)#2637

Merged
Sebastian Thiel (Byron) merged 2 commits into
GitoxideLabs:mainfrom
ameyypawar:fix-remote-save-1951
Jun 18, 2026
Merged

fix: write new remote sections to the local config file (#1951)#2637
Sebastian Thiel (Byron) merged 2 commits into
GitoxideLabs:mainfrom
ameyypawar:fix-remote-save-1951

Conversation

@ameyypawar

Copy link
Copy Markdown
Contributor

Fixes #1951.

Problem

When a remote.<name> section exists only from non-local configuration — e.g. a global remote.origin.prune = trueRemote::save_to wrote the new url/fetch into that foreign section instead of a local one. The metadata then mixes sources, and a caller that writes back only local sections (write_to_filter(|s| s.meta() == config.meta()), as jj does) loses the new remote.

Fix

Select the write-target section filtered to the file's own metadata, creating a fresh local section when only a foreign one exists — the approach suggested by the maintainer in the issue. It's a single call changed in gix/src/remote/save.rs, reusing the existing section_mut_or_create_new_filter API.

Tests

Added new_remote_in_presence_of_global_section_writes_to_local_file in gix/tests/gix/remote/save.rs: opens a repo with remote.origin.prune provided only as an override and asserts the saved url lands in a section owned by the local file. It fails before the change and passes after.

Verified locally against main:

cargo fmt -p gix --check
cargo clippy -p gix --all-targets -- -D warnings
cargo test -p gix --test gix remote:: clone::

All pass (remote 39, clone 5, plus the new test); the existing save tests are unchanged.

Files changed

  • gix/src/remote/save.rs
  • gix/tests/gix/remote/save.rs

Disclosure: developed with AI assistance, reviewed and tested by me.

…s#1951)

`Remote::save_to` selected the section to write into with
`section_mut_or_create_new`, which reuses any same-named section regardless of
its source. When a `remote.<name>` section was present from non-local
configuration (e.g. global `remote.origin.prune`), the new `url`/`fetch` values
were written into that foreign section, mixing metadata and getting lost when
only local sections are written back.

Select the target section filtered to the file's own metadata, creating a fresh
local section when only a foreign one exists.

Co-authored-by: Claude <[email protected]>

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

Fixes Remote::save_to() so that when a remote.<name> section exists only from non-local configuration sources (e.g., API/global overrides), saving a new remote writes into a section owned by the local config file metadata instead of mutating the foreign section.

Changes:

  • Update Remote::save_to() to select the target section using section_mut_or_create_new_filter(...) constrained to config.meta().
  • Add a regression test ensuring a new remote saved in the presence of an override-only remote.origin.* section writes url into a local-owned section.
  • Add snapshot + metadata assertions to validate section ordering and ownership.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
gix/src/remote/save.rs Switch write-target selection to a metadata-filtered remote section to avoid mutating non-local sources.
gix/tests/gix/remote/save.rs Add regression test covering override-only remote sections and verifying local metadata ownership for the new url.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread gix/src/remote/save.rs
Comment thread gix/tests/gix/remote/save.rs
Comment thread gix/tests/gix/remote/save.rs Outdated
@Byron
Sebastian Thiel (Byron) merged commit 847eb4a into GitoxideLabs:main Jun 18, 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.

New remotes save with unexpected metadata in the presence of global configuration

3 participants