@@ -5,7 +5,7 @@ import { toWslPath } from './wsl-utils'
55
66const log = createLogger ( 'git-port' )
77
8- const EXEC_TIMEOUT_MS = 15_000
8+ const DEFAULT_EXEC_TIMEOUT_MS = 15_000
99
1010// ─── Interface ────────────────────────────────────────────────────────────────
1111
@@ -77,11 +77,11 @@ export function makeBranchName(projectId: string, sessionId: string, suffix?: nu
7777 * Runs `wsl.exe git <args>` in the given working directory.
7878 * Resolves with trimmed stdout; rejects with a descriptive Error on non-zero exit.
7979 */
80- function wslExec ( args : string [ ] , cwd ?: string ) : Promise < string > {
80+ function wslExec ( args : string [ ] , cwd ?: string , timeoutMs ?: number ) : Promise < string > {
8181 return new Promise ( ( resolve , reject ) => {
8282 const opts : ExecFileOptions & { encoding : 'utf8' } = {
8383 encoding : 'utf8' ,
84- timeout : EXEC_TIMEOUT_MS ,
84+ timeout : timeoutMs ?? DEFAULT_EXEC_TIMEOUT_MS ,
8585 ...( cwd !== undefined ? { cwd } : { } ) ,
8686 }
8787 execFile ( 'wsl.exe' , [ 'git' , ...args ] , opts , ( err , stdout , stderr ) => {
@@ -106,23 +106,26 @@ function ensureWslPath(p: string): string {
106106/**
107107 * Creates a GitPort that shells out to `wsl.exe git ...` for all operations.
108108 */
109- export function createWslGitPort ( ) : GitPort {
109+ export function createWslGitPort ( options ?: { timeoutMs ?: number } ) : GitPort {
110+ const t = options ?. timeoutMs
111+ const git = ( args : string [ ] ) : Promise < string > => wslExec ( args , undefined , t )
112+
110113 return {
111114 async isGitRepo ( path : string ) : Promise < boolean > {
112115 try {
113- await wslExec ( [ '-C' , ensureWslPath ( path ) , 'rev-parse' , '--git-dir' ] )
116+ await git ( [ '-C' , ensureWslPath ( path ) , 'rev-parse' , '--git-dir' ] )
114117 return true
115118 } catch {
116119 return false
117120 }
118121 } ,
119122
120123 async getRepoRoot ( path : string ) : Promise < string > {
121- return wslExec ( [ '-C' , ensureWslPath ( path ) , 'rev-parse' , '--show-toplevel' ] )
124+ return git ( [ '-C' , ensureWslPath ( path ) , 'rev-parse' , '--show-toplevel' ] )
122125 } ,
123126
124127 async addWorktree ( repoRoot : string , worktreePath : string , branch : string ) : Promise < void > {
125- await wslExec ( [
128+ await git ( [
126129 '-C' ,
127130 ensureWslPath ( repoRoot ) ,
128131 'worktree' ,
@@ -135,7 +138,7 @@ export function createWslGitPort(): GitPort {
135138 } ,
136139
137140 async removeWorktree ( repoRoot : string , worktreePath : string ) : Promise < void > {
138- await wslExec ( [
141+ await git ( [
139142 '-C' ,
140143 ensureWslPath ( repoRoot ) ,
141144 'worktree' ,
@@ -147,16 +150,16 @@ export function createWslGitPort(): GitPort {
147150 } ,
148151
149152 async pruneWorktrees ( repoRoot : string ) : Promise < void > {
150- await wslExec ( [ '-C' , ensureWslPath ( repoRoot ) , 'worktree' , 'prune' ] )
153+ await git ( [ '-C' , ensureWslPath ( repoRoot ) , 'worktree' , 'prune' ] )
151154 } ,
152155
153156 async deleteBranch ( repoRoot : string , branch : string ) : Promise < void > {
154- await wslExec ( [ '-C' , ensureWslPath ( repoRoot ) , 'branch' , '-D' , branch ] )
157+ await git ( [ '-C' , ensureWslPath ( repoRoot ) , 'branch' , '-D' , branch ] )
155158 log . info ( 'branch deleted' , { repoRoot, branch } )
156159 } ,
157160
158161 async status ( path : string ) : Promise < { hasChanges : boolean } > {
159- const output = await wslExec ( [
162+ const output = await git ( [
160163 '-C' ,
161164 ensureWslPath ( path ) ,
162165 'status' ,
@@ -168,7 +171,7 @@ export function createWslGitPort(): GitPort {
168171 } ,
169172
170173 async aheadCount ( path : string , baseOid : string ) : Promise < number > {
171- const output = await wslExec ( [
174+ const output = await git ( [
172175 '-C' ,
173176 ensureWslPath ( path ) ,
174177 'rev-list' ,
@@ -179,11 +182,11 @@ export function createWslGitPort(): GitPort {
179182 } ,
180183
181184 async currentOid ( path : string ) : Promise < string > {
182- return wslExec ( [ '-C' , ensureWslPath ( path ) , 'rev-parse' , 'HEAD' ] )
185+ return git ( [ '-C' , ensureWslPath ( path ) , 'rev-parse' , 'HEAD' ] )
183186 } ,
184187
185188 async gitVersion ( ) : Promise < { major : number ; minor : number } > {
186- const output = await wslExec ( [ 'version' ] )
189+ const output = await git ( [ 'version' ] )
187190 return parseGitVersion ( output )
188191 } ,
189192 }
0 commit comments