1616 * SPDX-License-Identifier: Apache-2.0
1717 ***********************************************************************/
1818
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' ;
2222import http from 'isomorphic-git/http/node' ;
2323
2424export interface GitCloneInfo {
@@ -27,11 +27,50 @@ export interface GitCloneInfo {
2727 targetDirectory : string ;
2828}
2929
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+
3069export class GitManager {
3170 async cloneRepository ( gitCloneInfo : GitCloneInfo ) {
3271 // clone repo
3372 await git . clone ( {
34- fs,
73+ fs : getFs ( ) ,
3574 http,
3675 dir : gitCloneInfo . targetDirectory ,
3776 url : gitCloneInfo . repository ,
@@ -78,7 +117,7 @@ export class GitManager {
78117 clean : boolean ;
79118 } > {
80119 const status = await git . statusMatrix ( {
81- fs,
120+ fs : getFs ( ) ,
82121 dir : directory ,
83122 } ) ;
84123
@@ -106,12 +145,12 @@ export class GitManager {
106145 }
107146
108147 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' } ) ;
110149 }
111150
112151 async pull ( directory : string ) : Promise < void > {
113152 return git . pull ( {
114- fs,
153+ fs : getFs ( ) ,
115154 http,
116155 dir : directory ,
117156 } ) ;
@@ -170,7 +209,7 @@ export class GitManager {
170209 ) : Promise < { ok ?: boolean ; updatable ?: boolean ; error ?: string } > {
171210 // fetch updates
172211 await git . fetch ( {
173- fs,
212+ fs : getFs ( ) ,
174213 http,
175214 dir : directory ,
176215 } ) ;
@@ -186,7 +225,7 @@ export class GitManager {
186225 }
187226
188227 const branch = await git . currentBranch ( {
189- fs,
228+ fs : getFs ( ) ,
190229 dir : directory ,
191230 } ) ;
192231
@@ -240,12 +279,12 @@ export class GitManager {
240279
241280 async getTrackingBranch ( directory : string , branch : string ) : Promise < string | undefined > {
242281 const mergeRef = await git . getConfig ( {
243- fs,
282+ fs : getFs ( ) ,
244283 dir : directory ,
245284 path : `branch.${ branch } .merge` ,
246285 } ) ;
247286 const remote = await git . getConfig ( {
248- fs,
287+ fs : getFs ( ) ,
249288 dir : directory ,
250289 path : `branch.${ branch } .remote` ,
251290 } ) ;
@@ -257,7 +296,7 @@ export class GitManager {
257296
258297 const remoteCommits = (
259298 await git . log ( {
260- fs,
299+ fs : getFs ( ) ,
261300 dir,
262301 ref : remoteBranch ,
263302 } )
@@ -266,7 +305,7 @@ export class GitManager {
266305 . sort ( ) ;
267306 const localCommits = (
268307 await git . log ( {
269- fs,
308+ fs : getFs ( ) ,
270309 dir,
271310 ref : localBranch ,
272311 } )
@@ -302,7 +341,7 @@ export class GitManager {
302341 async getTagCommitId ( directory : string , tagName : string ) : Promise < string | undefined > {
303342 try {
304343 return await git . resolveRef ( {
305- fs,
344+ fs : getFs ( ) ,
306345 dir : directory ,
307346 ref : tagName ,
308347 } ) ;
0 commit comments