chooseReset

tcmts.cli.main.chooseReset · #ftkqbb3s · term · runs anywhere

tcm reset with no entry: which command to undo (it, and everything after it).

import type { Codebase } from "#codebase/tcmts/cli/codebase";
import { choose, UsageError } from "#codebase/tcmts/cli/ui";
import { shortHash } from "#codebase/tcmts/core/hash";
import { entryTitle } from "#codebase/tcmts/store";

export function chooseReset(cb: Codebase): Promise<string> {
  const entries = cb.store.causalLog(100).filter((c) => c.parents.length);
  if (!entries.length) throw new UsageError("nothing to undo on this branch");
  return choose(
    "reset <n|#hash>",
    "Undo back to before which command? (it, and everything after it)",
    entries.map((c) => ({
      value: `#${c.parents[0]!}`,
      label: c.message ? entryTitle(c) : `tcm ${c.command}`,
      hint: `${shortHash(c.hash)}, ${new Date(c.ts).toISOString().replace("T", " ").slice(0, 16)}`,
    })),
    false,
  );
}

uses

used by