private async function genApplyPatchToDestination()

in src/importit/phase/ImportItSyncPhase.php [170:222]


  private async function genApplyPatchToDestination(
    ShipItManifest $manifest,
    ShipItChangeset $changeset,
    ?string $base_rev,
  ): Awaitable<void> {
    $destination_repo = await ImportItRepo::genOpen(
      $manifest->getDestinationSharedLock(),
      $manifest->getDestinationPath(),
      $manifest->getDestinationBranch(),
    );
    if ($base_rev !== null) {
      ShipItLogger::out(
        "  Updating destination branch to new base revision...\n",
      );
      await $destination_repo->genUpdateBranchTo($base_rev);
    }
    invariant(
      $destination_repo is ShipItDestinationRepo,
      'The destination repository must implement ShipItDestinationRepo!',
    );
    ShipItLogger::out("  Filtering...\n");
    $filter_fn = $this->filter;
    $changeset = $filter_fn($changeset);
    if ($manifest->isVerboseEnabled()) {
      $changeset->dumpDebugMessages();
    }
    ShipItLogger::out("  Exporting...\n");
    $this->maybeSavePatch($destination_repo, $changeset);
    try {
      $rev = await $destination_repo->genCommitPatch(
        $changeset,
        $this->shouldDoSubmodules,
      );
      ShipItLogger::out(
        "  Done.  %s committed in %s\n",
        $rev,
        $destination_repo->getPath(),
      );
    } catch (\Exception $e) {
      if ($this->patchesDirectory !== null) {
        ShipItLogger::out(
          "  Failure to apply patch at %s\n",
          $this->getPatchLocationForChangeset($changeset),
        );
      } else {
        ShipItLogger::out(
          "  Failure to apply patch:\n%s\n",
          $destination_repo::renderPatch($changeset),
        );
      }
      throw $e;
    }
  }