diff --git a/README.md b/README.md index 44fe359..48ce8a4 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,8 @@ Many of the commands take arguments and return values that can only be used with ### Git commands +- `andreas.gitCheckout(branch: string)` + Checkout git branch. - `andreas.gitCheckoutDefaultBranch()` Checkout default git branch. - `andreas.getGitFileURL({ useSelection: boolean, useBranch: boolean }): string` diff --git a/package.json b/package.json index bc4033c..632494f 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "andreas-talon", "displayName": "Andreas Talon", "description": "VSCode extension used by Talon Voice", - "version": "3.57.0", + "version": "3.58.0", "publisher": "AndreasArvidsson", "license": "MIT", "main": "./out/extension.js", @@ -229,6 +229,11 @@ "title": "Get name for open tag.", "enablement": "false" }, + { + "command": "andreas.gitCheckout", + "category": "Andreas", + "title": "Checkout git branch." + }, { "command": "andreas.gitCheckoutDefaultBranch", "category": "Andreas", diff --git a/src/commands/GitUtil.ts b/src/commands/GitUtil.ts index 37cd530..3ca6dc5 100644 --- a/src/commands/GitUtil.ts +++ b/src/commands/GitUtil.ts @@ -14,7 +14,7 @@ export class GitUtil { this.gitApi = gitExtension.getAPI(1); } - getGitFileURL({ useSelection = false, useBranch = false }: GitParameters): string { + getFileURL({ useSelection = false, useBranch = false }: GitParameters): string { const { document, selections } = getActiveFileSchemaEditor(); const repository = this.getRepository(); const platform = getPlatform(repository); @@ -35,26 +35,35 @@ export class GitUtil { return platform.getFileUrl(commitOrBranch, relativeFilePath, range); } - getGitRepoURL(): string { + getRepoURL(): string { const repository = this.getRepository(); return getPlatform(repository).getRepoUrl(); } - getGitIssuesURL(): string { + getIssuesURL(): string { const repository = this.getRepository(); return getPlatform(repository).getIssuesUrl(); } - getGitNewIssueURL(): string { + getNewIssueURL(): string { const repository = this.getRepository(); return getPlatform(repository).getNewIssueUrl(); } - getGitPullRequestsURL(): string { + getPullRequestsURL(): string { const repository = this.getRepository(); return getPlatform(repository).getPullRequestsURL(); } + async checkout(branch: string) { + const repository = this.getRepository(); + try { + await repository.checkout(branch); + } catch (_error) { + throw Error(`Can't checkout branch '${branch}'`); + } + } + async checkoutDefaultBranch() { const repository = this.getRepository(); const branches = await repository.getBranches({}); diff --git a/src/commands/commands.ts b/src/commands/commands.ts index d6f792e..1a08604 100644 --- a/src/commands/commands.ts +++ b/src/commands/commands.ts @@ -115,6 +115,7 @@ export const commandDescriptions = { ), // Git commands + gitCheckout: visible("Git", "Checkout git branch.", undefined, "(branch: string)"), gitCheckoutDefaultBranch: visible("Git", "Checkout default git branch."), getGitFileURL: hidden( "Git", diff --git a/src/commands/registerCommands.ts b/src/commands/registerCommands.ts index 1d11b5e..fc6e0c2 100644 --- a/src/commands/registerCommands.ts +++ b/src/commands/registerCommands.ts @@ -63,12 +63,13 @@ export function registerCommands( getClassName: () => getText.getClassName(), getOpenTagName: () => getText.getOpenTagName(), // Git + gitCheckout: (branch: string) => git.checkout(branch), gitCheckoutDefaultBranch: () => git.checkoutDefaultBranch(), - getGitFileURL: (p: GitParameters) => git.getGitFileURL(p), - getGitRepoURL: () => git.getGitRepoURL(), - getGitIssuesURL: () => git.getGitIssuesURL(), - getGitNewIssueURL: () => git.getGitNewIssueURL(), - getGitPullRequestsURL: () => git.getGitPullRequestsURL(), + getGitFileURL: (p: GitParameters) => git.getFileURL(p), + getGitRepoURL: () => git.getRepoURL(), + getGitIssuesURL: () => git.getIssuesURL(), + getGitNewIssueURL: () => git.getNewIssueURL(), + getGitPullRequestsURL: () => git.getPullRequestsURL(), // Other getSetting, setSetting, @@ -86,14 +87,5 @@ export function registerCommands( function registerCommand(command: CommandId, callback: Callback): vscode.Disposable { const fullCommand = getFullCommand(command); - return vscode.commands.registerCommand(fullCommand, async (...args: unknown[]) => { - try { - return await Promise.resolve(callback(...args)); - } catch (ex) { - const err = ex as Error; - void vscode.window.showErrorMessage(err.message); - console.error(err.stack); - return undefined; - } - }); + return vscode.commands.registerCommand(fullCommand, callback); }