@@ -7,17 +7,15 @@ import { adjectives, animals, colors, NumberDictionary, uniqueNamesGenerator } f
77import vscode from 'vscode' ;
88import { Repository } from '../../api/api' ;
99import Logger from '../../common/logger' ;
10+ import { BRANCH_RANDOM_NAME_DICTIONARY , BRANCH_WHITESPACE_CHAR , GIT } from '../../common/settingKeys' ;
1011import { RepoInfo } from '../common' ;
1112
1213export class GitOperationsManager {
1314 constructor ( private loggerID : string ) { }
1415
1516 async commitAndPushChanges ( repoInfo : RepoInfo ) {
1617 const { repository, remote, baseRef } = repoInfo ;
17- const config = vscode . workspace . getConfiguration ( 'git' ) ;
18- const branchWhitespaceChar = config . get < string > ( 'branchWhitespaceChar' ) ! ;
19-
20- const asyncBranch = await this . generateRandomBranchName ( repository , 'copilot' , branchWhitespaceChar ) ;
18+ const asyncBranch = await this . generateRandomBranchName ( repository , 'copilot' ) ;
2119
2220 try {
2321 await repository . createBranch ( asyncBranch , true ) ;
@@ -144,10 +142,17 @@ export class GitOperationsManager {
144142 }
145143
146144 // Adapted from https://github.com/microsoft/vscode/blob/e35e3b4e057450ea3d90c724fae5e3e9619b96fe/extensions/git/src/commands.ts#L3007
147- private async generateRandomBranchName ( repository : Repository , prefix : string , separator : string ) : Promise < string > {
148- const config = vscode . workspace . getConfiguration ( 'git' ) ;
149- const branchRandomNameDictionary = config . get < string [ ] > ( 'branchRandomName.dictionary' ) ! ;
145+ private async generateRandomBranchName ( repository : Repository , prefix : string ) : Promise < string > {
146+ const config = vscode . workspace . getConfiguration ( GIT ) ;
147+ const branchWhitespaceChar = config . get < string > ( BRANCH_WHITESPACE_CHAR ) ;
148+ const branchRandomNameDictionary = config . get < string [ ] > ( BRANCH_RANDOM_NAME_DICTIONARY ) ;
149+
150+ // Default to legacy behaviour if config mismatches core
151+ if ( ! branchWhitespaceChar || ! branchRandomNameDictionary ) {
152+ return `copilot/vscode${ Date . now ( ) } ` ;
153+ }
150154
155+ const separator = branchWhitespaceChar ;
151156 const dictionaries : string [ ] [ ] = [ ] ;
152157 for ( const dictionary of branchRandomNameDictionary ) {
153158 if ( dictionary . toLowerCase ( ) === 'adjectives' ) {
@@ -170,11 +175,11 @@ export class GitOperationsManager {
170175
171176 // 5 attempts to generate a random branch name
172177 for ( let index = 0 ; index < 5 ; index ++ ) {
173- const randomName = prefix + '/' + uniqueNamesGenerator ( {
178+ const randomName = ` ${ prefix } / ${ uniqueNamesGenerator ( {
174179 dictionaries,
175180 length : dictionaries . length ,
176181 separator
177- } ) ;
182+ } ) } ` ;
178183
179184 // Check for local ref conflict
180185 const refs = await repository . getRefs ?.( { pattern : `refs/heads/${ randomName } ` } ) ;
0 commit comments