From 9aadefbcbd8a467354dc161432bf33a853834918 Mon Sep 17 00:00:00 2001 From: Cheng Liu Date: Tue, 9 Apr 2024 15:51:05 -0700 Subject: [PATCH 1/4] feat: sparo pull --- apps/sparo-lib/src/cli/commands/cmd-list.ts | 5 ++-- apps/sparo-lib/src/cli/commands/pull.ts | 33 ++++++++------------- apps/sparo-lib/src/logic/LocalState.ts | 2 +- 3 files changed, 16 insertions(+), 24 deletions(-) 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'); } } From c5900b7dade3583549f0cef4eb475dfb9e9aad57 Mon Sep 17 00:00:00 2001 From: Cheng Liu Date: Tue, 9 Apr 2024 16:04:42 -0700 Subject: [PATCH 2/4] feat: update website for sparo pull and sparo git-pull --- apps/sparo-lib/src/cli/commands/pull.ts | 8 +++++--- apps/website/docs/pages/commands/overview.md | 4 ++-- apps/website/docs/pages/commands/sparo_git-pull.md | 11 +++++++++++ apps/website/docs/pages/commands/sparo_pull.md | 14 ++++++++++++++ apps/website/sidebars.js | 2 ++ 5 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 apps/website/docs/pages/commands/sparo_git-pull.md create mode 100644 apps/website/docs/pages/commands/sparo_pull.md diff --git a/apps/sparo-lib/src/cli/commands/pull.ts b/apps/sparo-lib/src/cli/commands/pull.ts index 0f1695d..a1a3f90 100644 --- a/apps/sparo-lib/src/cli/commands/pull.ts +++ b/apps/sparo-lib/src/cli/commands/pull.ts @@ -19,7 +19,7 @@ export class PullCommand implements ICommand { @inject(GitService) private _gitService!: GitService; @inject(SparoProfileService) private _sparoProfileService!: SparoProfileService; - public builder(yargs: Argv<{}>): void { + public builder = (yargs: Argv<{}>): void => { /** * sparo pull [repository] [refsepc...] [--profile | --no-profile] * @@ -32,9 +32,11 @@ export class PullCommand implements ICommand { .default('profile', []) .parserConfiguration({ 'unknown-options-as-args': true }) .usage( - 'Usage: sparo pull [options] [repository] [refsepc...] [--profile | --no-profile]' + '$0 pull [options] [repository] [refsepc...] [--profile | --no-profile]' + + '\n\n' + + this.description ); - } + }; public handler = async ( args: ArgumentsCamelCase, diff --git a/apps/website/docs/pages/commands/overview.md b/apps/website/docs/pages/commands/overview.md index 9c8dec9..166189d 100644 --- a/apps/website/docs/pages/commands/overview.md +++ b/apps/website/docs/pages/commands/overview.md @@ -12,13 +12,13 @@ Sparo has four kinds of subcommands: - `sparo checkout` - `sparo clone` - `sparo fetch` - - `sparo pull` _(not implemented yet; currently mirrors `git pull`)_ + - `sparo pull` 3. **Renamed subcommands** are the mirrored versions of the four enhanced subcommands. They are renamed to add a `git-` prefix: - `sparo git-checkout` - `sparo git-clone` - `sparo git-fetch` - - `sparo git-pull` _(not implemented yet)_ + - `sparo git-pull` 4. **Auxiliary subcommands** are new subcommands that provide Sparo-specific functionality. They are: - `sparo auto-config` diff --git a/apps/website/docs/pages/commands/sparo_git-pull.md b/apps/website/docs/pages/commands/sparo_git-pull.md new file mode 100644 index 0000000..6019057 --- /dev/null +++ b/apps/website/docs/pages/commands/sparo_git-pull.md @@ -0,0 +1,11 @@ +--- +title: sparo git-pull +--- + +This is the [mirrored subcommand](./overview.md) for `git pull`. It has the same functionality as the corresponding Git subcommand, but supports Sparo's optional anonymous timing metrics collection. + +``` +sparo git-pull [] [ […​]] +``` + +See [git pull](https://git-scm.com/docs/git-pull) in the Git documentation for details. diff --git a/apps/website/docs/pages/commands/sparo_pull.md b/apps/website/docs/pages/commands/sparo_pull.md new file mode 100644 index 0000000..54415ce --- /dev/null +++ b/apps/website/docs/pages/commands/sparo_pull.md @@ -0,0 +1,14 @@ +--- +title: sparo pull +--- + +``` +sparo pull [options] [repository] [refsepc...] [--profile | +--no-profile] + +Incorporates changes from a remote repository into the current branch. + +Options: + --help Show help [boolean] + --profile [array] [default: []] +``` \ No newline at end of file diff --git a/apps/website/sidebars.js b/apps/website/sidebars.js index b5fbcb9..e90ca81 100644 --- a/apps/website/sidebars.js +++ b/apps/website/sidebars.js @@ -62,9 +62,11 @@ const sidebars = { 'pages/commands/sparo_checkout', 'pages/commands/sparo_clone', 'pages/commands/sparo_fetch', + 'pages/commands/sparo_pull', 'pages/commands/sparo_git-checkout', 'pages/commands/sparo_git-clone', 'pages/commands/sparo_git-fetch', + 'pages/commands/sparo_git-pull', 'pages/commands/sparo_init-profile', 'pages/commands/sparo_list-profiles' ] From f5ecf8e1b9068b31510a7caeed8704fd8ab4be44 Mon Sep 17 00:00:00 2001 From: Cheng Liu Date: Tue, 9 Apr 2024 16:05:20 -0700 Subject: [PATCH 3/4] chore: rush change --- .../sparo/feat-sparo-pull_2024-04-09-23-05.json | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 common/changes/sparo/feat-sparo-pull_2024-04-09-23-05.json diff --git a/common/changes/sparo/feat-sparo-pull_2024-04-09-23-05.json b/common/changes/sparo/feat-sparo-pull_2024-04-09-23-05.json new file mode 100644 index 0000000..a21b716 --- /dev/null +++ b/common/changes/sparo/feat-sparo-pull_2024-04-09-23-05.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "sparo", + "comment": "Add \"sparo pull\" command", + "type": "minor" + } + ], + "packageName": "sparo" +} \ No newline at end of file From c4ed216ab2083fcc97d4ce1c62049a676bd4a008 Mon Sep 17 00:00:00 2001 From: Cheng Liu Date: Tue, 9 Apr 2024 16:09:44 -0700 Subject: [PATCH 4/4] chore: update build test --- build-tests/sparo-output-test/etc/top-level-help.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build-tests/sparo-output-test/etc/top-level-help.txt b/build-tests/sparo-output-test/etc/top-level-help.txt index 38ef5bc..1386a66 100644 --- a/build-tests/sparo-output-test/etc/top-level-help.txt +++ b/build-tests/sparo-output-test/etc/top-level-help.txt @@ -20,6 +20,8 @@ Commands: HEAD to set the specified branch as the current branch. sparo fetch [remote] [branch] fetch remote branch to local + sparo pull Incorporates changes from a remote + repository into the current branch. sparo git-clone original git clone command sparo git-checkout original git checkout command sparo git-fetch original git fetch command