Skip to content

Commit

Permalink
Added gitCheckoutDefaultBranch command
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasArvidsson committed Jan 3, 2025
1 parent 7afe34b commit 46ea26a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ Many of the commands take arguments and return values that can only be used with

### Git commands

- `andreas.gitCheckoutDefaultBranch()`
Checkout default git branch.
- `andreas.getGitFileURL({ useSelection: boolean, useBranch: boolean }): string`
Get URL to Git repository file webpage. Optionally include selected line numbers.
- `andreas.getGitRepoURL(): string`
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "andreas-talon",
"displayName": "Andreas Talon",
"description": "VSCode extension used by Talon Voice",
"version": "3.56.1",
"version": "3.57.0",
"publisher": "AndreasArvidsson",
"license": "MIT",
"main": "./out/extension.js",
Expand Down Expand Up @@ -229,6 +229,11 @@
"title": "Get name for open tag.",
"enablement": "false"
},
{
"command": "andreas.gitCheckoutDefaultBranch",
"category": "Andreas",
"title": "Checkout default git branch."
},
{
"command": "andreas.getGitFileURL",
"category": "Andreas",
Expand Down
10 changes: 10 additions & 0 deletions src/commands/GitUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ export class GitUtil {
return getPlatform(repository).getPullRequestsURL();
}

async checkoutDefaultBranch() {
const repository = this.getRepository();
const branches = await repository.getBranches({});
const defaultBranch = branches.find((b) => b.name === "master" || b.name === "main");
if (defaultBranch == null) {
throw Error("Can't find default branch");
}
await repository.checkout(defaultBranch.name!);
}

private getRepository(): Repository {
const { repositories } = this.gitApi;
if (repositories.length === 0) {
Expand Down
1 change: 1 addition & 0 deletions src/commands/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export const commandDescriptions = {
),

// Git commands
gitCheckoutDefaultBranch: visible("Git", "Checkout default git branch."),
getGitFileURL: hidden(
"Git",
"Get URL to Git repository file webpage.",
Expand Down
1 change: 1 addition & 0 deletions src/commands/registerCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export function registerCommands(
getClassName: () => getText.getClassName(),
getOpenTagName: () => getText.getOpenTagName(),
// Git
gitCheckoutDefaultBranch: () => git.checkoutDefaultBranch(),
getGitFileURL: (p: GitParameters) => git.getGitFileURL(p),
getGitRepoURL: () => git.getGitRepoURL(),
getGitIssuesURL: () => git.getGitIssuesURL(),
Expand Down

0 comments on commit 46ea26a

Please sign in to comment.