From 5632dfd765113cdbcec5ac32136cf9766940b1cf Mon Sep 17 00:00:00 2001 From: Chris Bookholt Date: Thu, 2 Jul 2026 01:01:44 -0700 Subject: [PATCH] git-utils: support older Git boolean ranges --- .../git-utils/src/git_config_sources/primary_sources.rs | 9 +++++++-- codex-rs/git-utils/src/git_config_sources_tests.rs | 8 +++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/codex-rs/git-utils/src/git_config_sources/primary_sources.rs b/codex-rs/git-utils/src/git_config_sources/primary_sources.rs index 252e09314e..2693bb943d 100644 --- a/codex-rs/git-utils/src/git_config_sources/primary_sources.rs +++ b/codex-rs/git-utils/src/git_config_sources/primary_sources.rs @@ -253,9 +253,14 @@ fn git_env_bool(name: &str) -> io::Result { "1" | "true" | "yes" | "on" => Ok(true), "" | "0" | "false" | "no" | "off" => Ok(false), value => value - .parse::() + .parse::() + .ok() + // Supported Git releases disagree on whether INT_MIN is a valid + // numeric boolean. Accept only their shared symmetric range so a + // value approved here cannot make the selected Git fail later. + .filter(|value| (-i64::from(i32::MAX)..=i64::from(i32::MAX)).contains(value)) .map(|value| value != 0) - .map_err(|_| invalid_config_source("invalid Git boolean environment value")), + .ok_or_else(|| invalid_config_source("invalid Git boolean environment value")), } } diff --git a/codex-rs/git-utils/src/git_config_sources_tests.rs b/codex-rs/git-utils/src/git_config_sources_tests.rs index c86ae4bb26..8c12a1efbe 100644 --- a/codex-rs/git-utils/src/git_config_sources_tests.rs +++ b/codex-rs/git-utils/src/git_config_sources_tests.rs @@ -397,8 +397,9 @@ fn rejects_worktree_fifo_primary_source_without_opening_it() { } #[test] -fn git_config_nosystem_matches_git_integer_and_text_boolean_grammar() { - const TEST_NAME: &str = "git_config_sources::tests::git_config_nosystem_matches_git_integer_and_text_boolean_grammar"; +fn git_config_nosystem_accepts_cross_version_boolean_values() { + const TEST_NAME: &str = + "git_config_sources::tests::git_config_nosystem_accepts_cross_version_boolean_values"; if std::env::var_os("CODEX_GIT_CONFIG_SOURCE_CHILD").is_none() { let repo = init_repo(); let unsafe_system = repo.path().join("system.gitconfig"); @@ -410,7 +411,7 @@ fn git_config_nosystem_matches_git_integer_and_text_boolean_grammar() { ("01", "ignored"), ("+1", "ignored"), ("2147483647", "ignored"), - ("-2147483648", "ignored"), + ("-2147483647", "ignored"), ("true", "ignored"), ("yes", "ignored"), ("on", "ignored"), @@ -422,6 +423,7 @@ fn git_config_nosystem_matches_git_integer_and_text_boolean_grammar() { ("off", "rejected"), ("not-a-bool", "invalid"), ("2147483648", "invalid"), + ("-2147483648", "invalid"), ("-2147483649", "invalid"), ] { run_isolated_source_test(