git-ecosystem/git-credential-manager · error · Trace2Exception

Failed to get Git configuration multi-valued entries with…

Error message

Failed to get Git configuration multi-valued entries with name regex '{nameRegex}'

What it means

Thrown when `git config --get-regexp` (multivar name/value regex query) exits with a code other than 0 or 1. Exit 1 (no matches) is tolerated; this error means git rejected the query — almost always an invalid regex or invalid key-name pattern — or the config itself is unreadable.

Solutions

  1. Test the exact regexes with `git config --get-regexp <nameRegex>` to see git's complaint
  2. Fix the regex syntax (git uses POSIX basic/extended regex, not .NET flavor)
  3. Escape dots in key names ('remote\\.origin') and validate parentheses/escapes
  4. Wrap the call in try/catch and fall back to Enumerate + client-side filtering

Example fix

// before
config.GetRegex(level, type, "remote.*url", "("); // throws: invalid regex
// after
config.GetRegex(level, type, "remote\\..*\\.url", "https://.*"); // valid POSIX regex
Defensive patterns

Strategy: try-catch

Validate before calling

static bool IsValidPosixRegex(string pattern) {
    try { _ = new System.Text.RegularExpressions.Regex(pattern); return pattern.IndexOf('(') == pattern.LastIndexOf(')'); }
    catch (ArgumentException) { return false; }
}
// also escape dots: name.Replace(".", "\\.")

Try / catch

try { matches = cfg.GetRegex(level, type, nameRegex, valueRegex).ToList(); }
catch (GitException ex) { log.Warn($"Regex query failed: {ex.Message}"); matches = new List<string>(); }

Prevention

When it happens

Trigger: Calling GetRegex(level, type, nameRegex, valueRegex) with a name or value regex that git/.NET-compiled-to-git treats as invalid, or when the underlying config cannot be parsed.

Common situations: Passing regexes with unbalanced parentheses or invalid escapes ('remote\\.origin\\' etc.); copying a .NET regex flavor git's POSIX regex engine does not support; querying a corrupted config.

Related errors


AI-assisted analysis of git-ecosystem/git-credential-manager@e8ce762cd0 (2026-09-11). Data as JSON: /api/errors/872d2f504ec4223f. Report an issue: GitHub.

Appendix: source

Thrown at src/Core/GitConfiguration.cs:729

                gitArgs += $" {QuoteCmdArg(valueRegex)}";
            }

            using (ChildProcess git = _git.CreateProcess(gitArgs))
            {
                git.Start(Trace2ProcessClass.Git);
                // To avoid deadlocks, always read the output stream first and then wait
                // TODO: don't read in all the data at once; stream it
                string data = git.StandardOutput.ReadToEnd();
                git.WaitForExit();

                switch (git.ExitCode)
                {
                    case 0: // OK
                    case 1: // No results
                        break;
                    default:
                        _trace.WriteLine($"Failed to get all multivar regex '{nameRegex}' and value regex '{valueRegex}' (exit={git.ExitCode}, level={level})");
                        throw GitProcess.CreateGitException(git, $"Failed to get Git configuration multi-valued entries with name regex '{nameRegex}'");
                }

                string[] entries = data.Split('\0');
                foreach (string entry in entries)
                {
                    string[] kvp = entry.Split(new[]{'\n'}, count: 2);

                    if (kvp.Length == 2)
                    {
                        yield return kvp[1];
                    }
                }
            }
        }

        public void ReplaceAll(GitConfigurationLevel level, string name, string valueRegex, string value)
        {
            EnsureSpecificLevel(level);

View on GitHub (pinned to e8ce762cd0)