Repository navigation
feat: parse git config files - #129
podikoglou wants to merge 2 commits into
Conversation
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
There was a problem hiding this comment.
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/pushurlvalues 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.
| alt(( | ||
| quoted_value.map(|v| (v, false)), | ||
| escape.map(|v| (v, false)), | ||
| continuation.map(|v| (v, false)), |
There was a problem hiding this comment.
🟡 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.
Was this helpful? React with 👍 or 👎 to provide feedback.
| b'"'.context(StrContext::Expected(StrContextValue::CharLiteral('"'))), | ||
| ) | ||
| .context(StrContext::Label("quoted value")) | ||
| .parse_next(input) |
There was a problem hiding this comment.
🟡 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.
Was this helpful? React with 👍 or 👎 to provide feedback.
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
cf96811 to
ab66e72
Compare
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Summary
Adds
tinygit::config, a parser for a single git config file.ConfigimplementsDecode, and the parsers are winnow combinators overparsing::Stream.The model keeps file order:
Config { sections: Vec<Section> },Section { name, subsection: Option<String>, entries },Entry { key, value: Option<String> }.getreturns the last value.Supported syntax:
[section],[section "sub"](backslash escapes) and legacy[section.sub]#/;comments, full-line and trailing\n \t \b \\ \"escapesNot supported:
include/includeIf, writing, value type coercion, global/system config layering, and non-UTF-8 values.Tests:
configs_matchintests/libgit2.rscompares parsed values withgit2::Configon edge-case files and on the fixture repos' configs.Repo::configtests intests/repo.rs.Implemented in session Finish git config parser in tinygit
Review with Devin · Open in Devin Desktop