From 8876016a30041e2e03dcea029d309e964c5bc130 Mon Sep 17 00:00:00 2001 From: David First Date: Fri, 10 Jan 2025 15:14:34 -0500 Subject: [PATCH] fix(checkout), enable checking out main-ids where on a lane --- e2e/harmony/checkout-harmony.e2e.ts | 15 +++++++++++++++ .../component/checkout/checkout.main.runtime.ts | 7 ++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/e2e/harmony/checkout-harmony.e2e.ts b/e2e/harmony/checkout-harmony.e2e.ts index 2b5bb8e28de4..a8596d9c7010 100644 --- a/e2e/harmony/checkout-harmony.e2e.ts +++ b/e2e/harmony/checkout-harmony.e2e.ts @@ -680,4 +680,19 @@ describe('bit checkout command', function () { expect(() => helper.command.status()).to.not.throw(); }); }); + describe('checkout main component when on a lane', () => { + before(() => { + helper.scopeHelper.setNewLocalAndRemoteScopes(); + helper.fixtures.populateComponents(1); + helper.command.tagAllWithoutBuild(); + helper.command.tagAllWithoutBuild('--unmodified'); + helper.command.export(); + helper.command.createLane('dev'); + helper.command.checkoutVersion('0.0.1', 'comp1', '-x'); + }); + it('should checkout the component successfully', () => { + const bitmap = helper.bitMap.read(); + expect(bitmap.comp1.version).to.equal('0.0.1'); + }); + }); }); diff --git a/scopes/component/checkout/checkout.main.runtime.ts b/scopes/component/checkout/checkout.main.runtime.ts index 965f5c8809a6..0fec3b80fa42 100644 --- a/scopes/component/checkout/checkout.main.runtime.ts +++ b/scopes/component/checkout/checkout.main.runtime.ts @@ -346,7 +346,12 @@ export class CheckoutMain { const currentLane = await this.workspace.consumer.getCurrentLaneObject(); const currentLaneIds = currentLane?.toComponentIds(); - const ids = currentLaneIds ? idsOnWorkspace.filter((id) => currentLaneIds.hasWithoutVersion(id)) : idsOnWorkspace; + // when no ids were given and the user is on a lane, return lane-ids only. + // it's relevant for cases like "bit checkout head" when on a lane to not checkout main components. (see https://github.com/teambit/bit/pull/6853) + const ids = + currentLaneIds && !componentPattern + ? idsOnWorkspace.filter((id) => currentLaneIds.hasWithoutVersion(id)) + : idsOnWorkspace; checkoutProps.ids = ids.map((id) => (checkoutProps.head || checkoutProps.latest ? id.changeVersion(LATEST) : id)); }