public async function genExport()

in src/shipit/repo/ShipItRepoGIT.php [528:582]


  public async function genExport(
    keyset<string> $roots,
    bool $do_submodules,
    ?string $rev = null,
  ): Awaitable<shape('tempDir' => ShipItTempDir, 'revision' => string)> {
    if ($rev === null) {
      $rev = Str\trim(await $this->genGitCommand('rev-parse', 'HEAD'));
    }

    $dest = new ShipItTempDir('git-export');
    $archive_name = Str\format('%s/archive', $dest->getPath());

    $command = vec[
      'archive',
      '--format=tar',
      '--output',
      $archive_name,
      $rev,
    ];
    $command = Vec\concat($command, $roots);
    await $this->genGitCommand(...$command);

    await (new ShipItShellCommand($dest->getPath(), 'tar', 'xf', $archive_name))
      ->genRun();

    await (new ShipItShellCommand($this->path, 'rm', $archive_name))->genRun();

    if ($do_submodules) {
      $submodules = await $this->genSubmodules($roots);
    } else {
      $submodules = vec[];
    }
    // If we have any submodules, we'll need to set them up manually.
    foreach ($submodules as $submodule) {
      // @lint-ignore AWAIT_IN_LOOP We need to do this serially
      $status = await $this->genGitCommand(
        'submodule',
        'status',
        $submodule['path'],
      );
      $sha = $status
        // Strip any -, +, or U at the start of the status (see the man page for
        // git-submodule).
        |> Regex\replace($$, re"@^[\-\+U]@", '')
        |> Str\split($$, ' ')[0];
      $dest_submodule_path = $dest->getPath().'/'.$submodule['path'];
      // This removes the empty directory for the submodule that gets created
      // by the git-archive command.
      PHP\rmdir($dest_submodule_path);
      // This will setup a file that looks just like how git stores submodules.
      PHP\file_put_contents($dest_submodule_path, 'Subproject commit '.$sha);
    }

    return shape('tempDir' => $dest, 'revision' => $rev);
  }