Skip to content

Commit 7318c90

Browse files
authored
Checkout specific branch during clone operation (microsoft#163705)
1 parent 0492b92 commit 7318c90

File tree

2 files changed

+5
-14
lines changed

2 files changed

+5
-14
lines changed

extensions/git/src/commands.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -571,22 +571,9 @@ export class CommandCenter {
571571

572572
const repositoryPath = await window.withProgress(
573573
opts,
574-
(progress, token) => this.git.clone(url!, { parentPath: parentPath!, progress, recursive: options.recursive }, token)
574+
(progress, token) => this.git.clone(url!, { parentPath: parentPath!, progress, recursive: options.recursive, ref: options.ref }, token)
575575
);
576576

577-
const refToCheckoutAfterClone = options.ref;
578-
if (refToCheckoutAfterClone !== undefined) {
579-
await window.withProgress(
580-
{
581-
location: ProgressLocation.Notification,
582-
title: localize('checking out ref', "Checking out ref '{0}'...", options.ref)
583-
}, async () => {
584-
await this.model.openRepository(repositoryPath);
585-
const repository = this.model.getRepository(repositoryPath);
586-
await repository?.checkout(refToCheckoutAfterClone);
587-
});
588-
}
589-
590577
const config = workspace.getConfiguration('git');
591578
const openAfterClone = config.get<'always' | 'alwaysNewWindow' | 'whenNoFolderOpen' | 'prompt'>('openAfterClone');
592579

extensions/git/src/git.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ export interface ICloneOptions {
361361
readonly parentPath: string;
362362
readonly progress: Progress<{ increment: number }>;
363363
readonly recursive?: boolean;
364+
readonly ref?: string;
364365
}
365366

366367
export class Git {
@@ -455,6 +456,9 @@ export class Git {
455456
if (options.recursive) {
456457
command.push('--recursive');
457458
}
459+
if (options.ref) {
460+
command.push('--branch', `'${options.ref}'`);
461+
}
458462
await this.exec(options.parentPath, command, {
459463
cancellationToken,
460464
env: { 'GIT_HTTP_USER_AGENT': this.userAgent },

0 commit comments

Comments
 (0)