public static GitChange Parse(string s, string gitDirectory) { try { var result = new GitChange { FullString = s }; var infos = s.Split('|'); result.FileName = infos[0].Trim(); result.FileInfo = new FileInfo(Path.Combine(gitDirectory, result.FileName)); result.Changes = int.Parse(infos[1].Trim().Split(' ')[0].Trim()); result.Added = Regex.Matches(infos[1], Regex.Escape("+")).Count; result.Removed = Regex.Matches(infos[1], Regex.Escape("-")).Count; return(result); } catch { return(null); } }
public static GitStashInfo ParseFromCmdResult(string s, string gitDirectory) { try { var result = new GitStashInfo { FullString = s }; var lines = Regex.Split(s, @"\r?\n|\r").Where(s1 => !string.IsNullOrWhiteSpace(s1)).ToArray(); result.Changes = lines.Where(s1 => s1.Contains("|")).Select(s1 => GitChange.Parse(s1, gitDirectory)).ToArray(); result.StatusText = lines.Last(); var infos = result.StatusText.Split(','); result.FileChanges = int.Parse(infos[0].Trim().Split(' ')[0].Trim()); result.Insertions = int.Parse(infos[1].Trim().Split(' ')[0].Trim()); result.Deletions = int.Parse(infos[2].Trim().Split(' ')[0].Trim()); return(result); } catch { return(null); } }