mirror of
https://github.com/tiktok/sparo.git
synced 2025-02-17 00:21:14 -05:00
feat: sparo checkout support rush selectors from cli input
This commit is contained in:
parent
6790cd2c67
commit
49250d88bb
2 changed files with 47 additions and 8 deletions
|
@ -14,6 +14,8 @@ export interface ICheckoutCommandOptions {
|
|||
B?: boolean;
|
||||
startPoint?: string;
|
||||
addProfile?: string[];
|
||||
to?: string[];
|
||||
from?: string[];
|
||||
}
|
||||
|
||||
type ICheckoutTargetKind = 'branch' | 'tag' | 'commit' | 'filePath';
|
||||
|
@ -43,6 +45,7 @@ export class CheckoutCommand implements ICommand<ICheckoutCommandOptions> {
|
|||
* have been implemented, while other scenarios are yet to be implemented.
|
||||
* 1. sparo checkout [-b|-B] <new-branch> [start-point] [--profile <profile...>]
|
||||
* 2. sparo checkout [branch] [--profile <profile...>]
|
||||
* 3. sparo checkout [branch] [--to <project-name...>]
|
||||
*
|
||||
* TODO: implement more checkout functionalities
|
||||
*/
|
||||
|
@ -67,7 +70,11 @@ export class CheckoutCommand implements ICommand<ICheckoutCommandOptions> {
|
|||
.array('profile')
|
||||
.default('profile', [])
|
||||
.array('add-profile')
|
||||
.default('add-profile', []);
|
||||
.default('add-profile', [])
|
||||
.array('to')
|
||||
.default('to', [])
|
||||
.array('from')
|
||||
.default('from', []);
|
||||
}
|
||||
|
||||
public handler = async (
|
||||
|
@ -76,7 +83,9 @@ export class CheckoutCommand implements ICommand<ICheckoutCommandOptions> {
|
|||
): Promise<void> => {
|
||||
const { _gitService: gitService } = this;
|
||||
terminalService.terminal.writeDebugLine(`got args in checkout command: ${JSON.stringify(args)}`);
|
||||
const { b, B, startPoint } = args;
|
||||
const { b, B, startPoint, to, from } = args;
|
||||
const toProjects: Set<string> = new Set(to);
|
||||
const fromProjects: Set<string> = new Set(from);
|
||||
|
||||
let branch: string | undefined = args.branch;
|
||||
|
||||
|
@ -209,7 +218,9 @@ export class CheckoutCommand implements ICommand<ICheckoutCommandOptions> {
|
|||
// Sync local sparse checkout state with given profiles.
|
||||
await this._sparoProfileService.syncProfileState({
|
||||
profiles: isNoProfile ? undefined : profiles,
|
||||
addProfiles
|
||||
addProfiles,
|
||||
fromProjects,
|
||||
toProjects
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
|
@ -227,10 +227,14 @@ ${availableProfiles.join(',')}
|
|||
*/
|
||||
public async syncProfileState({
|
||||
profiles,
|
||||
addProfiles
|
||||
addProfiles,
|
||||
fromProjects,
|
||||
toProjects
|
||||
}: {
|
||||
profiles?: Set<string>;
|
||||
addProfiles?: Set<string>;
|
||||
fromProjects?: Set<string>;
|
||||
toProjects?: Set<string>;
|
||||
}): Promise<void> {
|
||||
this._localState.reset();
|
||||
const allProfiles: string[] = Array.from([...(profiles ?? []), ...(addProfiles ?? [])]);
|
||||
|
@ -239,11 +243,11 @@ ${availableProfiles.join(',')}
|
|||
`Syncing checkout with these Sparo profiles:\n${allProfiles.join(', ')}`
|
||||
);
|
||||
} else if (allProfiles.length === 1) {
|
||||
this._terminalService.terminal.writeLine(
|
||||
`Syncing checkout with the Sparo profile: ${allProfiles[0]}`
|
||||
);
|
||||
this._terminalService.terminal.writeLine(`Syncing checkout with the Sparo profile: ${allProfiles[0]}`);
|
||||
} else {
|
||||
this._terminalService.terminal.writeLine('Syncing checkout with the Sparo skeleton (no profile selection)');
|
||||
this._terminalService.terminal.writeLine(
|
||||
'Syncing checkout with the Sparo skeleton (no profile selection)'
|
||||
);
|
||||
}
|
||||
this._terminalService.terminal.writeLine();
|
||||
if (!profiles || profiles.size === 0) {
|
||||
|
@ -298,5 +302,29 @@ ${availableProfiles.join(',')}
|
|||
checkoutAction: 'add'
|
||||
});
|
||||
}
|
||||
|
||||
// handle case of `sparo checkout --to project-A project-B --from project-C project-D
|
||||
const toSelector: Set<string> = toProjects || new Set();
|
||||
const fromSelector: Set<string> = toProjects || new Set();
|
||||
// If Rush Selector --to <projects> is specified, using `git sparse-checkout add` to add folders of the projects specified
|
||||
const projectsSelections: ISelection[] = [];
|
||||
|
||||
for (const project of toSelector) {
|
||||
projectsSelections.push({
|
||||
selector: '--to',
|
||||
argument: project
|
||||
});
|
||||
}
|
||||
for (const project of fromSelector) {
|
||||
projectsSelections.push({
|
||||
selector: '--from',
|
||||
argument: project
|
||||
});
|
||||
}
|
||||
|
||||
await this._gitSparseCheckoutService.checkoutAsync({
|
||||
selections: projectsSelections,
|
||||
checkoutAction: 'add'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue