summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Davison <dandavison7@gmail.com>2021-04-24 10:13:44 -0400
committerDan Davison <dandavison7@gmail.com>2021-04-24 10:13:44 -0400
commit567bdf6775bce0f9b7ab6fc12cc319927aca12e2 (patch)
tree1beacef990820126d97cfcea14e7e89b871931a2
parent86a7a6a713b4b8e11510b2c27d26a3129865aa42 (diff)
Support new GIT_CONFIG_PARAMETERS env var format
https://github.com/git/git/blob/311531c9de557d25ac087c1637818bd2aad6eb3a/Documentation/RelNotes/2.31.0.txt#L127-L130
-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()
}