Skip to content

Commit

Permalink
fix(sign), throw a descriptive error when the requested snap belong t…
Browse files Browse the repository at this point in the history
…o another component (#9171)
  • Loading branch information
davidfirst authored Sep 3, 2024
1 parent f7a705e commit 703f79e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions scopes/scope/scope/scope-component-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import ConsumerComponent from '@teambit/legacy/dist/consumer/component';
import { ModelComponent, Version } from '@teambit/legacy/dist/scope/models';
import { Ref } from '@teambit/legacy/dist/scope/objects';
import { VERSION_ZERO } from '@teambit/legacy/dist/scope/models/model-component';
import { BitError } from '@teambit/bit-error';
import { getMaxSizeForComponents, InMemoryCache, createInMemoryCache } from '@teambit/harmony.modules.in-memory-cache';
import type { ScopeMain } from './scope.main.runtime';

Expand Down Expand Up @@ -51,6 +52,12 @@ export class ScopeComponentLoader {
if (versionStr === VERSION_ZERO) return undefined;
const newId = id.changeVersion(versionStr);
const version = await modelComponent.loadVersion(versionStr, this.scope.legacyScope.objects);
const versionOriginId = version.originId;
if (versionOriginId && !versionOriginId.isEqualWithoutVersion(id)) {
throw new BitError(
`version "${versionStr}" seem to be originated from "${versionOriginId.toString()}", not from "${id.toStringWithoutVersion()}"`
);
}
const snap = await this.getHeadSnap(modelComponent);
const state = await this.createStateFromVersion(id, version);
const tagMap = this.getTagMap(modelComponent);
Expand Down
5 changes: 5 additions & 0 deletions src/scope/models/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,11 @@ export default class Version extends BitObject {
get originLaneId(): LaneId | undefined {
return this.origin?.lane ? new LaneId({ name: this.origin.lane.name, scope: this.origin.lane.scope }) : undefined;
}
get originId(): ComponentID | undefined {
return this.origin?.id
? ComponentID.fromObject({ scope: this.origin.id.scope, name: this.origin.id.name })
: undefined;
}

setDist(dist: Source | undefined) {
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
Expand Down

0 comments on commit 703f79e

Please sign in to comment.