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

make lane name optional on change scope #7852

Closed
wants to merge 1 commit into from
Closed
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
10 changes: 6 additions & 4 deletions scopes/lanes/lanes/lane.cmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,18 +254,20 @@ it is useful e.g. when having multiple lanes with the same name, but with differ
}

export class LaneChangeScopeCmd implements Command {
name = 'change-scope <lane-name> <remote-scope-name>';
name = 'change-scope <remote-scope-name>';
description = `changes the remote scope of a lane`;
extendedDescription = 'NOTE: available only before the lane is exported to the remote';
alias = '';
options = [] as CommandOptions;
options = [
['lane-name', '', 'the name of the lane to change its remote scope. if not specified, the current lane is used'],
] as CommandOptions;
loader = true;
migration = true;

constructor(private lanes: LanesMain) {}

async report([localName, remoteScope]: [string, string]): Promise<string> {
const { remoteScopeBefore } = await this.lanes.changeScope(localName, remoteScope);
async report([remoteScope]: [string], { laneName }: { laneName?: string }): Promise<string> {
const { remoteScopeBefore, localName } = await this.lanes.changeScope(remoteScope, laneName);
return `the remote-scope of ${chalk.bold(localName)} has been changed from ${chalk.bold(
remoteScopeBefore
)} to ${chalk.bold(remoteScope)}`;
Expand Down
19 changes: 13 additions & 6 deletions scopes/lanes/lanes/lanes.main.runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,14 +356,21 @@ if you wish to keep ${scope} scope, please re-run the command with "--fork-lane-
return { laneId };
}

async changeScope(laneName: string, remoteScope: string): Promise<{ remoteScopeBefore: string }> {
async changeScope(remoteScope: string, laneName?: string): Promise<{ remoteScopeBefore: string; localName: string }> {
if (!this.workspace) {
throw new BitError(`unable to change-scope of a lane outside of Bit workspace`);
}
const laneNameWithoutScope = laneName.includes(LANE_REMOTE_DELIMITER)
? laneName.split(LANE_REMOTE_DELIMITER)[1]
: laneName;
const laneId = await this.scope.legacyScope.lanes.parseLaneIdFromString(laneName);
let laneId: LaneId;
let laneNameWithoutScope: string;
if (laneName) {
laneNameWithoutScope = laneName.includes(LANE_REMOTE_DELIMITER)
? laneName.split(LANE_REMOTE_DELIMITER)[1]
: laneName;
laneId = await this.scope.legacyScope.lanes.parseLaneIdFromString(laneName);
} else {
laneId = this.workspace.getCurrentLaneId();
laneNameWithoutScope = laneId.name;
}
const lane = await this.loadLane(laneId);
if (!lane) {
throw new BitError(`unable to find a local lane "${laneName}"`);
Expand All @@ -388,7 +395,7 @@ please create a new lane instead, which will include all components of this lane
this.workspace.consumer.bitMap.setCurrentLane(newLaneId, false);
await this.workspace.consumer.onDestroy();

return { remoteScopeBefore };
return { remoteScopeBefore, localName: laneNameWithoutScope };
}

/**
Expand Down