Skip to content

Fix crash when git branch config has a duplicate key#4

Closed
dennisdoomen wants to merge 1 commit into
mainfrom
fix-duplicate-git-config-keys
Closed

Fix crash when git branch config has a duplicate key#4
dennisdoomen wants to merge 1 commit into
mainfrom
fix-duplicate-git-config-keys

Conversation

@dennisdoomen

Copy link
Copy Markdown
Owner

Fixes a crash in GitRepository.GetRemoteNameAndBranch when the git branch config section contains a duplicate key.

Problem

VS Code's Git extension appends a vscode-merge-base entry to [branch "..."] instead of updating it in place, sometimes leaving it duplicated. Parsing that section built a Dictionary with ToDictionary, which throws:

System.ArgumentException: An item with the same key has already been added. Key: vscode-merge-base

This breaks GitRepository.FromLocalDirectory, and therefore [GitVersion] parameter injection, for any consumer whose .git/config has this duplicate.

Fix

Group config lines by key and take the last value (matches git's own last-value-wins semantics) instead of ToDictionary. Also skip lines without = instead of crashing with IndexOutOfRangeException.

Testing

Added a regression test that reproduces the exact reported exception against a real temp git repo with a duplicated vscode-merge-base line, and confirmed it fails without the fix and passes with it. Ran the full Fallout.Build.Tests suite (only the pre-existing, unrelated FromDirectoryTest worktree limitation fails, confirmed to fail identically on main).

GetRemoteNameAndBranch built a Dictionary from the raw key/value lines of
a [branch "..."] config section with ToDictionary, which throws
ArgumentException on a duplicate key. VS Code's Git extension is known to
append a duplicate vscode-merge-base entry instead of updating it in
place, which crashed FromLocalDirectory (and therefore GitVersionAttribute)
for anyone using it.

Group by key and take the last value instead (matches git's own
last-value-wins semantics), and skip malformed lines without an '='
instead of throwing an IndexOutOfRange.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@dennisdoomen dennisdoomen added bug Something isn't working target/2026 labels Jul 19, 2026
@dennisdoomen

Copy link
Copy Markdown
Owner Author

Reopening against Fallout-build/Fallout instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working target/2026

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant