diff --git a/e2e/harmony/lanes/merge-lanes.e2e.ts b/e2e/harmony/lanes/merge-lanes.e2e.ts index bd963a268e57..585e5dd15b7e 100644 --- a/e2e/harmony/lanes/merge-lanes.e2e.ts +++ b/e2e/harmony/lanes/merge-lanes.e2e.ts @@ -939,4 +939,24 @@ describe('merge lanes', function () { expect(list).to.have.lengthOf(1); }); }); + describe('merge from main when a component head is a tag on main and was not changed on lane', () => { + before(() => { + helper.scopeHelper.setNewLocalAndRemoteScopes(); + helper.command.createLane(); + helper.fixtures.populateComponents(3); + helper.command.snapAllComponentsWithoutBuild(); + helper.command.export(); + helper.command.switchLocalLane('main', '-x'); + helper.command.mergeLane('dev', '-x'); + helper.command.tagAllWithoutBuild(); + helper.command.export(); + helper.command.switchLocalLane('dev', '-x'); + helper.command.mergeLane('main', '-x'); + }); + // previously, it was throwing an error + // id o5kaxkjd-remote/comp1@0.0.1 exists in flattenedEdges but not in flattened of o5kaxkjd-remote/comp1@6f820556b472253cd08331b20e704fe74217fd31 + it('bit status should not throw', () => { + expect(() => helper.command.status()).to.not.throw(); + }); + }); }); diff --git a/scopes/workspace/workspace/workspace.ts b/scopes/workspace/workspace/workspace.ts index 08424431e764..175478d034d4 100644 --- a/scopes/workspace/workspace/workspace.ts +++ b/scopes/workspace/workspace/workspace.ts @@ -66,6 +66,7 @@ import { Lane, Version } from '@teambit/legacy/dist/scope/models'; import { LaneNotFound } from '@teambit/legacy/dist/api/scope/lib/exceptions/lane-not-found'; import { ScopeNotFoundOrDenied } from '@teambit/legacy/dist/remotes/exceptions/scope-not-found-or-denied'; import { linkToNodeModulesByIds } from '@teambit/workspace.modules.node-modules-linker'; +import { isHash } from '@teambit/component-version'; import { ComponentLoadOptions } from '@teambit/legacy/dist/consumer/component/component-loader'; import { ComponentConfigFile } from './component-config-file'; import { @@ -451,7 +452,17 @@ export class Workspace implements ComponentFactory { return null; } const flattenedBitIdCompIdMap: { [bitIdStr: string]: ComponentID } = {}; - flattenedBitIdCompIdMap[component.id._legacy.toString()] = component.id; + const getCurrentVersionAsTagIfPossible = (): string | undefined => { + const currentVer = component.id.version; + if (!currentVer) return undefined; + const isCurrentVerAHash = isHash(currentVer); + if (!isCurrentVerAHash) return currentVer; + const tag = component.tags.byHash(currentVer)?.version.raw; + return tag || currentVer; + }; + const currentVersion = getCurrentVersionAsTagIfPossible(); + + flattenedBitIdCompIdMap[component.id._legacy.changeVersion(currentVersion).toString()] = component.id; await Promise.all( versionObj.flattenedDependencies.map(async (bitId) => { flattenedBitIdCompIdMap[bitId.toString()] = await this.resolveComponentId(bitId);