Skip to content

Commit

Permalink
Merge pull request #64 from tiktok/feat-sparo-pull
Browse files Browse the repository at this point in the history
Feat sparo pull
  • Loading branch information
chengcyber authored Apr 12, 2024
2 parents 7babbfa + c4ed216 commit 40d68a0
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 28 deletions.
5 changes: 2 additions & 3 deletions apps/sparo-lib/src/cli/commands/cmd-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
39 changes: 17 additions & 22 deletions apps/sparo-lib/src/cli/commands/pull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,35 @@ 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;
@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
.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(
'$0 pull [options] [repository] [refsepc...] [--profile <profile_name> | --no-profile]' +
'\n\n' +
this.description
);
};

public handler = async (
args: ArgumentsCamelCase<IPullCommandOptions>,
Expand All @@ -46,17 +46,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
Expand Down
2 changes: 1 addition & 1 deletion apps/sparo-lib/src/logic/LocalState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
4 changes: 2 additions & 2 deletions apps/website/docs/pages/commands/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
11 changes: 11 additions & 0 deletions apps/website/docs/pages/commands/sparo_git-pull.md
Original file line number Diff line number Diff line change
@@ -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.
14 changes: 14 additions & 0 deletions apps/website/docs/pages/commands/sparo_pull.md
Original file line number Diff line number Diff line change
@@ -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: []]
```
2 changes: 2 additions & 0 deletions apps/website/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
]
Expand Down
2 changes: 2 additions & 0 deletions build-tests/sparo-output-test/etc/top-level-help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions common/changes/sparo/feat-sparo-pull_2024-04-09-23-05.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "sparo",
"comment": "Add \"sparo pull\" command",
"type": "minor"
}
],
"packageName": "sparo"
}

0 comments on commit 40d68a0

Please sign in to comment.