protected override bool ProcessLine(string line, out GitStatus result) { result = default; if (line == null) { ReturnStatus(); } else { Prepare(); var proc = new LineParser(line); if (gitStatus.LocalBranch == null) { if (proc.Matches("##")) { proc.MoveToAfter('#'); proc.SkipWhitespace(); string branchesString; if (proc.Matches(branchTrackedAndDelta)) { //master...origin/master [ahead 1] //master...origin/master [behind 1] //master...origin/master [ahead 1, behind 1] branchesString = proc.ReadUntilWhitespace(); proc.MoveToAfter('['); var deltaString = proc.ReadUntil(']'); var deltas = deltaString.Split(new[] { ", " }, StringSplitOptions.RemoveEmptyEntries); foreach (var delta in deltas) { var deltaComponents = delta.Split(' '); if (deltaComponents[0] == "ahead") { gitStatus.ahead = Int32.Parse(deltaComponents[1]); } else if (deltaComponents[0] == "behind") { gitStatus.behind = Int32.Parse(deltaComponents[1]); } else if (deltaComponents[0] == "gone") { } else { throw new InvalidOperationException("Unexpected deltaComponent in o"); } } } else { branchesString = proc.ReadToEnd(); } var branches = branchesString.Split(new[] { "..." }, StringSplitOptions.RemoveEmptyEntries); gitStatus.localBranch = branches[0]; if (branches.Length == 2) { gitStatus.remoteBranch = branches[1]; } } else { HandleUnexpected(line); } } else { var gitStatusMarker = proc.Read(2); if (gitStatusMarker == null) { HandleUnexpected(line); return(false); } /* * X Y Meaning * ------------------------------------------------- * [AMD] not updated * M [ MD] updated in index * A [ MD] added to index * D deleted from index * R [ MD] renamed in index * C [ MD] copied in index * [MARC] index and work tree matches * [ MARC] M work tree changed since index * [ MARC] D deleted in work tree * [ D] R renamed in work tree * [ D] C copied in work tree * ------------------------------------------------- * D D unmerged, both deleted * A A unmerged, both added * A U unmerged, added by us * D U unmerged, deleted by us * U A unmerged, added by them * U D unmerged, deleted by them * U U unmerged, both modified * ------------------------------------------------- * ? ? untracked * ! ! ignored * ------------------------------------------------- */ string originalPath = null; string path = null; var indexStatusMarker = gitStatusMarker[0]; var workTreeStatusMarker = gitStatusMarker[1]; GitFileStatus indexStatus = GitStatusEntry.ParseStatusMarker(indexStatusMarker); GitFileStatus workTreeStatus = GitStatusEntry.ParseStatusMarker(workTreeStatusMarker); GitFileStatus status = workTreeStatus != GitFileStatus.None ? workTreeStatus : indexStatus; if (status == GitFileStatus.None) { HandleUnexpected(line); return(false); } if (status == GitFileStatus.Copied || status == GitFileStatus.Renamed) { var files = proc.ReadToEnd() .Split(new[] { "->" }, StringSplitOptions.RemoveEmptyEntries) .Select(s => s.Trim()) .Select(s => s.Trim('"')) .ToArray(); originalPath = files[0]; path = files[1]; } else { path = proc.ReadToEnd().Trim().Trim('"'); } var gitStatusEntry = gitObjectFactory.CreateGitStatusEntry(path, indexStatus, workTreeStatus, originalPath); gitStatus.Entries.Add(gitStatusEntry); } } return(false); }