Skip to content

Commit 8d28ffa

Browse files
authored
Allow ref checkout after protocol handler clone (microsoft#159481)
1 parent 0ddb3ae commit 8d28ffa

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

extensions/git/src/commands.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ export class CommandCenter {
457457
);
458458
}
459459

460-
async cloneRepository(url?: string, parentPath?: string, options: { recursive?: boolean } = {}): Promise<void> {
460+
async cloneRepository(url?: string, parentPath?: string, options: { recursive?: boolean; ref?: string } = {}): Promise<void> {
461461
if (!url || typeof url !== 'string') {
462462
url = await pickRemoteSource({
463463
providerLabel: provider => localize('clonefrom', "Clone from {0}", provider.name),
@@ -519,6 +519,11 @@ export class CommandCenter {
519519
(progress, token) => this.git.clone(url!, { parentPath: parentPath!, progress, recursive: options.recursive }, token)
520520
);
521521

522+
if (options.ref !== undefined) {
523+
const repository = this.model.getRepository(Uri.file(repositoryPath));
524+
await repository?.checkout(options.ref);
525+
}
526+
522527
const config = workspace.getConfiguration('git');
523528
const openAfterClone = config.get<'always' | 'alwaysNewWindow' | 'whenNoFolderOpen' | 'prompt'>('openAfterClone');
524529

@@ -596,8 +601,8 @@ export class CommandCenter {
596601
}
597602

598603
@command('git.clone')
599-
async clone(url?: string, parentPath?: string): Promise<void> {
600-
await this.cloneRepository(url, parentPath);
604+
async clone(url?: string, parentPath?: string, options?: { ref?: string }): Promise<void> {
605+
await this.cloneRepository(url, parentPath, options);
601606
}
602607

603608
@command('git.cloneRecursive')

extensions/git/src/protocolHandler.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export class GitProtocolHandler implements UriHandler {
2525

2626
private clone(uri: Uri): void {
2727
const data = querystring.parse(uri.query);
28+
const ref = data.ref;
2829

2930
if (!data.url) {
3031
console.warn('Failed to open URI:', uri);
@@ -36,6 +37,11 @@ export class GitProtocolHandler implements UriHandler {
3637
return;
3738
}
3839

40+
if (ref !== undefined && typeof ref !== 'string') {
41+
console.warn('Failed to open URI:', uri);
42+
return;
43+
}
44+
3945
let cloneUri: Uri;
4046
try {
4147
let rawUri = Array.isArray(data.url) ? data.url[0] : data.url;
@@ -56,7 +62,7 @@ export class GitProtocolHandler implements UriHandler {
5662
return;
5763
}
5864

59-
commands.executeCommand('git.clone', cloneUri.toString(true));
65+
commands.executeCommand('git.clone', cloneUri.toString(true), undefined, { ref: ref });
6066
}
6167

6268
dispose(): void {

0 commit comments

Comments
 (0)