Skip to content

feat: parse git config files - #129

Open
podikoglou wants to merge 2 commits into
mainfrom
feat/config
Open

podikoglou wants to merge 2 commits into
mainfrom
feat/config

Conversation

@podikoglou

@podikoglou podikoglou commented Nov 19, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds tinygit::config, a parser for a single git config file. Config implements Decode, and the parsers are winnow combinators over parsing::Stream.

let config = repo.config()?;                       // reads .git/config; or Config::open(path)
config.get("core", None, "bare");                  // Option<Option<&str>>: None = missing, Some(None) = bare key
config.get_all("remote", Some("origin"), "fetch"); // every value, in file order
config.subsections("remote");                      // distinct subsection names, first-seen order

The model keeps file order: Config { sections: Vec<Section> }, Section { name, subsection: Option<String>, entries }, Entry { key, value: Option<String> }.

  • Section and key names are matched case-insensitively and subsection names case-sensitively.
  • get returns the last value.

Supported syntax:

  • headers: [section], [section "sub"] (backslash escapes) and legacy [section.sub]
  • # / ; comments, full-line and trailing
  • quoted values; \n \t \b \\ \" escapes
  • backslash line continuations, CRLF, UTF-8 BOM
  • an entry on the same line as its header

Not supported: include/includeIf, writing, value type coercion, global/system config layering, and non-UTF-8 values.

Tests:

  • insta snapshots for the section and entry parsers.
  • configs_match in tests/libgit2.rs compares parsed values with git2::Config on edge-case files and on the fixture repos' configs.
  • A bolero test checks that arbitrary bytes never panic.
  • Repo::config tests in tests/repo.rs.

Product Engineer opened this PR for Alex
Implemented in session Finish git config parser in tinygit
Review with Devin · Open in Devin Desktop


@devin-ai-integration

Copy link
Copy Markdown

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration devin-ai-integration Bot 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.

Note

Newer findings are available below. Devin Review posted a newer report on this PR, in addition to the findings presented here.

Devin Review found 5 findings. Devin fixed 3 findings; 2 findings are left for you to triage below.

Fixed by Devin (3)
  • Remote queries select the wrong URL — Remote now exposes all url/pushurl values in file order (urls, push_urls), matching git's model.
  • Valid escaped subsection names are rejected — Quoted subsections now drop the backslash before any character, verified against libgit2.
  • Continuation trimming removes significant spaces — Spaces before a continuation are preserved; libgit2 differential case added.

View findings in Devin Review · Follow Devin's work

Devin Review

Comment thread src/config.rs
alt((
quoted_value.map(|v| (v, false)),
escape.map(|v| (v, false)),
continuation.map(|v| (v, false)),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Whitespace-only continued values retain spaces

For whitespace-only values split across multiple continued lines, value returns spaces instead of Git's empty string. Each continuation stops trimming, even when all earlier fragments contain only whitespace.

Devin left this for you to triage: Same choice as the leading-whitespace finding: our output matches libgit2 for whitespace-only continued values (" " with two continuations). Recommend following libgit2 unless git CLI parity is preferred.

Learn more

A continuation produces an empty byte vector. Marking it as non-unquoted makes the reverse trimming loop stop there unconditionally. With two continuations separated only by indentation, the second continuation protects that indentation even though the value contains no content. Git parses the same configuration as an empty string.

Example: The configuration represented by the Rust string "[core]\nx = \\\n \\\n\n" produces " " from get("core", None, "x"), rather than Git's "".

Recommended fix: Track whether meaningful value content precedes a continuation before treating it as a whitespace-preservation boundary. Preserve spaces before continuations following actual content, including the existing a regression cases. Add a differential test for whitespace-only values containing multiple continuations.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment thread src/config.rs
Comment on lines +205 to +208
b'"'.context(StrContext::Expected(StrContextValue::CharLiteral('"'))),
)
.context(StrContext::Label("quoted value"))
.parse_next(input)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Leading whitespace survives continued values

For an indented value beginning after a continuation, value retains whitespace that Git discards. Leading empty quotes cause the same failure because whitespace removal runs only before parsing fragments. Continued fetch refspecs acquire an invalid whitespace prefix.

Devin left this for you to triage: We match libgit2, which the suite uses as its oracle: leading spaces after a continuation or after a leading "" are kept. Git CLI drops them (git config --list gives abc). Recommend keeping libgit2 behaviour unless you want to match git CLI instead.

Learn more

Git discards unquoted leading spaces until the decoded value contains content, including after an initial line continuation or an empty quoted fragment. The parser calls space0 only once, so later leading spaces become ordinary value bytes. This affects both configuration queries and the fetch refspecs returned by remote queries.

Example: A configuration containing fetch = \\ followed by a newline and +refs/heads/*:refs/remotes/origin/* must decode without the two leading spaces. Likewise, x = "" status decodes to status in Git, but this parser returns status.

Recommended fix: Track whether decoded value content has started and discard unquoted leading whitespace across fragments and continuations. Preserve whitespace inside nonempty quoted values. Add differential cases for initial continuations and empty quoted fragments.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration devin-ai-integration Bot changed the title feat: parse git config files and query remotes feat: parse git config files Nov 20, 2026

@devin-ai-integration devin-ai-integration Bot 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.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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.

1 participant