Merge pull request #64 from tiktok/feat-sparo-pull

Feat sparo pull
This commit is contained in:
Cheng Liu 2024-04-12 12:17:53 -07:00 committed by GitHub
commit 40d68a0687
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 61 additions and 28 deletions

View file

@ -11,7 +11,7 @@ import { GitCheckoutCommand } from './git-checkout';
import { GitFetchCommand } from './git-fetch'; import { GitFetchCommand } from './git-fetch';
import { GitPullCommand } from './git-pull'; import { GitPullCommand } from './git-pull';
import { InitProfileCommand } from './init-profile'; import { InitProfileCommand } from './init-profile';
// import { PullCommand } from './pull'; import { PullCommand } from './pull';
// When adding new Sparo subcommands, remember to update this doc page: // 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 // https://github.com/tiktok/sparo/blob/main/apps/website/docs/pages/commands/overview.md
@ -23,8 +23,7 @@ export const COMMAND_LIST: Constructable[] = [
CloneCommand, CloneCommand,
CheckoutCommand, CheckoutCommand,
FetchCommand, FetchCommand,
// Should be introduced after sparo merge|rebase PullCommand,
// PullCommand,
// The commands customized by Sparo require a mirror command to Git // The commands customized by Sparo require a mirror command to Git
GitCloneCommand, GitCloneCommand,

View file

@ -8,35 +8,35 @@ import type { ICommand } from './base';
import type { TerminalService } from '../../services/TerminalService'; import type { TerminalService } from '../../services/TerminalService';
export interface IPullCommandOptions { export interface IPullCommandOptions {
branch?: string;
remote?: string;
profile?: string[]; profile?: string[];
addProfile?: string[];
} }
@Command() @Command()
export class PullCommand implements ICommand<IPullCommandOptions> { 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.'; public description: string = 'Incorporates changes from a remote repository into the current branch.';
@inject(GitService) private _gitService!: GitService; @inject(GitService) private _gitService!: GitService;
@inject(SparoProfileService) private _sparoProfileService!: SparoProfileService; @inject(SparoProfileService) private _sparoProfileService!: SparoProfileService;
public builder(yargs: Argv<{}>): void { 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 yargs
.positional('remote', { type: 'string' })
.positional('branch', { type: 'string' })
.string('remote')
.string('branch')
.boolean('full')
.array('profile') .array('profile')
.default('profile', []) .default('profile', [])
.array('add-profile') .parserConfiguration({ 'unknown-options-as-args': true })
.default('add-profile', []); .usage(
} '$0 pull [options] [repository] [refsepc...] [--profile <profile_name> | --no-profile]' +
'\n\n' +
this.description
);
};
public handler = async ( public handler = async (
args: ArgumentsCamelCase<IPullCommandOptions>, args: ArgumentsCamelCase<IPullCommandOptions>,
@ -46,17 +46,12 @@ export class PullCommand implements ICommand<IPullCommandOptions> {
const { terminal } = terminalService; const { terminal } = terminalService;
terminal.writeDebugLine(`got args in pull command: ${JSON.stringify(args)}`); terminal.writeDebugLine(`got args in pull command: ${JSON.stringify(args)}`);
const pullArgs: string[] = ['pull']; // Collect anything that is not related to profile, pass down them to native git pull
const pullArgs: string[] = args._ as string[];
const { branch, remote } = args;
if (branch && remote) {
pullArgs.push(remote, branch);
}
const { isNoProfile, profiles, addProfiles } = await sparoProfileService.preprocessProfileArgs({ const { isNoProfile, profiles, addProfiles } = await sparoProfileService.preprocessProfileArgs({
profilesFromArg: args.profile ?? [], profilesFromArg: args.profile ?? [],
addProfilesFromArg: args.addProfile ?? [] addProfilesFromArg: []
}); });
// invoke native git pull command // invoke native git pull command

View file

@ -91,6 +91,6 @@ export class LocalState {
if (!repoRoot) { if (!repoRoot) {
throw new Error('Running outside of the git repository folder'); 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');
} }
} }

View file

@ -12,13 +12,13 @@ Sparo has four kinds of subcommands:
- `sparo checkout` - `sparo checkout`
- `sparo clone` - `sparo clone`
- `sparo fetch` - `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: 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-checkout`
- `sparo git-clone` - `sparo git-clone`
- `sparo git-fetch` - `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: 4. **Auxiliary subcommands** are new subcommands that provide Sparo-specific functionality. They are:
- `sparo auto-config` - `sparo auto-config`

View file

@ -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 [<options>] [<repository> [<refspec>…​]]
```
See [git pull](https://git-scm.com/docs/git-pull) in the Git documentation for details.

View file

@ -0,0 +1,14 @@
---
title: sparo pull
---
```
sparo pull [options] [repository] [refsepc...] [--profile <profile_name> |
--no-profile]
Incorporates changes from a remote repository into the current branch.
Options:
--help Show help [boolean]
--profile [array] [default: []]
```

View file

@ -62,9 +62,11 @@ const sidebars = {
'pages/commands/sparo_checkout', 'pages/commands/sparo_checkout',
'pages/commands/sparo_clone', 'pages/commands/sparo_clone',
'pages/commands/sparo_fetch', 'pages/commands/sparo_fetch',
'pages/commands/sparo_pull',
'pages/commands/sparo_git-checkout', 'pages/commands/sparo_git-checkout',
'pages/commands/sparo_git-clone', 'pages/commands/sparo_git-clone',
'pages/commands/sparo_git-fetch', 'pages/commands/sparo_git-fetch',
'pages/commands/sparo_git-pull',
'pages/commands/sparo_init-profile', 'pages/commands/sparo_init-profile',
'pages/commands/sparo_list-profiles' 'pages/commands/sparo_list-profiles'
] ]

View file

@ -20,6 +20,8 @@ Commands:
HEAD to set the specified branch as the HEAD to set the specified branch as the
current branch. current branch.
sparo fetch [remote] [branch] fetch remote branch to local 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-clone original git clone command
sparo git-checkout original git checkout command sparo git-checkout original git checkout command
sparo git-fetch original git fetch command sparo git-fetch original git fetch command

View file

@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "sparo",
"comment": "Add \"sparo pull\" command",
"type": "minor"
}
],
"packageName": "sparo"
}