Skip to content

Commit

Permalink
fix(lane-merge), import missing artifacts before starting the merge p…
Browse files Browse the repository at this point in the history
…rocess (#7103)

otherwise, in some case, it needs the artifacts later on in the merge
process where it doesn't have the lane object at hand and then throw an
error about missing objects.
  • Loading branch information
davidfirst authored Feb 28, 2023
1 parent ef08cc5 commit b9ac5fa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 15 additions & 2 deletions scopes/lanes/merge-lanes/merge-lanes.main.runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ import ScopeComponentsImporter from '@teambit/legacy/dist/scope/component-ops/sc
import { ComponentID } from '@teambit/component-id';
import { DEFAULT_LANE, LaneId } from '@teambit/lane-id';
import { Lane, Version } from '@teambit/legacy/dist/scope/models';
import { getRefsFromExtensions } from '@teambit/legacy/dist/consumer/component/sources/artifact-files';
import { Logger, LoggerAspect, LoggerMain } from '@teambit/logger';
import { SnapsDistance } from '@teambit/legacy/dist/scope/component-ops/snaps-distance';
import { RemoveAspect, RemoveMain } from '@teambit/remove';
import { compact } from 'lodash';
import { compact, uniq } from 'lodash';
import { ExportAspect, ExportMain } from '@teambit/export';
import { BitObject } from '@teambit/legacy/dist/scope/objects';
import { getDivergeData } from '@teambit/legacy/dist/scope/component-ops/get-diverge-data';
Expand Down Expand Up @@ -107,7 +108,19 @@ export class MergeLanesMain {
const shouldFetch = !lane || (!skipFetch && !lane.isNew);
if (shouldFetch) {
// don't assign `lane` to the result of this command. otherwise, if you have local snaps, it'll ignore them and use the remote-lane.
await this.lanes.fetchLaneWithItsComponents(otherLaneId);
const otherLane = await this.lanes.fetchLaneWithItsComponents(otherLaneId);

// get all artifacts
const allIds = otherLane.toBitIds();
const laneComps = await consumer.scope.getManyConsumerComponents(allIds);
const allRefs = laneComps.map((comp) => getRefsFromExtensions(comp.extensions)).flat();
const allRefsUniq = uniq(allRefs.map((r) => r.toString()));
try {
await consumer.scope.scopeImporter.importManyObjects({ [otherLaneId.scope]: allRefsUniq });
} catch (err) {
this.logger.error(`failed fetching artifacts for lane ${otherLaneId.toString()}`, err);
}

lane = await consumer.scope.loadLane(otherLaneId);
}
return lane;
Expand Down
2 changes: 1 addition & 1 deletion src/scope/component-ops/scope-components-importer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export default class ScopeComponentsImporter {

/**
* an efficient way to verify that all history exists locally.
* instead of all versions objects, load only the VersionHistory, get the graph from head, then only check whether
* instead of loading all versions objects, load only the VersionHistory, get the graph from head, then only check whether
* the objects exist in the filesystem.
*/
private async importMissingHistoryOne(id: BitId) {
Expand Down

0 comments on commit b9ac5fa

Please sign in to comment.