Skip to content

Fix config parameter precedence for same-scope values - #41

Merged
mjcheetham merged 1 commit into
git-ecosystem:mainfrom
sambostock:fix-config-same-scope-precedence
Sep 21, 2026
Merged

mjcheetham merged 1 commit into
git-ecosystem:mainfrom
sambostock:fix-config-same-scope-precedence

Conversation

@sambostock

@sambostock sambostock commented Oct 21, 2025 •

Copy link
Copy Markdown
Contributor

From git config's documentation:

The files are read in the order given above, with last value found taking precedence over values read earlier.

Currently, we discard values if we already have one with the same priority. However, this gives us "first one wins" semantics, which is incorrect.

By instead only discarding values if we already have one with a higher priority, we can achieve "last one wins" semantics, matching git.


This is of particular importance because we use config values to resolve the nickname and ruleset fields, so the value we resolve must match what a user would expect when writing their config. For example, consider the following git config:

[otel.trace2]
  ruleset = dl:drop # Drop traces by default)

[includeIf "hasconfig:remote.*.url:https://example.com/my-repo.git"]
  path = my-repo-tracing.gitconfig

and in my-repo-tracing.gitconfig

[otel.trace2]
  ruleset = dl:verbose # Collect detailed traces for my-repo

Because we have "first one wins" semantics instead of git's "last one wins" semantics, the override doesn't do anything and traces are dropped unconditionally.

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.

Copilot review overview

🟢 Approval recommended

The implementation matches Git precedence semantics and includes focused regression coverage.

Review effort: Balanced
Findings: 1 Low severity

Open (1)
What changed in this PR

Corrects same-scope Git configuration precedence so the latest value wins.

Changes:

  • Accepts later values with equal priority.
  • Adds regression coverage for local and global scopes.
File Description
evt_apply.go Updates precedence logic.
evt_apply_test.go Tests same-scope last-value behavior.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread evt_apply_test.go
From `git config`'s documentation:

> The files are read in the order given above, with last value found taking precedence over values read earlier.

Currently, we discard values if we already have one with the same
priority. However, this gives us "first one wins" semantics, which is
incorrect.

By instead only discarding values if we already have one with a higher
priority, we can achieve "last one wins" semantics, matching `git`.

This is of particular importance because we use config values to resolve
the nickname and ruleset fields, so the value we resolve must match what
a user would expect when writing their config. For example, consider the
following git config:

    [otel.trace2]
      ruleset = dl:drop # Drop traces by default)

    [includeIf "hasconfig:remote.*.url:https://example.com/my-repo.git"]
      path = my-repo-tracing.gitconfig

and in my-repo-tracing.gitconfig

    [otel.trace2]
      ruleset = dl:verbose # Collect detailed traces for my-repo

Because we have "first one wins" semantics instead of git's "last one
wins" semantics, the override doesn't do anything and traces are
dropped unconditionally.
@mjcheetham
mjcheetham force-pushed the fix-config-same-scope-precedence branch from bce8995 to 4321b4c Compare September 21, 2026 11:21

@mjcheetham mjcheetham 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.

Thank you for finding and fixing this! Sorry for the time it's taken to get around to reviewing this.

@mjcheetham
mjcheetham merged commit f0a78d1 into git-ecosystem:main Sep 21, 2026
3 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