mirror of
https://github.com/openai/codex.git
synced 2026-09-04 15:08:45 +00:00
git-utils: support older Git boolean ranges
This commit is contained in:
@@ -253,9 +253,14 @@ fn git_env_bool(name: &str) -> io::Result<bool> {
|
||||
"1" | "true" | "yes" | "on" => Ok(true),
|
||||
"" | "0" | "false" | "no" | "off" => Ok(false),
|
||||
value => value
|
||||
.parse::<i32>()
|
||||
.parse::<i64>()
|
||||
.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")),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user