From f7e605110f09df74a30f87a610c67c807d6793d3 Mon Sep 17 00:00:00 2001 From: Mahendra Singh Rathore <49229348+mahendrarathore1742@users.noreply.github.com> Date: Mon, 9 Mar 2026 10:56:58 +0000 Subject: [PATCH] fix(isl): handle missing commits in dag sortAsc during drag-and-drop (#1229) When dragging and dropping commits for rebase, the preview DAG may contain commits not present in the defaultSortAscIndex. The sortAsc method threw 'not in the dag' error instead of gracefully handling missing hashes. Fix: filter out hashes not present in the index before sorting, consistent with base_dag.ts sortImpl which calls this.present(set) before processing. Fixes #1229 --- addons/isl/src/dag/dag.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/addons/isl/src/dag/dag.ts b/addons/isl/src/dag/dag.ts index 92397fce20c6d..f4d001ca978d6 100644 --- a/addons/isl/src/dag/dag.ts +++ b/addons/isl/src/dag/dag.ts @@ -274,12 +274,13 @@ export class Dag extends SelfUpdate { return [...sorted]; } const hashes = arrayFromHashes(set === undefined ? this.all() : set); - return hashes.sort((a, b) => { - const aIdx = index.get(a); - const bIdx = index.get(b); - if (aIdx == null || bIdx == null) { - throw new Error(`Commit ${a} or ${b} is not in the dag.`); - } + // Filter out hashes not present in the dag to avoid errors when the set + // contains commits that are not in the dag (e.g. during drag-and-drop + // rebase previews where commits may reference hashes not yet in the dag). + const presentHashes = hashes.filter(h => index.has(h)); + return presentHashes.sort((a, b) => { + const aIdx = index.get(a) as number; + const bIdx = index.get(b) as number; return aIdx - bIdx; }); }