diff options
author | Dan Davison <dandavison7@gmail.com> | 2021-04-24 10:13:44 -0400 |
---|---|---|
committer | Dan Davison <dandavison7@gmail.com> | 2021-04-24 10:13:44 -0400 |
commit | 567bdf6775bce0f9b7ab6fc12cc319927aca12e2 (patch) | |
tree | 1beacef990820126d97cfcea14e7e89b871931a2 /src | |
parent | 86a7a6a713b4b8e11510b2c27d26a3129865aa42 (diff) |
Support new GIT_CONFIG_PARAMETERS env var format
https://github.com/git/git/blob/311531c9de557d25ac087c1637818bd2aad6eb3a/Documentation/RelNotes/2.31.0.txt#L127-L130
Diffstat (limited to 'src')
-rw-r--r-- | src/git_config/mod.rs | 24 |
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() } |