testLandingMergesMainIntoTheBranchFirst

tcmts.cli.test.e2e.merge.testLandingMergesMainIntoTheBranchFirst · #5aowtr6e · term

On main, tcm merge <branch> lands it as a session does: main is merged into the branch first, there; where that leaves something to settle, nothing lands and main is untouched (the merge waits on the branch); settled, the branch lands, its tests passing.

import { okIn, tcmIn, tempDir } from "#codebase/tcmts/cli/test/e2e/harness";
import assert from "node:assert/strict";
import fs from "node:fs";
import path from "node:path";

export const testLandingMergesMainIntoTheBranchFirst = () => {
  const dir = tempDir("merge landing");
  const tcm = (...args: string[]) => okIn(dir, ...args);
  const update = (code: string) => {
    fs.writeFileSync(path.join(dir, "scratch.ts"), `// tcm: namespace lib\n${code}\n`);
    tcm("update");
  };
  tcm("init");
  update(
    `export const k = (): number => 1;\nexport const testK = () => { if (k() < 1) throw new Error("k"); };`,
  );
  tcm("branch", "s");
  tcm("switch", "s");
  update(`export const k = (): number => 2;`);
  tcm("switch", "main");
  update(`export const k = (): number => 3;`);
  const main = tcm("history");
  const land = tcmIn(dir, "merge", "s", "--squash", "-m", "Make k two");
  assert.equal(land.status, 1, land.out);
  assert.match(land.out, /nothing landed on main/);
  assert.equal(tcm("history"), main, "main is untouched");
  assert.match(tcm("view", "lib.k"), /=> 3/);
  // the merge waits on s, to settle there
  tcm("switch", "s");
  assert.match(tcm("todo"), /merging main into s/);
  tcm("resolve", "lib.k", "--ours");
  tcm("switch", "main");
  const again = tcmIn(dir, "merge", "s", "--squash", "-m", "Make k two");
  assert.equal(again.status, 0, again.out);
  assert.match(again.out, /testing s/);
  assert.match(tcm("view", "lib.k"), /=> 2/);
  assert.match(tcm("history"), /Make k two/);
}

uses