diff --git a/apps/sparo-lib/src/cli/commands/cmd-list.ts b/apps/sparo-lib/src/cli/commands/cmd-list.ts index 8d95350..99ee585 100644 --- a/apps/sparo-lib/src/cli/commands/cmd-list.ts +++ b/apps/sparo-lib/src/cli/commands/cmd-list.ts @@ -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, diff --git a/apps/sparo-lib/src/cli/commands/pull.ts b/apps/sparo-lib/src/cli/commands/pull.ts index cd16a09..0f1695d 100644 --- a/apps/sparo-lib/src/cli/commands/pull.ts +++ b/apps/sparo-lib/src/cli/commands/pull.ts @@ -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 { - 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 { public builder(yargs: Argv<{}>): void { /** - * sparo pull [remote] [branch] --profile --add-profile --no-profile + * sparo pull [repository] [refsepc...] [--profile | --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 | --no-profile]' + ); } public handler = async ( @@ -46,17 +44,12 @@ export class PullCommand implements ICommand { 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 diff --git a/apps/sparo-lib/src/logic/LocalState.ts b/apps/sparo-lib/src/logic/LocalState.ts index b7cee6e..577cab1 100644 --- a/apps/sparo-lib/src/logic/LocalState.ts +++ b/apps/sparo-lib/src/logic/LocalState.ts @@ -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'); } }