protected function parseFileDiff(\Arbit\VCSWrapper\Diff\Collection $diff, array $lines)
    {
        $chunks = array();
        while (count($lines)) {
            // Skip lines until we hit a range specification
            while (!preg_match('(^@@\\s+-(?P<start>\\d+)(?:,\\s*(?P<startrange>\\d+))?\\s+\\+(?P<end>\\d+)(?:,\\s*(?P<endrange>\\d+))?\\s+@@)', $last = array_shift($lines), $match)) {
                // If we reached the end, break
                if ($last === null) {
                    break 2;
                }
            }

            $chunk = new \Arbit\VCSWrapper\Diff\Chunk(
                $match['start'],
                (isset($match['startrange']) ? max(1, $match['startrange']) : 1),
                $match['end'],
                (isset($match['endrange']) ? max(1, $match['endrange']) : 1)
            );

            // Read following diff lines
            $diffLines = array();
            $last      = null;
            while (count($lines) &&
                    (preg_match('(^(?P<type>[+ -])(?P<line>.*))', $last = array_shift($lines), $match) ||
                      (strpos($last, '\\ No newline at end of file') === 0)))
            {
                // We ignore the missing newlines for now
                if (count($match)) {
                    $diffLines[] = new \Arbit\VCSWrapper\Diff\Line(
                        ($match['type'] === '+' ? \Arbit\VCSWrapper\Diff\Line::ADDED :
                            ($match['type'] === '-' ? \Arbit\VCSWrapper\Diff\Line::REMOVED : \Arbit\VCSWrapper\Diff\Line::UNCHANGED)),
                        $match['line']
                    );
                }
            }
            $chunk->lines = $diffLines;
            $chunks[]     = $chunk;

            // Repreprend last not matching line
            if ($last !== null) {
                array_unshift($lines, $last);
            }
        }

        $diff->chunks = $chunks;
    }