From e03d03f8da17262ce973ca86300a612c1c2ca51b Mon Sep 17 00:00:00 2001 From: David First Date: Tue, 14 Feb 2023 11:17:24 -0500 Subject: [PATCH 1/2] fix(export): do not try to export snaps existing on main --- src/scope/models/model-component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scope/models/model-component.ts b/src/scope/models/model-component.ts index ddbd310d9065..97e1681aa44d 100644 --- a/src/scope/models/model-component.ts +++ b/src/scope/models/model-component.ts @@ -306,7 +306,7 @@ export default class Component extends BitObject { return LaneId.from(DEFAULT_LANE, this.scope as string); }; const remoteToCheck = getRemoteToCheck(); - this.laneHeadRemote = await repo.remoteLanes.getRef(remoteToCheck, this.toBitId()); + this.laneHeadRemote = (await repo.remoteLanes.getRef(remoteToCheck, this.toBitId())) || this.head; } // we need also the remote head of main, otherwise, the diverge-data assumes all versions are local this.remoteHead = await repo.remoteLanes.getRef(LaneId.from(DEFAULT_LANE, this.scope), this.toBitId()); From efa923bd1b7fa2591430a36529e50ccc5ce126b0 Mon Sep 17 00:00:00 2001 From: David First Date: Tue, 14 Feb 2023 12:20:33 -0500 Subject: [PATCH 2/2] add tests --- e2e/harmony/lanes/lanes.e2e.ts | 39 +++++++++++++++++++++++++++++ src/scope/models/model-component.ts | 2 ++ 2 files changed, 41 insertions(+) diff --git a/e2e/harmony/lanes/lanes.e2e.ts b/e2e/harmony/lanes/lanes.e2e.ts index 1bc4811af99e..5a852c7141eb 100644 --- a/e2e/harmony/lanes/lanes.e2e.ts +++ b/e2e/harmony/lanes/lanes.e2e.ts @@ -908,6 +908,45 @@ describe('bit lane command', function () { expect(getFirstTagFromRemote).to.not.throw(); }); }); + describe('multiple scopes - lane-scope does not have main tags', () => { + let anotherRemote: string; + before(() => { + helper.scopeHelper.setNewLocalAndRemoteScopes(); + const { scopeName, scopePath } = helper.scopeHelper.getNewBareScope(); + anotherRemote = scopeName; + helper.scopeHelper.addRemoteScope(scopePath); + helper.scopeHelper.addRemoteScope(scopePath, helper.scopes.remotePath); + helper.scopeHelper.addRemoteScope(helper.scopes.remotePath, scopePath); + helper.fixtures.populateComponents(1, false); + helper.command.setScope(scopeName, 'comp1'); + helper.command.tagAllWithoutBuild(); + // snap multiple times on main. these snaps will be missing locally during the snap-from-scope + helper.command.tagAllWithoutBuild('--unmodified'); + helper.command.tagAllWithoutBuild('--unmodified'); + helper.command.export(); + + helper.scopeHelper.reInitLocalScope(); + helper.scopeHelper.addRemoteScope(); + helper.scopeHelper.addRemoteScope(scopePath); + helper.command.createLane(); + helper.fixtures.createComponentBarFoo(); + helper.fixtures.addComponentBarFooAsDir(); + helper.command.snapAllComponentsWithoutBuild(); + helper.command.export(); + + helper.command.import(`${anotherRemote}/comp1`); + helper.command.snapAllComponentsWithoutBuild('--unmodified'); + }); + it('bit status should show only the last snap of the imported component as staged', () => { + const status = helper.command.statusJson(); + status.stagedComponents.forEach((comp) => { + expect(comp.versions).to.have.lengthOf(1); + }); + }); + it('bit export should not throw an error', () => { + expect(() => helper.command.export()).to.not.throw(); + }); + }); describe('snapping and un-tagging on a lane', () => { let afterFirstSnap: string; before(() => { diff --git a/src/scope/models/model-component.ts b/src/scope/models/model-component.ts index 97e1681aa44d..fbd676ebb238 100644 --- a/src/scope/models/model-component.ts +++ b/src/scope/models/model-component.ts @@ -306,6 +306,8 @@ export default class Component extends BitObject { return LaneId.from(DEFAULT_LANE, this.scope as string); }; const remoteToCheck = getRemoteToCheck(); + // if no remote-ref was found, because it's checked out to a lane, it's safe to assume that + // this.head should be on the original-remote. hence, FetchMissingHistory will retrieve it on lane-remote this.laneHeadRemote = (await repo.remoteLanes.getRef(remoteToCheck, this.toBitId())) || this.head; } // we need also the remote head of main, otherwise, the diverge-data assumes all versions are local