16
16
* SPDX-License-Identifier: Apache-2.0
17
17
***********************************************************************/
18
18
19
- import { window } from '@podman-desktop/api' ;
20
- import fs , { statSync , existsSync , mkdirSync , rmSync } from 'node:fs' ;
21
- import git from 'isomorphic-git' ;
19
+ import { env , window } from '@podman-desktop/api' ;
20
+ import fs , { existsSync , mkdirSync , type NoParamCallback , rmSync , statSync } from 'node:fs' ;
21
+ import git , { type CallbackFsClient } from 'isomorphic-git' ;
22
22
import http from 'isomorphic-git/http/node' ;
23
23
24
24
export interface GitCloneInfo {
@@ -27,11 +27,50 @@ export interface GitCloneInfo {
27
27
targetDirectory : string ;
28
28
}
29
29
30
+ function getFs ( ) : CallbackFsClient {
31
+ if ( env . isWindows ) {
32
+ return {
33
+ chmod : fs . chmod ,
34
+ lstat : fs . lstat ,
35
+ mkdir : fs . mkdir ,
36
+ readFile : fs . readFile ,
37
+ readdir : fs . readdir ,
38
+ readlink : fs . readlink ,
39
+ rmdir : fs . rmdir ,
40
+ stat : fs . stat ,
41
+ symlink : (
42
+ target : fs . PathLike ,
43
+ path : fs . PathLike ,
44
+ type_ : fs . symlink . Type | undefined ,
45
+ callback : fs . NoParamCallback ,
46
+ ) => {
47
+ if ( ! callback ) {
48
+ callback = type_ as unknown as NoParamCallback ;
49
+ type_ = undefined ;
50
+ }
51
+ fs . symlink ( target , path , type_ , err => {
52
+ if ( err ) {
53
+ fs . writeFile ( path , target . toString ( ) , { mode : 0o0444 } , err => {
54
+ callback ( err ) ;
55
+ } ) ;
56
+ } else {
57
+ // eslint-disable-next-line no-null/no-null
58
+ callback ( null ) ;
59
+ }
60
+ } ) ;
61
+ } ,
62
+ unlink : fs . unlink ,
63
+ writeFile : fs . writeFile ,
64
+ } ;
65
+ }
66
+ return fs ;
67
+ }
68
+
30
69
export class GitManager {
31
70
async cloneRepository ( gitCloneInfo : GitCloneInfo ) {
32
71
// clone repo
33
72
await git . clone ( {
34
- fs,
73
+ fs : getFs ( ) ,
35
74
http,
36
75
dir : gitCloneInfo . targetDirectory ,
37
76
url : gitCloneInfo . repository ,
@@ -78,7 +117,7 @@ export class GitManager {
78
117
clean : boolean ;
79
118
} > {
80
119
const status = await git . statusMatrix ( {
81
- fs,
120
+ fs : getFs ( ) ,
82
121
dir : directory ,
83
122
} ) ;
84
123
@@ -106,12 +145,12 @@ export class GitManager {
106
145
}
107
146
108
147
async getCurrentCommit ( directory : string ) : Promise < string > {
109
- return git . resolveRef ( { fs, dir : directory , ref : 'HEAD' } ) ;
148
+ return git . resolveRef ( { fs : getFs ( ) , dir : directory , ref : 'HEAD' } ) ;
110
149
}
111
150
112
151
async pull ( directory : string ) : Promise < void > {
113
152
return git . pull ( {
114
- fs,
153
+ fs : getFs ( ) ,
115
154
http,
116
155
dir : directory ,
117
156
} ) ;
@@ -170,7 +209,7 @@ export class GitManager {
170
209
) : Promise < { ok ?: boolean ; updatable ?: boolean ; error ?: string } > {
171
210
// fetch updates
172
211
await git . fetch ( {
173
- fs,
212
+ fs : getFs ( ) ,
174
213
http,
175
214
dir : directory ,
176
215
} ) ;
@@ -186,7 +225,7 @@ export class GitManager {
186
225
}
187
226
188
227
const branch = await git . currentBranch ( {
189
- fs,
228
+ fs : getFs ( ) ,
190
229
dir : directory ,
191
230
} ) ;
192
231
@@ -240,12 +279,12 @@ export class GitManager {
240
279
241
280
async getTrackingBranch ( directory : string , branch : string ) : Promise < string | undefined > {
242
281
const mergeRef = await git . getConfig ( {
243
- fs,
282
+ fs : getFs ( ) ,
244
283
dir : directory ,
245
284
path : `branch.${ branch } .merge` ,
246
285
} ) ;
247
286
const remote = await git . getConfig ( {
248
- fs,
287
+ fs : getFs ( ) ,
249
288
dir : directory ,
250
289
path : `branch.${ branch } .remote` ,
251
290
} ) ;
@@ -257,7 +296,7 @@ export class GitManager {
257
296
258
297
const remoteCommits = (
259
298
await git . log ( {
260
- fs,
299
+ fs : getFs ( ) ,
261
300
dir,
262
301
ref : remoteBranch ,
263
302
} )
@@ -266,7 +305,7 @@ export class GitManager {
266
305
. sort ( ) ;
267
306
const localCommits = (
268
307
await git . log ( {
269
- fs,
308
+ fs : getFs ( ) ,
270
309
dir,
271
310
ref : localBranch ,
272
311
} )
@@ -302,7 +341,7 @@ export class GitManager {
302
341
async getTagCommitId ( directory : string , tagName : string ) : Promise < string | undefined > {
303
342
try {
304
343
return await git . resolveRef ( {
305
- fs,
344
+ fs : getFs ( ) ,
306
345
dir : directory ,
307
346
ref : tagName ,
308
347
} ) ;
0 commit comments