File tree Expand file tree Collapse file tree 5 files changed +20
-1
lines changed
Expand file tree Collapse file tree 5 files changed +20
-1
lines changed Original file line number Diff line number Diff 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 `
Original file line number Diff line number Diff line change 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" ,
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" ,
Original file line number Diff line number Diff 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 ) {
Original file line number Diff line number Diff 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." ,
Original file line number Diff line number Diff 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 ( ) ,
You can’t perform that action at this time.
0 commit comments