sideHash

tcmts.cli.merge.sideHash · #qm36xq2u · term · runs anywhere

The #hash of the definition one side of a merge gave a conflicted name, as it is now (tcm resolve --ours): a hash copied earlier can be stale, as resolving another conflict re-derives what used it.

import type { Codebase } from "#codebase/tcmts/cli/codebase";
import { conflictAt } from "#codebase/tcmts/cli/merge";
import { UsageError } from "#codebase/tcmts/cli/ui";

export function sideHash(cb: Codebase, name: string, side: "ours" | "theirs"): string {
  const c = conflictAt(cb, name);
  if (!c) throw new UsageError(`${name} isn't conflicted (\`tcm todo\` lists what is)`);
  const hs = c.sides.filter((s) => s.side === side);
  if (hs.length !== 1)
    throw new UsageError(
      hs.length
        ? `${hs.length} of ${name}'s definitions are ${side}: give the #hash to keep`
        : `which of ${name}'s definitions is ${side} isn't known (it wasn't conflicted by a merge on this branch): give the #hash to keep (\`tcm todo\` lists them)`,
    );
  return `#${hs[0]!.hash}`;
}

uses

used by