From c14dc1d9932057efd04cbd657effe50d4acb1512 Mon Sep 17 00:00:00 2001 From: David First Date: Mon, 13 Feb 2023 11:48:41 -0500 Subject: [PATCH 1/2] fix(snap-from-scope): export only the current snap, ignore the history --- e2e/harmony/snap-from-scope.e2e.ts | 50 +++++++++++++++++++ .../snapping/snapping.main.runtime.ts | 4 ++ 2 files changed, 54 insertions(+) diff --git a/e2e/harmony/snap-from-scope.e2e.ts b/e2e/harmony/snap-from-scope.e2e.ts index 87babda1e92f..67e2838cf82e 100644 --- a/e2e/harmony/snap-from-scope.e2e.ts +++ b/e2e/harmony/snap-from-scope.e2e.ts @@ -166,4 +166,54 @@ describe('snap components from scope', function () { }); }); }); + describe('snap on a lane when the component is new to the lane and the scope', () => { + let bareScope; + let beforeSnappingOnScope: string; + 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.snapAllComponentsWithoutBuild(); + // snap multiple times on main. these snaps will be missing locally during the snap-from-scope + helper.command.snapAllComponentsWithoutBuild('--unmodified'); + helper.command.snapAllComponentsWithoutBuild('--unmodified'); + helper.command.export(); + helper.command.createLane(); + helper.fixtures.createComponentBarFoo(); + helper.fixtures.addComponentBarFooAsDir(); + helper.command.snapAllComponentsWithoutBuild(); + helper.command.export(); + + bareScope = helper.scopeHelper.getNewBareScope('-bare-merge'); + helper.scopeHelper.addRemoteScope(helper.scopes.remotePath, bareScope.scopePath); + helper.scopeHelper.addRemoteScope(scopePath, bareScope.scopePath); + beforeSnappingOnScope = helper.scopeHelper.cloneScope(bareScope.scopePath); + }); + describe('running with --push flag', () => { + before(() => { + const data = [ + { + componentId: `${anotherRemote}/comp1`, + message: `msg`, + }, + ]; + helper.scopeHelper.getClonedScope(beforeSnappingOnScope, bareScope.scopePath); + helper.command.snapFromScope(bareScope.scopePath, data, `--push --lane ${helper.scopes.remote}/dev`); + }); + // previously, it was throwing an error during the export: + // error: version "ebf5f55d3b8f1897cb1ac4f236b058b4ddd0c701" of component bnbu2jms-remote2/comp1 was not found on the filesystem. try running "bit import". if it doesn't help, try running "bit import bnbu2jms-remote2/comp1 --objects" + // because it was trying to export previous snaps from main although they were not imported locally + it('should export successfully to the remote', () => { + const snapOnLaneOnBareScope = helper.command.getHeadOfLane('dev', 'comp1', bareScope.scopePath); + const snapOnLaneOnRemote = helper.command.getHeadOfLane('dev', 'comp1', helper.scopes.remotePath); + expect(snapOnLaneOnBareScope).to.equal(snapOnLaneOnRemote); + }); + }); + }); }); diff --git a/scopes/component/snapping/snapping.main.runtime.ts b/scopes/component/snapping/snapping.main.runtime.ts index e2b3cb6e7bbe..89f7af535cf7 100644 --- a/scopes/component/snapping/snapping.main.runtime.ts +++ b/scopes/component/snapping/snapping.main.runtime.ts @@ -390,6 +390,10 @@ export class SnappingMain { idsWithFutureScope: legacyIds, allVersions: false, laneObject: updatedLane || undefined, + // no need other snaps. only the latest one. without this option, when snapping on lane from another-scope, it + // may throw an error saying the previous snaps don't exist on the filesystem. + // (see the e2e - "snap on a lane when the component is new to the lane and the scope") + exportHeadsOnly: true, }); exportedIds = exported.map((e) => e.toString()); } From 406c08f9eb0cddbb901c1cd10842572d2096bc72 Mon Sep 17 00:00:00 2001 From: David First Date: Mon, 13 Feb 2023 13:44:33 -0500 Subject: [PATCH 2/2] fix tests --- scopes/scope/export/export.main.runtime.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scopes/scope/export/export.main.runtime.ts b/scopes/scope/export/export.main.runtime.ts index 2485516eb2de..79fb8f1160c3 100644 --- a/scopes/scope/export/export.main.runtime.ts +++ b/scopes/scope/export/export.main.runtime.ts @@ -266,7 +266,7 @@ export class ExportMain { const getVersionsToExport = async (modelComponent: ModelComponent): Promise => { if (exportHeadsOnly) { - const head = modelComponent.head; + const head = laneObject?.getComponent(modelComponent.toBitId())?.head || modelComponent.head; if (!head) throw new Error( `getVersionsToExport should export the head only, but the head of ${modelComponent.id()} is missing`