mirror of
https://github.com/tiktok/sparo.git
synced 2024-11-23 07:38:15 -05:00
feat: sparo pull
This commit is contained in:
parent
7babbfaf5f
commit
9aadefbcbd
3 changed files with 16 additions and 24 deletions
|
@ -11,7 +11,7 @@ import { GitCheckoutCommand } from './git-checkout';
|
|||
import { GitFetchCommand } from './git-fetch';
|
||||
import { GitPullCommand } from './git-pull';
|
||||
import { InitProfileCommand } from './init-profile';
|
||||
// import { PullCommand } from './pull';
|
||||
import { PullCommand } from './pull';
|
||||
|
||||
// When adding new Sparo subcommands, remember to update this doc page:
|
||||
// https://github.com/tiktok/sparo/blob/main/apps/website/docs/pages/commands/overview.md
|
||||
|
@ -23,8 +23,7 @@ export const COMMAND_LIST: Constructable[] = [
|
|||
CloneCommand,
|
||||
CheckoutCommand,
|
||||
FetchCommand,
|
||||
// Should be introduced after sparo merge|rebase
|
||||
// PullCommand,
|
||||
PullCommand,
|
||||
|
||||
// The commands customized by Sparo require a mirror command to Git
|
||||
GitCloneCommand,
|
||||
|
|
|
@ -8,15 +8,12 @@ import type { ICommand } from './base';
|
|||
import type { TerminalService } from '../../services/TerminalService';
|
||||
|
||||
export interface IPullCommandOptions {
|
||||
branch?: string;
|
||||
remote?: string;
|
||||
profile?: string[];
|
||||
addProfile?: string[];
|
||||
}
|
||||
|
||||
@Command()
|
||||
export class PullCommand implements ICommand<IPullCommandOptions> {
|
||||
public cmd: string = 'pull [remote] [branch]';
|
||||
public cmd: string = 'pull';
|
||||
public description: string = 'Incorporates changes from a remote repository into the current branch.';
|
||||
|
||||
@inject(GitService) private _gitService!: GitService;
|
||||
|
@ -24,18 +21,19 @@ export class PullCommand implements ICommand<IPullCommandOptions> {
|
|||
|
||||
public builder(yargs: Argv<{}>): void {
|
||||
/**
|
||||
* sparo pull [remote] [branch] --profile <profile_name> --add-profile <profile_name> --no-profile
|
||||
* sparo pull [repository] [refsepc...] [--profile <profile_name> | --no-profile]
|
||||
*
|
||||
* sparo pull origin
|
||||
*
|
||||
* sparo pull origin master
|
||||
*/
|
||||
yargs
|
||||
.positional('remote', { type: 'string' })
|
||||
.positional('branch', { type: 'string' })
|
||||
.string('remote')
|
||||
.string('branch')
|
||||
.boolean('full')
|
||||
.array('profile')
|
||||
.default('profile', [])
|
||||
.array('add-profile')
|
||||
.default('add-profile', []);
|
||||
.parserConfiguration({ 'unknown-options-as-args': true })
|
||||
.usage(
|
||||
'Usage: sparo pull [options] [repository] [refsepc...] [--profile <profile_name> | --no-profile]'
|
||||
);
|
||||
}
|
||||
|
||||
public handler = async (
|
||||
|
@ -46,17 +44,12 @@ export class PullCommand implements ICommand<IPullCommandOptions> {
|
|||
const { terminal } = terminalService;
|
||||
|
||||
terminal.writeDebugLine(`got args in pull command: ${JSON.stringify(args)}`);
|
||||
const pullArgs: string[] = ['pull'];
|
||||
|
||||
const { branch, remote } = args;
|
||||
|
||||
if (branch && remote) {
|
||||
pullArgs.push(remote, branch);
|
||||
}
|
||||
// Collect anything that is not related to profile, pass down them to native git pull
|
||||
const pullArgs: string[] = args._ as string[];
|
||||
|
||||
const { isNoProfile, profiles, addProfiles } = await sparoProfileService.preprocessProfileArgs({
|
||||
profilesFromArg: args.profile ?? [],
|
||||
addProfilesFromArg: args.addProfile ?? []
|
||||
addProfilesFromArg: []
|
||||
});
|
||||
|
||||
// invoke native git pull command
|
||||
|
|
|
@ -91,6 +91,6 @@ export class LocalState {
|
|||
if (!repoRoot) {
|
||||
throw new Error('Running outside of the git repository folder');
|
||||
}
|
||||
return path.join(this._gitService.getRepoInfo().root, '.git/info/local-state.json');
|
||||
return path.join(repoRoot, '.git/info/local-state.json');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue