sendReleases

tcmts.cli.sync.sendReleases · #7aqp5y2m · term · runs anywhere

Send the releases the remote lacks, with their history. A release both have must be the same.

import type { Codebase } from "#codebase/tcmts/cli/codebase";
import { differ, releaseKey, sendHistory } from "#codebase/tcmts/cli/sync";
import type { Remote } from "#codebase/tcmts/cli/sync";
import type { Release } from "#codebase/tcmts/store";

export async function sendReleases(cb: Codebase, remote: Remote): Promise<string[]> {
  const theirs = new Map((await remote.releases()).map((r) => [releaseKey(r), r]));
  const missing: Release[] = [];
  for (const r of cb.store.releases()) {
    const t = theirs.get(releaseKey(r));
    if (t && (t.causal !== r.causal || t.notes !== r.notes)) throw differ(remote, t, r);
    if (!t) missing.push(r);
  }
  for (const r of missing) await sendHistory(cb, remote, r.causal);
  if (missing.length) await remote.putReleases(missing);
  return missing.map(releaseKey).reverse();
}

uses

used by