testMergeOfAChangeBothSidesMadeLeavesNothingStale

tcmts.cli.test.e2e.merge.testMergeOfAChangeBothSidesMadeLeavesNothingStale · #hgdiquo2 · term

Both sides made the same change (a cherry-pick, say), and one side another: a definition each side only re-hashed is ours re-derived, which hashes as theirs did, and what uses it follows it there: nothing is left using a version nothing names.

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 testMergeOfAChangeBothSidesMadeLeavesNothingStale = () => {
  const dir = tempDir("merge same change");
  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 a = () => 1;\nexport const b = () => 10;`);
  update(`import { a, b } from "#codebase/lib";
export const handlers = () => a() + b();
export const dispatch = () => handlers() * 2;`);
  tcm("branch", "feature");
  tcm("branch", "m");
  tcm("switch", "feature");
  update(`export const b = () => 20;`);
  tcm("switch", "m");
  // (a first: the same change first would be the same entry as feature's, and the merge a fast-forward)
  update(`export const a = () => 3;`);
  update(`export const b = () => 20;`);

  tcm("switch", "feature");
  const merged = tcmIn(dir, "merge", "m");
  assert.equal(merged.status, 0, merged.out);
  assert.doesNotMatch(merged.out, /unnamed version|conflict/);
  // m's a (3) and the b both have (20), through handlers
  assert.equal(tcm("run", "lib.dispatch").trim(), "46");
  assert.match(tcm("todo"), /nothing to do/);
}

uses