@teambit/snapping 1.0.929 → 1.0.931

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.
@@ -12,6 +12,8 @@ export type ResetResult = {
12
12
  * we want .bitmap to have the version before the detachment. not as the head.
13
13
  */
14
14
  versionToSetInBitmap?: string;
15
+ /** batchIds from the version objects being removed, used to clean up lane history entries */
16
+ batchIds?: string[];
15
17
  };
16
18
  /**
17
19
  * If head is false, remove all local versions.
@@ -7,6 +7,13 @@ exports.getComponentsWithOptionToUntag = getComponentsWithOptionToUntag;
7
7
  exports.removeLocalVersion = removeLocalVersion;
8
8
  exports.removeLocalVersionsForAllComponents = removeLocalVersionsForAllComponents;
9
9
  exports.removeLocalVersionsForMultipleComponents = removeLocalVersionsForMultipleComponents;
10
+ function _lodash() {
11
+ const data = require("lodash");
12
+ _lodash = function () {
13
+ return data;
14
+ };
15
+ return data;
16
+ }
10
17
  function _bitError() {
11
18
  const data = require("@teambit/bit-error");
12
19
  _bitError = function () {
@@ -63,6 +70,15 @@ async function removeLocalVersion(consumer, id, lane, head, force = false) {
63
70
  }
64
71
  });
65
72
  }
73
+
74
+ // Load version objects to extract batchIds before they are removed.
75
+ // These batchIds are used to clean up the corresponding lane history entries.
76
+ // Only needed on lanes — on main there's no lane history to clean up.
77
+ let batchIds;
78
+ if (lane) {
79
+ const versionObjects = await Promise.all(versionsToRemoveStr.map(ver => component.loadVersion(ver, consumer.scope.objects, false)));
80
+ batchIds = [...new Set((0, _lodash().compact)((0, _lodash().compact)(versionObjects).map(v => v.batchId)))];
81
+ }
66
82
  const headBefore = component.getHead();
67
83
  await consumer.scope.sources.removeComponentVersions(component, versionsToRemove, versionsToRemoveStr, lane, head);
68
84
  const headAfter = component.getHead();
@@ -77,7 +93,8 @@ async function removeLocalVersion(consumer, id, lane, head, force = false) {
77
93
  id,
78
94
  versions: versionsToRemoveStr,
79
95
  component,
80
- versionToSetInBitmap
96
+ versionToSetInBitmap,
97
+ batchIds
81
98
  };
82
99
  }
83
100
  async function removeLocalVersionsForAllComponents(workspace, remove, lane, head) {
@@ -1 +1 @@
1
- {"version":3,"names":["_bitError","data","require","_legacy","_legacy2","_legacy3","removeLocalVersion","consumer","id","lane","head","force","component","scope","getModelComponent","idStr","toString","fromBitmap","bitMap","getComponentIdIfExist","localVersions","getLocalHashes","objects","length","BitError","headRef","getHeadRegardlessOfLane","Error","find","v","isEqual","versionsToRemove","versionsToRemoveStr","switchHashesWithTagsIfExist","dependencyGraph","DependencyGraph","loadAllVersions","forEach","versionToRemove","idWithVersion","toComponentId","changeVersion","dependents","getImmediateDependentsPerId","join","headBefore","getHead","sources","removeComponentVersions","headAfter","versionToSetInBitmap","divergeData","getDivergeData","snapBeforeDetached","commonSnapBeforeDiverge","getTagOfRefIfExists","versions","removeLocalVersionsForAllComponents","workspace","remove","componentsToUntag","getComponentsWithOptionToUntag","removeLocalVersionsForMultipleComponents","candidateComponentsIds","map","bitId","candidateComponentsIdsStr","dependentsNotCandidates","filter","dependent","includes","version","logger","debug","Promise","all","componentList","ComponentsList","laneObj","getCurrentLaneObject","components","listExportPendingComponents","removedStagedIds","getRemovedStaged","removedStagedBitIds","nonExistsInStaged","c","isEqualWithoutVersion","modelComps","push"],"sources":["reset-component.ts"],"sourcesContent":["import { BitError } from '@teambit/bit-error';\nimport type { ComponentID } from '@teambit/component-id';\nimport type { Consumer } from '@teambit/legacy.consumer';\nimport { ComponentsList } from '@teambit/legacy.component-list';\nimport { logger } from '@teambit/legacy.logger';\nimport type { Lane, ModelComponent } from '@teambit/objects';\nimport type { RemoveMain } from '@teambit/remove';\nimport { DependencyGraph } from '@teambit/legacy.dependency-graph';\nimport type { Workspace } from '@teambit/workspace';\n\nexport type ResetResult = {\n id: ComponentID;\n versions: string[];\n component?: ModelComponent;\n /**\n * relevant when the component was detached head so the head didn't change.\n * we want .bitmap to have the version before the detachment. not as the head.\n */\n versionToSetInBitmap?: string;\n};\n\n/**\n * If head is false, remove all local versions.\n */\nexport async function removeLocalVersion(\n consumer: Consumer,\n id: ComponentID,\n lane?: Lane,\n head?: boolean,\n force = false\n): Promise<ResetResult> {\n const component: ModelComponent = await consumer.scope.getModelComponent(id);\n const idStr = id.toString();\n const fromBitmap = consumer.bitMap.getComponentIdIfExist(id);\n const localVersions = await component.getLocalHashes(consumer.scope.objects, fromBitmap);\n if (!localVersions.length) throw new BitError(`unable to untag ${idStr}, the component is not staged`);\n const headRef = component.getHeadRegardlessOfLane();\n if (!headRef) {\n throw new Error(`unable to reset ${idStr}, it has not head`);\n }\n if (head && !localVersions.find((v) => v.isEqual(headRef))) {\n throw new Error(`unable to reset ${idStr}, the head ${headRef.toString()} is exported`);\n }\n const versionsToRemove = head ? [headRef] : localVersions;\n const versionsToRemoveStr = component.switchHashesWithTagsIfExist(versionsToRemove);\n\n if (!force) {\n const dependencyGraph = await DependencyGraph.loadAllVersions(consumer.scope);\n\n versionsToRemoveStr.forEach((versionToRemove) => {\n const idWithVersion = component.toComponentId().changeVersion(versionToRemove);\n const dependents = dependencyGraph.getImmediateDependentsPerId(idWithVersion);\n if (dependents.length) {\n throw new BitError(\n `unable to reset ${idStr}, the version ${versionToRemove} has the following dependent(s) ${dependents.join(\n ', '\n )}`\n );\n }\n });\n }\n\n const headBefore = component.getHead();\n await consumer.scope.sources.removeComponentVersions(component, versionsToRemove, versionsToRemoveStr, lane, head);\n const headAfter = component.getHead();\n let versionToSetInBitmap;\n if (headBefore && headAfter && headBefore.isEqual(headAfter) && !lane) {\n // if it's on main and the head didn't change, it means that it was in a detached-head state.\n const divergeData = component.getDivergeData();\n const snapBeforeDetached = divergeData.commonSnapBeforeDiverge;\n if (snapBeforeDetached) versionToSetInBitmap = component.getTagOfRefIfExists(snapBeforeDetached);\n }\n\n return { id, versions: versionsToRemoveStr, component, versionToSetInBitmap };\n}\n\nexport async function removeLocalVersionsForAllComponents(\n workspace: Workspace,\n remove: RemoveMain,\n lane?: Lane,\n head?: boolean\n): Promise<ResetResult[]> {\n const componentsToUntag = await getComponentsWithOptionToUntag(workspace, remove);\n const force = true; // when removing local versions from all components, no need to check if the component is used as a dependency\n return removeLocalVersionsForMultipleComponents(workspace.consumer, componentsToUntag, lane, head, force);\n}\n\nexport async function removeLocalVersionsForMultipleComponents(\n consumer: Consumer,\n componentsToUntag: ModelComponent[],\n lane?: Lane,\n head?: boolean,\n force?: boolean\n) {\n if (!componentsToUntag.length) {\n throw new BitError(`no components found to reset on your workspace`);\n }\n // if only head is removed, there is risk of deleting dependencies version without their dependents.\n if (!force && head) {\n const dependencyGraph = await DependencyGraph.loadAllVersions(consumer.scope);\n const candidateComponentsIds = componentsToUntag.map((component) => {\n const bitId = component.toComponentId();\n const headRef = component.getHeadRegardlessOfLane();\n if (!headRef)\n throw new Error(`component ${bitId.toString()} does not have head. it should not be a candidate for reset`);\n\n return bitId.changeVersion(component.getTagOfRefIfExists(headRef) || headRef.toString());\n });\n const candidateComponentsIdsStr = candidateComponentsIds.map((id) => id.toString());\n candidateComponentsIds.forEach((bitId: ComponentID) => {\n const dependents = dependencyGraph.getImmediateDependentsPerId(bitId);\n // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!\n const dependentsNotCandidates = dependents.filter((dependent) => !candidateComponentsIdsStr.includes(dependent));\n if (dependentsNotCandidates.length) {\n throw new BitError( // $FlowFixMe\n `unable to untag ${bitId}, the version ${bitId.version} has the following dependent(s) ${dependents.join(\n ', '\n )}`\n );\n }\n });\n }\n logger.debug(`found ${componentsToUntag.length} components to untag`);\n return Promise.all(\n componentsToUntag.map((component) => removeLocalVersion(consumer, component.toComponentId(), lane, head, force))\n );\n}\n\nexport async function getComponentsWithOptionToUntag(\n workspace: Workspace,\n remove: RemoveMain\n): Promise<ModelComponent[]> {\n const componentList = new ComponentsList(workspace);\n const laneObj = await workspace.getCurrentLaneObject();\n const components: ModelComponent[] = await componentList.listExportPendingComponents(laneObj);\n const removedStagedIds = await remove.getRemovedStaged();\n if (!removedStagedIds.length) return components;\n const removedStagedBitIds = removedStagedIds.map((id) => id);\n const nonExistsInStaged = removedStagedBitIds.filter(\n (id) => !components.find((c) => c.toComponentId().isEqualWithoutVersion(id))\n );\n if (!nonExistsInStaged.length) return components;\n const modelComps = await Promise.all(nonExistsInStaged.map((id) => workspace.consumer.scope.getModelComponent(id)));\n components.push(...modelComps);\n\n return components;\n}\n"],"mappings":";;;;;;;;;AAAA,SAAAA,UAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,SAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAGA,SAAAE,QAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,OAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,SAAA;EAAA,MAAAH,IAAA,GAAAC,OAAA;EAAAE,QAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAGA,SAAAI,SAAA;EAAA,MAAAJ,IAAA,GAAAC,OAAA;EAAAG,QAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAcA;AACA;AACA;AACO,eAAeK,kBAAkBA,CACtCC,QAAkB,EAClBC,EAAe,EACfC,IAAW,EACXC,IAAc,EACdC,KAAK,GAAG,KAAK,EACS;EACtB,MAAMC,SAAyB,GAAG,MAAML,QAAQ,CAACM,KAAK,CAACC,iBAAiB,CAACN,EAAE,CAAC;EAC5E,MAAMO,KAAK,GAAGP,EAAE,CAACQ,QAAQ,CAAC,CAAC;EAC3B,MAAMC,UAAU,GAAGV,QAAQ,CAACW,MAAM,CAACC,qBAAqB,CAACX,EAAE,CAAC;EAC5D,MAAMY,aAAa,GAAG,MAAMR,SAAS,CAACS,cAAc,CAACd,QAAQ,CAACM,KAAK,CAACS,OAAO,EAAEL,UAAU,CAAC;EACxF,IAAI,CAACG,aA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AC,CAAC,EAAE/B,IAAI,EAAEC,IAAI,EAAEC,KAAK,CAAC,CACjH,CAAC;AACH;AAEO,eAAekD,8BAA8BA,CAClDH,SAAoB,EACpBC,MAAkB,EACS;EAC3B,MAAMiB,aAAa,GAAG,KAAIC,wBAAc,EAACnB,SAAS,CAAC;EACnD,MAAMoB,OAAO,GAAG,MAAMpB,SAAS,CAACqB,oBAAoB,CAAC,CAAC;EACtD,MAAMC,UAA4B,GAAG,MAAMJ,aAAa,CAACK,2BAA2B,CAACH,OAAO,CAAC;EAC7F,MAAMI,gBAAgB,GAAG,MAAMvB,MAAM,CAACwB,gBAAgB,CAAC,CAAC;EACxD,IAAI,CAACD,gBAAgB,CAAC3D,MAAM,EAAE,OAAOyD,UAAU;EAC/C,MAAMI,mBAAmB,GAAGF,gBAAgB,CAAClB,GAAG,CAAExD,EAAE,IAAKA,EAAE,CAAC;EAC5D,MAAM6E,iBAAiB,GAAGD,mBAAmB,CAAChB,MAAM,CACjD5D,EAAE,IAAK,CAACwE,UAAU,CAACpD,IAAI,CAAE0D,CAAC,IAAKA,CAAC,CAAC9C,aAAa,CAAC,CAAC,CAAC+C,qBAAqB,CAAC/E,EAAE,CAAC,CAC7E,CAAC;EACD,IAAI,CAAC6E,iBAAiB,CAAC9D,MAAM,EAAE,OAAOyD,UAAU;EAChD,MAAMQ,UAAU,GAAG,MAAMd,OAAO,CAACC,GAAG,CAACU,iBAAiB,CAACrB,GAAG,CAAExD,EAAE,IAAKkD,SAAS,CAACnD,QAAQ,CAACM,KAAK,CAACC,iBAAiB,CAACN,EAAE,CAAC,CAAC,CAAC;EACnHwE,UAAU,CAACS,IAAI,CAAC,GAAGD,UAAU,CAAC;EAE9B,OAAOR,UAAU;AACnB","ignoreList":[]}
1
+ {"version":3,"names":["_lodash","data","require","_bitError","_legacy","_legacy2","_legacy3","removeLocalVersion","consumer","id","lane","head","force","component","scope","getModelComponent","idStr","toString","fromBitmap","bitMap","getComponentIdIfExist","localVersions","getLocalHashes","objects","length","BitError","headRef","getHeadRegardlessOfLane","Error","find","v","isEqual","versionsToRemove","versionsToRemoveStr","switchHashesWithTagsIfExist","dependencyGraph","DependencyGraph","loadAllVersions","forEach","versionToRemove","idWithVersion","toComponentId","changeVersion","dependents","getImmediateDependentsPerId","join","batchIds","versionObjects","Promise","all","map","ver","loadVersion","Set","compact","batchId","headBefore","getHead","sources","removeComponentVersions","headAfter","versionToSetInBitmap","divergeData","getDivergeData","snapBeforeDetached","commonSnapBeforeDiverge","getTagOfRefIfExists","versions","removeLocalVersionsForAllComponents","workspace","remove","componentsToUntag","getComponentsWithOptionToUntag","removeLocalVersionsForMultipleComponents","candidateComponentsIds","bitId","candidateComponentsIdsStr","dependentsNotCandidates","filter","dependent","includes","version","logger","debug","componentList","ComponentsList","laneObj","getCurrentLaneObject","components","listExportPendingComponents","removedStagedIds","getRemovedStaged","removedStagedBitIds","nonExistsInStaged","c","isEqualWithoutVersion","modelComps","push"],"sources":["reset-component.ts"],"sourcesContent":["import { compact } from 'lodash';\nimport { BitError } from '@teambit/bit-error';\nimport type { ComponentID } from '@teambit/component-id';\nimport type { Consumer } from '@teambit/legacy.consumer';\nimport { ComponentsList } from '@teambit/legacy.component-list';\nimport { logger } from '@teambit/legacy.logger';\nimport type { Lane, ModelComponent } from '@teambit/objects';\nimport type { RemoveMain } from '@teambit/remove';\nimport { DependencyGraph } from '@teambit/legacy.dependency-graph';\nimport type { Workspace } from '@teambit/workspace';\n\nexport type ResetResult = {\n id: ComponentID;\n versions: string[];\n component?: ModelComponent;\n /**\n * relevant when the component was detached head so the head didn't change.\n * we want .bitmap to have the version before the detachment. not as the head.\n */\n versionToSetInBitmap?: string;\n /** batchIds from the version objects being removed, used to clean up lane history entries */\n batchIds?: string[];\n};\n\n/**\n * If head is false, remove all local versions.\n */\nexport async function removeLocalVersion(\n consumer: Consumer,\n id: ComponentID,\n lane?: Lane,\n head?: boolean,\n force = false\n): Promise<ResetResult> {\n const component: ModelComponent = await consumer.scope.getModelComponent(id);\n const idStr = id.toString();\n const fromBitmap = consumer.bitMap.getComponentIdIfExist(id);\n const localVersions = await component.getLocalHashes(consumer.scope.objects, fromBitmap);\n if (!localVersions.length) throw new BitError(`unable to untag ${idStr}, the component is not staged`);\n const headRef = component.getHeadRegardlessOfLane();\n if (!headRef) {\n throw new Error(`unable to reset ${idStr}, it has not head`);\n }\n if (head && !localVersions.find((v) => v.isEqual(headRef))) {\n throw new Error(`unable to reset ${idStr}, the head ${headRef.toString()} is exported`);\n }\n const versionsToRemove = head ? [headRef] : localVersions;\n const versionsToRemoveStr = component.switchHashesWithTagsIfExist(versionsToRemove);\n\n if (!force) {\n const dependencyGraph = await DependencyGraph.loadAllVersions(consumer.scope);\n\n versionsToRemoveStr.forEach((versionToRemove) => {\n const idWithVersion = component.toComponentId().changeVersion(versionToRemove);\n const dependents = dependencyGraph.getImmediateDependentsPerId(idWithVersion);\n if (dependents.length) {\n throw new BitError(\n `unable to reset ${idStr}, the version ${versionToRemove} has the following dependent(s) ${dependents.join(\n ', '\n )}`\n );\n }\n });\n }\n\n // Load version objects to extract batchIds before they are removed.\n // These batchIds are used to clean up the corresponding lane history entries.\n // Only needed on lanes — on main there's no lane history to clean up.\n let batchIds: string[] | undefined;\n if (lane) {\n const versionObjects = await Promise.all(\n versionsToRemoveStr.map((ver) => component.loadVersion(ver, consumer.scope.objects, false))\n );\n batchIds = [...new Set(compact(compact(versionObjects).map((v) => v.batchId)))];\n }\n\n const headBefore = component.getHead();\n await consumer.scope.sources.removeComponentVersions(component, versionsToRemove, versionsToRemoveStr, lane, head);\n const headAfter = component.getHead();\n let versionToSetInBitmap;\n if (headBefore && headAfter && headBefore.isEqual(headAfter) && !lane) {\n // if it's on main and the head didn't change, it means that it was in a detached-head state.\n const divergeData = component.getDivergeData();\n const snapBeforeDetached = divergeData.commonSnapBeforeDiverge;\n if (snapBeforeDetached) versionToSetInBitmap = component.getTagOfRefIfExists(snapBeforeDetached);\n }\n\n return { id, versions: versionsToRemoveStr, component, versionToSetInBitmap, batchIds };\n}\n\nexport async function removeLocalVersionsForAllComponents(\n workspace: Workspace,\n remove: RemoveMain,\n lane?: Lane,\n head?: boolean\n): Promise<ResetResult[]> {\n const componentsToUntag = await getComponentsWithOptionToUntag(workspace, remove);\n const force = true; // when removing local versions from all components, no need to check if the component is used as a dependency\n return removeLocalVersionsForMultipleComponents(workspace.consumer, componentsToUntag, lane, head, force);\n}\n\nexport async function removeLocalVersionsForMultipleComponents(\n consumer: Consumer,\n componentsToUntag: ModelComponent[],\n lane?: Lane,\n head?: boolean,\n force?: boolean\n) {\n if (!componentsToUntag.length) {\n throw new BitError(`no components found to reset on your workspace`);\n }\n // if only head is removed, there is risk of deleting dependencies version without their dependents.\n if (!force && head) {\n const dependencyGraph = await DependencyGraph.loadAllVersions(consumer.scope);\n const candidateComponentsIds = componentsToUntag.map((component) => {\n const bitId = component.toComponentId();\n const headRef = component.getHeadRegardlessOfLane();\n if (!headRef)\n throw new Error(`component ${bitId.toString()} does not have head. it should not be a candidate for reset`);\n\n return bitId.changeVersion(component.getTagOfRefIfExists(headRef) || headRef.toString());\n });\n const candidateComponentsIdsStr = candidateComponentsIds.map((id) => id.toString());\n candidateComponentsIds.forEach((bitId: ComponentID) => {\n const dependents = dependencyGraph.getImmediateDependentsPerId(bitId);\n // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!\n const dependentsNotCandidates = dependents.filter((dependent) => !candidateComponentsIdsStr.includes(dependent));\n if (dependentsNotCandidates.length) {\n throw new BitError( // $FlowFixMe\n `unable to untag ${bitId}, the version ${bitId.version} has the following dependent(s) ${dependents.join(\n ', '\n )}`\n );\n }\n });\n }\n logger.debug(`found ${componentsToUntag.length} components to untag`);\n return Promise.all(\n componentsToUntag.map((component) => removeLocalVersion(consumer, component.toComponentId(), lane, head, force))\n );\n}\n\nexport async function getComponentsWithOptionToUntag(\n workspace: Workspace,\n remove: RemoveMain\n): Promise<ModelComponent[]> {\n const componentList = new ComponentsList(workspace);\n const laneObj = await workspace.getCurrentLaneObject();\n const components: ModelComponent[] = await componentList.listExportPendingComponents(laneObj);\n const removedStagedIds = await remove.getRemovedStaged();\n if (!removedStagedIds.length) return components;\n const removedStagedBitIds = removedStagedIds.map((id) => id);\n const nonExistsInStaged = removedStagedBitIds.filter(\n (id) => !components.find((c) => c.toComponentId().isEqualWithoutVersion(id))\n );\n if (!nonExistsInStaged.length) return components;\n const modelComps = await Promise.all(nonExistsInStaged.map((id) => workspace.consumer.scope.getModelComponent(id)));\n components.push(...modelComps);\n\n return components;\n}\n"],"mappings":";;;;;;;;;AAAA,SAAAA,QAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,OAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAE,UAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,SAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAGA,SAAAG,QAAA;EAAA,MAAAH,IAAA,GAAAC,OAAA;EAAAE,OAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,SAAA;EAAA,MAAAJ,IAAA,GAAAC,OAAA;EAAAG,QAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAGA,SAAAK,SAAA;EAAA,MAAAL,IAAA,GAAAC,OAAA;EAAAI,QAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAgBA;AACA;AACA;AACO,eAAeM,kBAAkBA,CACtCC,QAAkB,EAClBC,EAAe,EACfC,IAAW,EACXC,IAAc,EACdC,KAAK,GAAG,KAAK,EACS;EACtB,MAAMC,SAAyB,GAAG,MAAML,QAAQ,CAACM,KAAK,CAACC,iBAAiB,CAACN,EAAE,CAAC;EAC5E,MAAMO,K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AAgB,CAACxC,GAAG,CAAEzC,EAAE,IAAKA,EAAE,CAAC;EAC5D,MAAMoF,iBAAiB,GAAGD,mBAAmB,CAACd,MAAM,CACjDrE,EAAE,IAAK,CAAC+E,UAAU,CAAC3D,IAAI,CAAEiE,CAAC,IAAKA,CAAC,CAACrD,aAAa,CAAC,CAAC,CAACsD,qBAAqB,CAACtF,EAAE,CAAC,CAC7E,CAAC;EACD,IAAI,CAACoF,iBAAiB,CAACrE,MAAM,EAAE,OAAOgE,UAAU;EAChD,MAAMQ,UAAU,GAAG,MAAMhD,OAAO,CAACC,GAAG,CAAC4C,iBAAiB,CAAC3C,GAAG,CAAEzC,EAAE,IAAK4D,SAAS,CAAC7D,QAAQ,CAACM,KAAK,CAACC,iBAAiB,CAACN,EAAE,CAAC,CAAC,CAAC;EACnH+E,UAAU,CAACS,IAAI,CAAC,GAAGD,UAAU,CAAC;EAE9B,OAAOR,UAAU;AACnB","ignoreList":[]}
@@ -809,6 +809,17 @@ in case you're unsure about the pattern syntax, use "bit pattern [--help]"`);
809
809
  const isRealUntag = !soft;
810
810
  if (isRealUntag) {
811
811
  results = await untag();
812
+
813
+ // Remove lane history entries that correspond to the reset snaps.
814
+ // Each snap uses its batchId as the lane history key, so we can match them.
815
+ if (currentLane) {
816
+ const allBatchIds = (0, _lodash().uniq)(results.flatMap(r => r.batchIds || []));
817
+ if (allBatchIds.length) {
818
+ const laneHistory = await consumer.scope.lanes.getOrCreateLaneHistory(currentLane);
819
+ laneHistory.removeHistoryEntries(allBatchIds);
820
+ consumer.scope.objects.add(laneHistory);
821
+ }
822
+ }
812
823
  await consumer.scope.objects.persist();
813
824
  const currentLaneId = consumer.getCurrentLaneId();
814
825
  const stagedConfig = await this.workspace.scope.getStagedConfig();