@@ -2,7 +2,7 @@ import { spawn } from 'child_process'
22import { basename , resolve , join } from 'path'
33import { ProcessProxyConnection as Connection } from 'process-proxy'
44import type { HookCallbackOptions } from '../git'
5- import { resolveGitBinary } from 'dugite'
5+ import { resolveGitBinary , resolveGitExecPath } from 'dugite'
66import { ShellEnvResult } from './get-shell-env'
77import { shellFriendlyNames } from './config'
88import { Writable } from 'stream'
@@ -145,7 +145,9 @@ export const createHooksProxy = (
145145 ]
146146
147147 const terminalOutput : Buffer [ ] = [ ]
148- const gitPath = resolveGitBinary ( resolve ( __dirname , 'git' ) )
148+ const gitDir = resolve ( __dirname , 'git' )
149+ const gitPath = resolveGitBinary ( gitDir )
150+ const gitExecPath = resolveGitExecPath ( gitDir )
149151 const shellEnv = await getShellEnv ( proxyCwd )
150152
151153 if ( shellEnv . kind === 'failure' ) {
@@ -174,9 +176,20 @@ export const createHooksProxy = (
174176
175177 const child = spawn ( gitPath , args , {
176178 cwd : proxyCwd ,
177- // GITHUB_DESKTOP lets hooks know they're run from GitHub Desktop.
178- // See https://github.com/desktop/desktop/issues/19001
179- env : { ...shellEnv . env , ...safeEnv , GITHUB_DESKTOP : '1' } ,
179+ env : {
180+ ...shellEnv . env ,
181+ ...safeEnv ,
182+ // The bundled Git can't resolve its own exec-path when spawned this
183+ // way (it reports "//libexec/git-core"), so set it explicitly. Native
184+ // Git prepends GIT_EXEC_PATH to the hook's PATH, which is what makes
185+ // the bundled git-lfs (and git) findable from inside the hook. This
186+ // matters most in sandboxed builds (e.g. Flatpak) where no system
187+ // git-lfs exists on PATH to fall back on.
188+ GIT_EXEC_PATH : gitExecPath ,
189+ // GITHUB_DESKTOP lets hooks know they're run from GitHub Desktop.
190+ // See https://github.com/desktop/desktop/issues/19001
191+ GITHUB_DESKTOP : '1' ,
192+ } ,
180193 signal : abortController . signal ,
181194 } )
182195 . on ( 'close' , ( code , signal ) => resolve ( { code, signal } ) )
0 commit comments