@@ -29,11 +29,11 @@ function isAvoidableDir(dir: string): boolean {
29
29
) ;
30
30
}
31
31
32
- async function isGitRepo ( dirUri : vscode . Uri ) {
32
+ export async function isGitRepository ( dirUri : vscode . Uri ) {
33
33
const gitFolder = vscode . Uri . joinPath ( dirUri , '.git' ) ;
34
34
try {
35
- await vscode . workspace . fs . stat ( gitFolder ) ;
36
- return true ;
35
+ const stat = await vscode . workspace . fs . stat ( gitFolder ) ;
36
+ return stat . type === vscode . FileType . Directory ;
37
37
} catch ( error ) {
38
38
return false ;
39
39
}
@@ -44,7 +44,6 @@ export class Opener {
44
44
public readonly repoUri ?: string ;
45
45
public readonly file ?: string ;
46
46
public readonly repoRef ?: string ;
47
-
48
47
public readonly range ?: vscode . Range ;
49
48
50
49
constructor (
@@ -81,46 +80,52 @@ export class Opener {
81
80
) ;
82
81
83
82
if ( correctWorkspace ) {
84
- // did the user asked for a particular ref?
85
- const gitRepo = await this . git ?. openRepository ( correctWorkspace . uri ) ;
86
- if ( gitRepo && this . repoRef ) {
87
- // are we in the correct ref?
88
- let currentCommit = ( await this . getCurrentCommit ( gitRepo ) ) ?. commit ;
89
- let repoRefCommit = await gitRepo . getCommit ( this . repoRef ) ;
90
- console . log ( `CurrentCommit ${ currentCommit } === ${ repoRefCommit . hash } ` ) ;
91
- if (
92
- currentCommit &&
93
- repoRefCommit &&
94
- currentCommit !== repoRefCommit . hash
95
- ) {
96
- // it seems that's not the case!!
97
- // ask the user if they want to checkout the correct branch
98
- const response = await vscode . window . showInformationMessage (
99
- `It seems that you're not in the correct branch. Do you want to checkout ${ this . repoRef } ?` ,
100
- 'Yes' ,
101
- 'No' ,
102
- ) ;
103
- if ( response === 'Yes' ) {
104
- await gitRepo . checkout ( this . repoRef ) ;
105
- }
83
+ await this . openWorkspace ( correctWorkspace ) ;
84
+ } else {
85
+ // it's not in the correct workspace, let's open it in a new window
86
+ await this . openNewWorkspace ( true ) ;
87
+ }
88
+ }
89
+
90
+ private async openWorkspace (
91
+ workspace : vscode . WorkspaceFolder ,
92
+ ) : Promise < void > {
93
+ // did the user ask for a particular ref?
94
+ const gitRepo = await this . git ?. openRepository ( workspace . uri ) ;
95
+ if ( gitRepo && this . repoRef ) {
96
+ // are we in the correct ref?
97
+ const currentCommit = ( await this . getCurrentCommit ( gitRepo ) ) ?. commit ;
98
+ const repoRefCommit = await gitRepo . getCommit ( this . repoRef ) ;
99
+ console . log ( `CurrentCommit ${ currentCommit } === ${ repoRefCommit . hash } ` ) ;
100
+ if (
101
+ currentCommit &&
102
+ repoRefCommit &&
103
+ currentCommit !== repoRefCommit . hash
104
+ ) {
105
+ // it seems that's not the case!!
106
+ // ask the user if they want to checkout the correct branch
107
+ const response = await vscode . window . showInformationMessage (
108
+ `It seems that you're not in the correct branch. Do you want to checkout ${ this . repoRef } ?` ,
109
+ 'Yes' ,
110
+ 'No' ,
111
+ ) ;
112
+ if ( response === 'Yes' ) {
113
+ await gitRepo . checkout ( this . repoRef ) ;
106
114
}
107
- } else {
108
- console . log ( 'NO GIT REPO????' ) ;
109
115
}
116
+ } else {
117
+ console . log ( 'NO GIT REPO????' ) ;
118
+ }
110
119
111
- if ( ! this . file ) {
112
- // we wanted to open precisely this particular repo (not a file) which is already open.
113
- return ;
114
- }
120
+ if ( ! this . file ) {
121
+ // we wanted to open precisely this particular repo (not a file) which is already open.
122
+ return ;
123
+ }
115
124
116
- // for the moment, we'll check that the file exists (in case it has been deleted in the current branch)
117
- const files = await vscode . workspace . findFiles ( this . file ) ;
118
- if ( files ) {
119
- await this . openFile ( correctWorkspace , this . file ) ;
120
- }
121
- } else {
122
- // it's not in the correct workspace, let's open it in a new window
123
- await this . openNewWorkspace ( true ) ;
125
+ // for the moment, we'll check that the file exists (in case it has been deleted in the current branch)
126
+ const files = await vscode . workspace . findFiles ( this . file ) ;
127
+ if ( files ) {
128
+ await this . openFile ( workspace , this . file ) ;
124
129
}
125
130
}
126
131
@@ -129,7 +134,7 @@ export class Opener {
129
134
const knownRepoInfo = await getOpenedRepoHistory ( this . context ) ;
130
135
const knownRepo = knownRepoInfo [ this . repoName ] ;
131
136
console . log ( `knownRepo ${ this . repoName } : ${ knownRepo } ` ) ;
132
- // if the repo is not found in the history, we're going to search it in the config roots
137
+ // if the repo is not found in the history, we're going to search for it in the config roots
133
138
const repoPath = knownRepo
134
139
? vscode . Uri . file ( knownRepo )
135
140
: await this . findFolderInConfigRoots ( ) ;
@@ -248,7 +253,7 @@ export class Opener {
248
253
continue ;
249
254
}
250
255
const dirUri = vscode . Uri . joinPath ( dir , itemName ) ;
251
- if ( itemName === this . repoName && ( await isGitRepo ( dirUri ) ) ) {
256
+ if ( itemName === this . repoName && ( await isGitRepository ( dirUri ) ) ) {
252
257
// found!
253
258
return dirUri ;
254
259
} else {
@@ -320,9 +325,8 @@ export class Opener {
320
325
: process . platform === 'darwin'
321
326
? 'gitFoldersMac'
322
327
: 'gitFolders' ;
323
- const roots = ( config . get ( prop ) ||
324
- config . get ( 'gitFolders' ) ||
325
- [ ] ) as string [ ] ;
328
+ const roots =
329
+ config . get < string [ ] > ( prop ) || config . get < string [ ] > ( 'gitFolders' ) || [ ] ;
326
330
return roots ;
327
331
}
328
332
0 commit comments