From b70a0c0ee03732273c5db5c92d65a4220e346bc5 Mon Sep 17 00:00:00 2001 From: qun <68707557+L-Qun@users.noreply.github.com> Date: Wed, 28 Feb 2024 16:29:49 +0000 Subject: [PATCH] chore: support for cloning a specify branch --- apps/sparo-lib/src/cli/commands/clone.ts | 5 +++++ apps/sparo-lib/src/services/GitCloneService.ts | 7 +++++-- common/changes/sparo/main_2024-02-28-16-29.json | 10 ++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 common/changes/sparo/main_2024-02-28-16-29.json diff --git a/apps/sparo-lib/src/cli/commands/clone.ts b/apps/sparo-lib/src/cli/commands/clone.ts index c78fc50..26b7fba 100644 --- a/apps/sparo-lib/src/cli/commands/clone.ts +++ b/apps/sparo-lib/src/cli/commands/clone.ts @@ -45,6 +45,11 @@ export class CloneCommand implements ICommand { default: false, type: 'boolean' }) + .option('branch', { + alias: 'b', + describe: 'Specify a branch to clone', + type: 'string' + }) .check((argv) => { if (!argv.repository) { return 'You must specify a repository to clone.'; diff --git a/apps/sparo-lib/src/services/GitCloneService.ts b/apps/sparo-lib/src/services/GitCloneService.ts index c6ea5ee..77e8ff4 100644 --- a/apps/sparo-lib/src/services/GitCloneService.ts +++ b/apps/sparo-lib/src/services/GitCloneService.ts @@ -9,6 +9,7 @@ import { TerminalService } from './TerminalService'; export interface ICloneOptions { repository: string; directory: string; + branch?: string; } @Service() @@ -64,7 +65,7 @@ an empty directory.`); terminal.writeDebugLine('full clone done'); } - public bloblessClone({ repository, directory }: ICloneOptions): void { + public bloblessClone({ repository, directory, branch }: ICloneOptions): void { const { terminal } = this._terminalService; terminal.writeDebugLine('blobless clone start...'); @@ -73,6 +74,7 @@ an empty directory.`); '--filter=blob:none', '--sparse', '--single-branch', + ...(branch ? ['--branch', branch] : []), repository, directory ]; @@ -85,7 +87,7 @@ an empty directory.`); terminal.writeDebugLine('blobless clone done'); } - public treelessClone({ repository, directory }: ICloneOptions): void { + public treelessClone({ repository, directory, branch }: ICloneOptions): void { const { terminal } = this._terminalService; terminal.writeDebugLine('treeless clone start...'); @@ -94,6 +96,7 @@ an empty directory.`); '--filter=tree:0', '--sparse', '--single-branch', + ...(branch ? ['--branch', branch] : []), repository, directory ]; diff --git a/common/changes/sparo/main_2024-02-28-16-29.json b/common/changes/sparo/main_2024-02-28-16-29.json new file mode 100644 index 0000000..16ecd9b --- /dev/null +++ b/common/changes/sparo/main_2024-02-28-16-29.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "sparo", + "comment": "support for cloning a specify branch", + "type": "none" + } + ], + "packageName": "sparo" +} \ No newline at end of file