fix: write new remote sections to the local config file (#1951)#2637
Merged
Sebastian Thiel (Byron) merged 2 commits intoJun 18, 2026
Merged
Conversation
…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]>
There was a problem hiding this comment.
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 usingsection_mut_or_create_new_filter(...)constrained toconfig.meta(). - Add a regression test ensuring a new remote saved in the presence of an override-only
remote.origin.*section writesurlinto 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.
Sebastian Thiel (Byron)
force-pushed
the
fix-remote-save-1951
branch
from
June 18, 2026 14:14
5226e08 to
5217d66
Compare
Sebastian Thiel (Byron)
enabled auto-merge
June 18, 2026 14:16
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.
Fixes #1951.
Problem
When a
remote.<name>section exists only from non-local configuration — e.g. a globalremote.origin.prune = true—Remote::save_towrote the newurl/fetchinto 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 existingsection_mut_or_create_new_filterAPI.Tests
Added
new_remote_in_presence_of_global_section_writes_to_local_fileingix/tests/gix/remote/save.rs: opens a repo withremote.origin.pruneprovided only as an override and asserts the savedurllands in a section owned by the local file. It fails before the change and passes after.Verified locally against
main:All pass (remote 39, clone 5, plus the new test); the existing save tests are unchanged.
Files changed
gix/src/remote/save.rsgix/tests/gix/remote/save.rsDisclosure: developed with AI assistance, reviewed and tested by me.