Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow ref checkout after protocol handler clone #159481

Merged
merged 2 commits into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 8 additions & 3 deletions extensions/git/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ export class CommandCenter {
);
}

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

if (options.ref !== undefined) {
const repository = this.model.getRepository(Uri.file(repositoryPath));
await repository?.checkout(options.ref);
}

const config = workspace.getConfiguration('git');
const openAfterClone = config.get<'always' | 'alwaysNewWindow' | 'whenNoFolderOpen' | 'prompt'>('openAfterClone');

Expand Down Expand Up @@ -596,8 +601,8 @@ export class CommandCenter {
}

@command('git.clone')
async clone(url?: string, parentPath?: string): Promise<void> {
await this.cloneRepository(url, parentPath);
async clone(url?: string, parentPath?: string, options?: { ref?: string }): Promise<void> {
await this.cloneRepository(url, parentPath, options);
}

@command('git.cloneRecursive')
Expand Down
8 changes: 7 additions & 1 deletion extensions/git/src/protocolHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class GitProtocolHandler implements UriHandler {

private clone(uri: Uri): void {
const data = querystring.parse(uri.query);
const ref = data.ref;

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

if (ref !== undefined && typeof ref !== 'string') {
console.warn('Failed to open URI:', uri);
return;
}

let cloneUri: Uri;
try {
let rawUri = Array.isArray(data.url) ? data.url[0] : data.url;
Expand All @@ -56,7 +62,7 @@ export class GitProtocolHandler implements UriHandler {
return;
}

commands.executeCommand('git.clone', cloneUri.toString(true));
commands.executeCommand('git.clone', cloneUri.toString(true), undefined, { ref: ref });
}

dispose(): void {
Expand Down