causalArg

tcmts.cli.main.causalArg · #e2qqbtnb · term · runs on the server

uses tcmts.cli.main.releaseAt, which uses tcmts.cli.manifests.packagesIn, which uses tcmts.cli.config.configValue, which uses node:path

A history entry: a number, how many entries back on this branch (0 is the latest; tcm history shows them), or a hash from any branch's history (a prefix will do; the # is optional, since shells read #… as a comment).

import type { Codebase } from "#codebase/tcmts/cli/codebase";
import { releaseAt } from "#codebase/tcmts/cli/main";
import { UsageError } from "#codebase/tcmts/cli/ui";

export function causalArg(cb: Codebase, ref: string): string {
  if (/^\d+$/.test(ref)) {
    const n = Number(ref);
    const c = cb.store.causalLog(n + 1)[n];
    if (!c) throw new UsageError(`this branch's history isn't ${n} entries long`);
    return c.hash;
  }
  if (/^(@?[^@]+)?@v?\d+\.\d+\.\d+/.test(ref)) return releaseAt(cb, ref).causal;
  const hs = cb.store.causalsWithPrefix(ref.replace(/^#/, ""));
  if (hs.length !== 1) throw new UsageError(hs.length ? `${ref} matches ${hs.length} history entries; give more of the hash` : `no history entry ${ref} (see \`tcm history\`)`);
  return hs[0]!;
}

uses

used by