Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
fix(config): read a git config key with no value as true (#4314)
Worktrunk Bot8423f3c67eaf
diff --git a/src/git/repository/config.rs b/src/git/repository/config.rsindex 015ebedd0..d2d97da6b 100644--- a/src/git/repository/config.rs+++ b/src/git/repository/config.rs@@ -135,8 +135,9 @@ impl Repository {////// `git config --null --get-regexp` emits `key\nvalue\0` records, so values/// containing newlines remain intact. Valueless keys are emitted as- /// `key\0` and represented with an empty value. When a key has multiple- /// values, the last value wins, matching the other config readers.+ /// `key\0` and read as `"true"`, git's boolean reading of them (see+ /// `parse_config_list_z`). When a key has multiple values, the last value+ /// wins, matching the other config readers.pub fn config_regexp_entries(&self, pattern: &str) -> anyhow::Result<Vec<(String, String)>> {let args = ["config", "--null", "--get-regexp", pattern];let output = self.run_command_output(&args)?;diff --git a/src/git/repository/mod.rs b/src/git/repository/mod.rsindex 306775116..cd3f24c44 100644--- a/src/git/repository/mod.rs+++ b/src/git/repository/mod.rs@@ -1799,8 +1799,7 @@ impl Repository {/// a commit meant to match what porcelain would record passes `-S` itself./// Asked of git from this worktree rather than read from the cached config/// map, which is read from the common dir and so misses worktree-scoped- /// config, and whose boolean parsing is not git's (a valueless key is true- /// to git).+ /// config.pub fn signs_commits(&self) -> anyhow::Result<bool> {let args = ["config", "--type=bool", "--get", "commit.gpgSign"];let output = self.run_command_output(&args)?;@@ -2238,8 +2237,10 @@ fn worktree_config_enabled(parsed: &indexmap::IndexMap<String, Vec<String>>) ->/// Parse the output of `git config --list -z`.///-/// Format: each entry is `key\nvalue\0`. Values may be empty (no `\n`) for-/// keys set via `git config key ""` — handled as `key -> ""`.+/// Format: each entry is `key\nvalue\0`. An explicitly empty value+/// (`key = ""`) keeps the newline and parses as `key -> ""`. A key written+/// with no value at all is emitted as bare `key\0`; git reads that as boolean+/// true, so it parses as `key -> "true"`.////// Returns a map from canonical key (as git emits it) to the list of/// values, preserving order (matches git's own multivar semantics where@@ -2253,9 +2254,8 @@ fn parse_config_list_z(stdout: &[u8]) -> indexmap::IndexMap<String, Vec<String>>let text = String::from_utf8_lossy(entry);let (key, value) = match text.split_once('\n') {Some((k, v)) => (k, v),- // `key` without any newline → no value set (shouldn't happen- // with `--list -z`, but tolerate gracefully).- None => (text.as_ref(), ""),+ // A key with no value is git's implicit boolean true.+ None => (text.as_ref(), "true"),};map.entry(key.to_string()).or_default()diff --git a/src/git/repository/tests.rs b/src/git/repository/tests.rsindex b3792126c..88655e8b3 100644--- a/src/git/repository/tests.rs+++ b/src/git/repository/tests.rs@@ -597,17 +597,29 @@ fn parse_config_list_z_empty() {}#[test]-fn parse_config_list_z_entry_without_newline_tolerates_key_only() {- // `git config --list -z` always emits `key\nvalue\0`, but the parser- // tolerates bare `key\0` by mapping it to `key -> ""` rather than- // dropping the entry. Lets a future git oddity be diagnosed at the- // use-site instead of silently missing.- let input = b"core.bare\0other.key\nfalse\0";+fn parse_config_list_z_key_without_value_is_true() {+ // A key written with no `= value` is git's implicit boolean true, and+ // `--list -z` emits it as `key\0` with no newline. An explicitly empty+ // value (`key = ""`) keeps its newline, and git reads that as false.+ let input = b"core.bare\0core.fsmonitor\n\0other.key\nfalse\0";let map = super::parse_config_list_z(input);- assert_eq!(map["core.bare"], vec![""]);+ assert_eq!(map["core.bare"], vec!["true"]);+ assert_eq!(map["core.fsmonitor"], vec![""]);assert_eq!(map["other.key"], vec!["false"]);}+#[test]+fn config_bool_reads_key_without_value_as_true() {+ let test = TestRepo::with_initial_commit();+ let config_path = test.root_path().join(".git/config");+ let mut config = std::fs::read_to_string(&config_path).unwrap();+ config.push_str("[core]\n\tfsmonitor\n");+ std::fs::write(&config_path, config).unwrap();++ let repo = Repository::at(test.root_path()).unwrap();+ assert!(repo.is_builtin_fsmonitor_enabled());+}+#[test]fn canonical_config_key_cases() {// section + variable: both lowercased