Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(snap-from-scope): export only the current snap, ignore the history #7031

Merged
merged 2 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions e2e/harmony/snap-from-scope.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});
});
4 changes: 4 additions & 0 deletions scopes/component/snapping/snapping.main.runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
2 changes: 1 addition & 1 deletion scopes/scope/export/export.main.runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ export class ExportMain {

const getVersionsToExport = async (modelComponent: ModelComponent): Promise<Ref[]> => {
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`
Expand Down