public static async function genVerifyRepo()

in src/shipit/phase/ShipItVerifyRepoPhase.php [96:201]


  public static async function genVerifyRepo(
    shape(
      'manifest' => ShipItManifest,
      'genFilter' => (function(ShipItChangeset): Awaitable<ShipItChangeset>),
      'useLatestSourceCommit' => bool,
      'verifySourceCommit' => ?string,
      'shouldDoSubmodules' => bool,
      'createPatch' => bool,
    ) $args,
  ): Awaitable<shape('diffstat' => string, 'patch' => string)> {
    if ($args['useLatestSourceCommit']) {
      if ($args['verifySourceCommit'] is nonnull) {
        throw new ShipItException(
          "the 'verify-source-commit' flag cannot be used with the ".
          "'use-latest-source-commit' flag since the latter automatically ".
          "sets the verify source commit",
        );
      }
      $repo = await ShipItRepo::genTypedOpen<ShipItDestinationRepo>(
        $args['manifest']->getDestinationSharedLock(),
        $args['manifest']->getDestinationPath(),
        $args['manifest']->getDestinationBranch(),
      );
      invariant(
        $repo is ShipItRepoGIT,
        "This phase only works if the destination is a git repo",
      );
      $args['verifySourceCommit'] = await $repo->genFindLastSourceCommit(
        keyset[],
        $args['manifest']->getCommitMarker(),
      );
    }
    $clean_dir = await ShipItCreateNewRepoPhase::genCreateNewGitRepo(
      $args['manifest'],
      $args['genFilter'],
      static::COMMITTER_INFO,
      $args['shouldDoSubmodules'],
      $args['verifySourceCommit'],
    );
    $clean_path = $clean_dir->getPath();
    $dirty_remote = 'shipit_dest';
    $dirty_ref = $dirty_remote.'/'.$args['manifest']->getDestinationBranch();

    await (
      new ShipItShellCommand(
        $clean_path,
        'git',
        'remote',
        'add',
        $dirty_remote,
        $args['manifest']->getDestinationPath(),
      )
    )->genRun();
    await (
      new ShipItShellCommand($clean_path, 'git', 'fetch', $dirty_remote)
    )->genRun();

    $diffstat = (
      await (
        new ShipItShellCommand(
          $clean_path,
          'git',
          'diff',
          '--stat',
          $dirty_ref,
          'HEAD',
        )
      )->genRun()
    )->getStdOut();

    if ($diffstat === '') {
      if ($args['createPatch']) {
        ShipItLogger::err(
          "  CREATE PATCH FAILED: destination is already in sync.\n",
        );
        throw new ShipItExitException(1);
      }
      ShipItLogger::out("  Verification OK: destination is in sync.\n");
      throw new ShipItExitException(0);
    }

    if (!$args['createPatch']) {
      ShipItLogger::err(
        "  VERIFICATION FAILED: destination repo does not match:\n\n%s\n",
        $diffstat,
      );
      throw new ShipItExitException(1);
    }

    $patch = (
      await (
        new ShipItShellCommand(
          $clean_path,
          'git',
          'diff',
          '--full-index',
          '--binary',
          '--no-color',
          $dirty_ref,
          'HEAD',
        )
      )->genRun()
    )->getStdOut();

    return shape('diffstat' => $diffstat, 'patch' => $patch);
  }