Skip to content

fix: preserve multiline state variable values - #4272

Merged
max-sixty merged 4 commits into
max-sixty:mainfrom
Duang777:fix/multiline-state-vars
Sep 27, 2026
Merged

max-sixty merged 4 commits into
max-sixty:mainfrom
Duang777:fix/multiline-state-vars

Conversation

@Duang777

Copy link
Copy Markdown
Contributor

Summary

  • read regex-matched git config entries with NUL record delimiters
  • preserve embedded newlines in vars and marker values
  • cover vars get, JSON list, and clear-all with a multiline value

Root cause

git config --get-regexp uses newlines both between records and inside multiline values. Splitting stdout with .lines() truncated each value after its first line. git config --null --get-regexp emits NUL-terminated records, allowing the parser to split each record only at the first key/value newline.

Verification

  • cargo test integration_tests::config_state:: -- --nocapture (143 passed)
  • cargo run -- hook pre-merge --yes (4,968 passed, 1 skipped)

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The NUL-delimited read fixes the truncation. One behavior regression and one leftover are inline.

Two doc comments in src/commands/config/state.rs outside the diff still name the old helper: the one on clear_all_markers ("get_config_regexp returns an empty string when no keys match…") and the one on clear_all_vars ("Enumerates keys via get_config_regexp…"). They should point at config_regexp_entries now.

Comment thread src/git/repository/config.rs Resolved
Comment thread src/git/repository/config.rs Resolved
Address review feedback by preserving key-only records from git config --null output and removing the superseded regexp reader.
Comment thread src/git/repository/config.rs Outdated
/// Each NUL-terminated record contains `key\nvalue` or a valueless `key`.
/// Only the first newline separates the fields; later newlines are part of
/// the value.
fn parse_config_regexp_z(stdout: &[u8]) -> Vec<(String, String)> {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

seems complicated, is this really the simplest approach? to parsing configs?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Switching to --null is the right fix, but the new parser isn't needed. parse_config_regexp_z duplicates parse_config_list_z, which already parses the same key\nvalue\0 records for the git config --list -z snapshot. It has the same split on NUL, the same first-newline split, and the same fallback to "" for a valueless key. git config --null --get-regexp emits that format too, so the simplest version is:

pub fn get_config_regexp(&self, pattern: &str) -> anyhow::Result<IndexMap<String, Vec<String>>> {
    let args = ["config", "--null", "--get-regexp", pattern];
    // ...same exit-1 / error handling...
    Ok(parse_config_list_z(&output.stdout))
}

Callers would iterate (key, values) and take values.last(), which matches Git's last-value-wins rule. The alternative is to move the record splitting into a shared iterator and use it from both places. Either way, the PR ends up with one parser instead of two.

Routing these reads through the in-memory all_config snapshot would be simpler still, but that doesn't work here. Hook and alias pipelines have to see vars writes made by earlier steps' own git config subprocesses (config.rs:181-185), and the clear --all paths need a read error to fail rather than report "cleared 0". A fresh --get-regexp call is still required, and only its parsing changes.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

OK, @Duang777 I'm seeing this sort of thing a lot.

I think I would prefer Issues and then for @worktrunk-bot to do the work: it would be less work from me and probably fewer tokens.

If you have a preference to do the PR, then fine, but please do the work to get this right. you are welcome to ask @worktrunk-bot to review or do things for you; but please have a much higher quality of work; otherwise it's -ev for me to invest time reviewing

thank you

@Duang777

Copy link
Copy Markdown
Contributor Author

Addressed in cd7e83d. config_regexp_entries now reuses the existing parse_config_list_z parser and takes the last value for each key, matching the other config readers. The duplicate parser is gone. The multiline-value and valueless-key CLI regressions still pass, and the Rust 1.97 pre-merge gate passed 4,980 tests with 1 skipped after merging current main.

@max-sixty
max-sixty merged commit d36078e into max-sixty:main Sep 27, 2026
38 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