private GitConfigFile() { m_config = new Lazy <Dictionary <string, GitConfigValue> >(() => { var config = new Dictionary <string, GitConfigValue>( StringComparer.InvariantCultureIgnoreCase); // Bug: `git config -l --local` inexplicably fails when both // (1) called via git filter and when (2) working dir explictly set string workingDir = null; // = WorkingDir; var sr = GitCmd.Execute(RefreshCommand, workingDir); foreach (var line in sr.Lines()) { var match = Regex.Match(line, ConfigRegex, RegexOptions.IgnoreCase); var key = match.Groups[ConfigRegexName].Value; var value = match.Groups[ConfigRegexValue].Value; config[key] = new GitConfigValue(this, key, value); } return(config); }); }
public static IEnumerable <GitFile> Load( string filter = null, string dir = null, GitFileFlags flags = GitFileFlags.All) { if (dir == null) { dir = Environment.CurrentDirectory; } dir = IOPath.GetFullPath(dir.ToDir()); // tracked, untracked files var lsFilesCommand = $"ls-files {filter}"; if ((flags & GitFileFlags.Tracked) != 0) { lsFilesCommand += " -c"; } if ((flags & GitFileFlags.Untracked) != 0) { lsFilesCommand += " -o"; } // ls-files | check-attr var stream = GitCmd.Stream(lsFilesCommand, dir) .PipeTo(GitCmd.Exe, "check-attr -a --stdin", dir); // parse output Uri currentPath = null; Dictionary <string, string> attributes = null; var dirUrl = dir.ToUrl(); foreach (var line in new StreamReader(stream).Lines()) { var match = Regex.Match(line, AttributeRegex, RegexOptions.IgnoreCase); var path = match.Get(PatternPath); var key = match.Get(PatternName); var value = match.Get(PatternValue); var thisPath = new Uri(dirUrl, path); if (string.IsNullOrEmpty(value)) { value = null; } if (currentPath != thisPath) { if (currentPath != null) { yield return(new GitFile( currentPath.LocalPath, flags, attributes)); } currentPath = thisPath; attributes = new Dictionary <string, string>( StringComparer.InvariantCultureIgnoreCase); } attributes[key] = value; } if (currentPath != null) { yield return(new GitFile( currentPath.LocalPath, flags, attributes)); } }