private async function genSubmodules()

in src/shipit/repo/ShipItRepoGIT.php [589:630]


  private async function genSubmodules(
    ?keyset<string> $roots = null,
  ): Awaitable<vec<self::TSubmoduleSpec>> {
    // The gitmodules file is in the repo root, so if this application is for
    // a set of source roots that does not contain the entire repository then
    // there are no relevant submodules.
    if ($roots !== null && !C\is_empty($roots) && !C\contains($roots, '')) {
      return vec[];
    }
    if (!PHP\file_exists($this->getPath().'/.gitmodules')) {
      return vec[];
    }
    $configs =
      await $this->genGitCommand('config', '-f', '.gitmodules', '--list');
    $configs = dict(PHP\parse_ini_string($configs) as KeyedContainer<_, _>)
      |> Dict\filter_keys($$, ($key) ==> {
        return Str\slice($key as string, 0, 10) === 'submodule.' &&
          (
            Str\slice($key as string, -5) === '.path' ||
            Str\slice($key as string, -4) === '.url'
          );
      });
    return Vec\keys($configs)
      |> Vec\filter($$, $key ==> Str\slice($key as string, -4) === '.url')
      |> Vec\map(
        $$,
        $key ==>
          Str\slice($key as string, 10, Str\length($key as string) - 10 - 4),
      )
      |> Vec\map(
        $$,
        $name ==> shape(
          'name' => $name,
          'path' => $configs['submodule.'.$name.'.path'] as string,
          'url' => $configs['submodule.'.$name.'.url'] as string,
        ),
      )
      |> Vec\filter(
        $$,
        $config ==> PHP\file_exists($this->getPath().'/'.($config['path'])),
      );
  }