amalgm 0.1.220 → 0.1.221

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "amalgm",
3
- "version": "0.1.220",
3
+ "version": "0.1.221",
4
4
  "description": "Amalgm local computer runtime: login, MCP, chat, events, previews, and tunnels.",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,
@@ -903,6 +903,37 @@ test('the materializer creates, moves, and deletes branch refs without checking
903
903
  assert.equal((await git(repo, 'branch', '--show-current')).trim(), 'main');
904
904
  });
905
905
 
906
+ test('an unpublished local branch delete is not restored while catching up', async () => {
907
+ const { repo, oid } = await makeRepo('pending-branch-delete');
908
+ await git(repo, 'switch', '-c', 'feature');
909
+ fs.writeFileSync(path.join(repo, 'feature.txt'), 'feature\n');
910
+ await git(repo, 'add', '.');
911
+ await git(repo, 'commit', '-m', 'feature');
912
+ const featureOid = (await git(repo, 'rev-parse', 'HEAD')).trim();
913
+ await git(repo, 'switch', 'main');
914
+ await git(repo, 'branch', '-D', 'feature');
915
+
916
+ const localCard = card(repo, oid, 1);
917
+ const plan = {
918
+ repoKey: 'root:pending-branch-delete',
919
+ card: localCard,
920
+ transitions: [],
921
+ parked: [],
922
+ branches: [
923
+ { name: 'main', oid, version: 1 },
924
+ { name: 'feature', oid: featureOid, version: 2 },
925
+ ],
926
+ };
927
+ await materializeRepo(localCard, plan);
928
+ assert.equal((await git(repo, 'rev-parse', 'refs/heads/feature')).trim(), featureOid);
929
+
930
+ await git(repo, 'branch', '-D', 'feature');
931
+ await materializeRepo(localCard, plan);
932
+
933
+ await assert.rejects(() => git(repo, 'rev-parse', 'refs/heads/feature'));
934
+ assert.equal((await git(repo, 'branch', '--show-current')).trim(), 'main');
935
+ });
936
+
906
937
  test('a card branch switch follows branch and OID together and leaves the old branch unchanged', async () => {
907
938
  const { repo, oid: mainOid } = await makeRepo('card-branch-switch');
908
939
  await git(repo, 'checkout', '-b', 'feature');
@@ -427,9 +427,11 @@ async function materializeParked(localCard, entries) {
427
427
  return waiting;
428
428
  }
429
429
 
430
- async function materializeBranches(localCard, plan) {
430
+ async function materializeBranches(localCard, plan, heldBranches = []) {
431
431
  const current = new Map((await localBranches(localCard.path)).map((ref) => [ref.name, ref.oid]));
432
+ const held = new Map(heldBranches.map((ref) => [ref.name, ref.oid]));
432
433
  const waiting = [];
434
+ const pending = [];
433
435
  let moved = false;
434
436
  for (const ref of plan.branches || []) {
435
437
  if (ref.name === plan.card.head?.branch) {
@@ -438,6 +440,12 @@ async function materializeBranches(localCard, plan) {
438
440
  }
439
441
  continue;
440
442
  }
443
+ const currentOid = current.get(ref.name) || null;
444
+ const heldOid = held.get(ref.name) || null;
445
+ if (currentOid !== heldOid && currentOid !== ref.oid) {
446
+ pending.push({ name: ref.name, oid: currentOid });
447
+ continue;
448
+ }
441
449
  if (ref.oid === null) {
442
450
  if (current.has(ref.name)) {
443
451
  await transition.deleteBranchRef(localCard.path, ref.name);
@@ -468,7 +476,7 @@ async function materializeBranches(localCard, plan) {
468
476
  moved = true;
469
477
  }
470
478
  }
471
- return { moved, waiting };
479
+ return { moved, waiting, pending };
472
480
  }
473
481
 
474
482
  async function reduceCheckpoint(localCard, plan) {
@@ -599,7 +607,7 @@ async function materializeRepo(localCardInput, plan, appliedThrough = null) {
599
607
  if (requiredParkedWaiting.length > 0) {
600
608
  return { state: 'waiting', reason: `parked-${requiredParkedWaiting[0].state}` };
601
609
  }
602
- const branchResult = await materializeBranches(localCard, plan);
610
+ const branchResult = await materializeBranches(localCard, plan, previous?.branches);
603
611
  const reduced = await reduceCheckpoint(localCard, plan);
604
612
  if (reduced.state !== 'ready') return reduced;
605
613
 
@@ -702,6 +710,7 @@ async function materializeRepo(localCardInput, plan, appliedThrough = null) {
702
710
  worktreeDiff: stateWorktreeDiff,
703
711
  checkpointVersions: plan.transitions.map((entry) => entry.version),
704
712
  branches: plan.branches || [],
713
+ pendingRefs: branchResult.pending,
705
714
  heldTree: applied.heldTree,
706
715
  heldIndexTree: targetIndex,
707
716
  parked,