public static function parseDiffHunk()

in src/shipit/repo/ShipItRepo.php [100:126]


  public static function parseDiffHunk(string $hunk): ?ShipItDiff {
    list($header, $body) = Str\split($hunk, "\n", 2);
    $matches = Regex\first_match(
      Str\trim($header),
      re'@^diff --git ("?)[ab]/(.*?)"? "?[ab]/(.*?)"?$@',
    );
    if ($matches is null) {
      return null;
    }
    $path = $matches[2] as string;
    $new_path = $matches[3] !== '' ? $matches[3] : null;
    if ($new_path !== null && $path !== $new_path) {
      $operation = ShipItDiffOperation::RENAME;
    } else {
      $operation = ShipItDiffOperation::CHANGE;
    }
    if ($matches[1] === '"') {
      // Quoted paths may contain escaped characters.
      $path = PHP\stripslashes($path);
    }
    return shape(
      'path' => $path,
      'body' => $body,
      'operation' => $operation,
      'new_path' => $new_path,
    );
  }