Skip to content

Commit 46ea26a

Browse files
Added gitCheckoutDefaultBranch command
1 parent 7afe34b commit 46ea26a

File tree

5 files changed

+20
-1
lines changed

5 files changed

+20
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ Many of the commands take arguments and return values that can only be used with
6969

7070
### Git commands
7171

72+
- `andreas.gitCheckoutDefaultBranch()`
73+
Checkout default git branch.
7274
- `andreas.getGitFileURL({ useSelection: boolean, useBranch: boolean }): string`
7375
Get URL to Git repository file webpage. Optionally include selected line numbers.
7476
- `andreas.getGitRepoURL(): string`

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "andreas-talon",
33
"displayName": "Andreas Talon",
44
"description": "VSCode extension used by Talon Voice",
5-
"version": "3.56.1",
5+
"version": "3.57.0",
66
"publisher": "AndreasArvidsson",
77
"license": "MIT",
88
"main": "./out/extension.js",
@@ -229,6 +229,11 @@
229229
"title": "Get name for open tag.",
230230
"enablement": "false"
231231
},
232+
{
233+
"command": "andreas.gitCheckoutDefaultBranch",
234+
"category": "Andreas",
235+
"title": "Checkout default git branch."
236+
},
232237
{
233238
"command": "andreas.getGitFileURL",
234239
"category": "Andreas",

src/commands/GitUtil.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ export class GitUtil {
5555
return getPlatform(repository).getPullRequestsURL();
5656
}
5757

58+
async checkoutDefaultBranch() {
59+
const repository = this.getRepository();
60+
const branches = await repository.getBranches({});
61+
const defaultBranch = branches.find((b) => b.name === "master" || b.name === "main");
62+
if (defaultBranch == null) {
63+
throw Error("Can't find default branch");
64+
}
65+
await repository.checkout(defaultBranch.name!);
66+
}
67+
5868
private getRepository(): Repository {
5969
const { repositories } = this.gitApi;
6070
if (repositories.length === 0) {

src/commands/commands.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ export const commandDescriptions = {
115115
),
116116

117117
// Git commands
118+
gitCheckoutDefaultBranch: visible("Git", "Checkout default git branch."),
118119
getGitFileURL: hidden(
119120
"Git",
120121
"Get URL to Git repository file webpage.",

src/commands/registerCommands.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export function registerCommands(
6363
getClassName: () => getText.getClassName(),
6464
getOpenTagName: () => getText.getOpenTagName(),
6565
// Git
66+
gitCheckoutDefaultBranch: () => git.checkoutDefaultBranch(),
6667
getGitFileURL: (p: GitParameters) => git.getGitFileURL(p),
6768
getGitRepoURL: () => git.getGitRepoURL(),
6869
getGitIssuesURL: () => git.getGitIssuesURL(),

0 commit comments

Comments
 (0)