summaryrefslogtreecommitdiffstats
path: root/src/git_config/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/git_config/mod.rs')
-rw-r--r--src/git_config/mod.rs24
1 files 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<String, String> {
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<String, String> {
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()
}