From 567bdf6775bce0f9b7ab6fc12cc319927aca12e2 Mon Sep 17 00:00:00 2001 From: Dan Davison Date: Sat, 24 Apr 2021 10:13:44 -0400 Subject: Support new GIT_CONFIG_PARAMETERS env var format https://github.com/git/git/blob/311531c9de557d25ac087c1637818bd2aad6eb3a/Documentation/RelNotes/2.31.0.txt#L127-L130 --- src/git_config/mod.rs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/git_config/mod.rs b/src/git_config/mod.rs index cbdab805..1b2ea0a6 100644 --- a/src/git_config/mod.rs +++ b/src/git_config/mod.rs @@ -82,7 +82,11 @@ fn parse_config_from_env_var() -> HashMap { lazy_static! { static ref GIT_CONFIG_PARAMETERS_REGEX: Regex = Regex::new( r"(?x) - '(delta\.[a-z-]+)=([^']+)' + (?: # Non-capturing group containing union + '(delta\.[a-z-]+)=([^']+)' # Git <2.31.0 format + | + '(delta\.[a-z-]+)'='([^']+)' # Git ≥2.31.0 format + ) " ) .unwrap(); @@ -91,7 +95,23 @@ lazy_static! { fn parse_config_from_env_var_value(s: &str) -> HashMap { GIT_CONFIG_PARAMETERS_REGEX .captures_iter(s) - .map(|captures| (captures[1].to_string(), captures[2].to_string())) + .map(|captures| { + let (i, j) = match ( + captures.get(1), + captures.get(2), + captures.get(3), + captures.get(4), + ) { + (Some(_), Some(_), None, None) => (1, 2), + (None, None, Some(_), Some(_)) => (3, 4), + _ => (0, 0), + }; + if (i, j) == (0, 0) { + ("".to_string(), "".to_string()) + } else { + (captures[i].to_string(), captures[j].to_string()) + } + }) .collect() } -- cgit v1.2.3