Skip to content

Commit

Permalink
fix(import): fetch versions that are shown in .bitmap but not in the …
Browse files Browse the repository at this point in the history
…lane object (#7167)

currently, when checked out to a lane, `bit import` fetches main
components from main and lane components according to the versions in
the lane.
In some scenarios, the .bitmap can be out-of-sync and a version in
.bitmap is different than a version in the lane object. Or maybe `bit
checkout` was running to a different version. In such cases, if the
local scope is deleted, bit was throwing `ComponentsPendingImport`
error.
This PR fixes the import process to fetch these versions as well.
  • Loading branch information
davidfirst authored Mar 16, 2023
1 parent 47c9351 commit b1f5a38
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
31 changes: 31 additions & 0 deletions e2e/harmony/lanes/lanes.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1458,4 +1458,35 @@ describe('bit lane command', function () {
});
});
});
describe('checking out to a different version from main', () => {
before(() => {
helper.scopeHelper.setNewLocalAndRemoteScopes();
helper.fixtures.populateComponents(1, false);
helper.command.tagAllWithoutBuild(); // 0.0.1
helper.command.tagAllWithoutBuild('--unmodified'); // 0.0.2
helper.command.export();

helper.scopeHelper.reInitLocalScope();
helper.scopeHelper.addRemoteScope();
helper.command.createLane();
helper.fixtures.createComponentBarFoo();
helper.fixtures.addComponentBarFooAsDir();
helper.command.snapAllComponentsWithoutBuild();
helper.command.importComponent('[email protected]', '--save-in-lane'); // now the lane has it as 0.0.1
helper.command.export();

helper.command.checkoutVersion('0.0.2', 'comp1', '-x');

// deleting the local scope
helper.command.init('--reset-scope');

helper.command.import();
});
it('bit import should bring the version in the bitmap', () => {
expect(() => helper.command.catComponent(`${helper.scopes.remote}/[email protected]`)).to.not.throw();
});
it('bit status should not throw ComponentsPendingImport', () => {
expect(() => helper.command.status()).to.not.throw();
});
});
});
7 changes: 4 additions & 3 deletions scopes/scope/importer/import-components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,10 @@ export default class ImportComponents {
const bitIdsFromLane = BitIds.fromArray(this.laneObjects.flatMap((lane) => lane.toBitIds()));

if (!this.options.ids.length) {
const mainIds = this.consumer.bitMap.getAuthoredAndImportedBitIdsOfDefaultLane();
const mainIdsToImport = mainIds.filter((id) => id.hasScope() && !bitIdsFromLane.hasWithoutVersion(id));
bitIdsFromLane.push(...mainIdsToImport);
const bitMapIds = this.consumer.bitMap.getAllBitIds();
const bitMapIdsToImport = bitMapIds.filter((id) => id.hasScope() && !bitIdsFromLane.has(id));
bitIdsFromLane.push(...bitMapIdsToImport);

return bitIdsFromLane;
}

Expand Down

0 comments on commit b1f5a38

Please sign in to comment.