@@ -103,6 +103,27 @@ public static bool TryUpdateHooks(GVFSContext context, out string errorMessage)
103103 }
104104 }
105105
106+ // Update the pre-command and post-command hook loaders (GitHooksLoader copies).
107+ // These are deployed at clone time by InstallHooks but also need updating on
108+ // mount so that upgrading GVFS and remounting refreshes all hooks.
109+ string loaderSourcePath = Path . Combine ( ExecutingDirectory , GVFSConstants . DotGit . Hooks . LoaderExecutable ) ;
110+
111+ string precommandHookPath = Path . Combine (
112+ context . Enlistment . WorkingDirectoryBackingRoot ,
113+ GVFSConstants . DotGit . Hooks . PreCommandPath + GVFSPlatform . Instance . Constants . ExecutableExtension ) ;
114+ if ( ! TryUpdateHook ( context , GVFSConstants . DotGit . Hooks . PreCommandHookName , loaderSourcePath , precommandHookPath , out errorMessage ) )
115+ {
116+ return false ;
117+ }
118+
119+ string postcommandHookPath = Path . Combine (
120+ context . Enlistment . WorkingDirectoryBackingRoot ,
121+ GVFSConstants . DotGit . Hooks . PostCommandPath + GVFSPlatform . Instance . Constants . ExecutableExtension ) ;
122+ if ( ! TryUpdateHook ( context , GVFSConstants . DotGit . Hooks . PostCommandHookName , loaderSourcePath , postcommandHookPath , out errorMessage ) )
123+ {
124+ return false ;
125+ }
126+
106127 return true ;
107128 }
108129
@@ -161,13 +182,23 @@ private static bool TryUpdateHook(
161182 HookData hook ,
162183 out string errorMessage )
163184 {
164- bool copyHook = false ;
165185 string enlistmentHookPath = Path . Combine ( context . Enlistment . WorkingDirectoryBackingRoot , hook . Path + GVFSPlatform . Instance . Constants . ExecutableExtension ) ;
166186 string installedHookPath = Path . Combine ( ExecutingDirectory , hook . ExecutableName ) ;
187+ return TryUpdateHook ( context , hook . Name , installedHookPath , enlistmentHookPath , out errorMessage ) ;
188+ }
189+
190+ private static bool TryUpdateHook (
191+ GVFSContext context ,
192+ string hookName ,
193+ string installedHookPath ,
194+ string enlistmentHookPath ,
195+ out string errorMessage )
196+ {
197+ bool copyHook = false ;
167198
168199 if ( ! context . FileSystem . FileExists ( installedHookPath ) )
169200 {
170- errorMessage = hook . ExecutableName + " cannot be found at " + installedHookPath ;
201+ errorMessage = Path . GetFileName ( installedHookPath ) + " cannot be found at " + installedHookPath ;
171202 return false ;
172203 }
173204
@@ -179,8 +210,8 @@ private static bool TryUpdateHook(
179210 metadata . Add ( "Area" , "Mount" ) ;
180211 metadata . Add ( nameof ( enlistmentHookPath ) , enlistmentHookPath ) ;
181212 metadata . Add ( nameof ( installedHookPath ) , installedHookPath ) ;
182- metadata . Add ( TracingConstants . MessageKey . WarningMessage , hook . Name + " not found in enlistment, copying from installation folder" ) ;
183- context . Tracer . RelatedWarning ( hook . Name + " MissingFromEnlistment" , metadata ) ;
213+ metadata . Add ( TracingConstants . MessageKey . WarningMessage , hookName + " not found in enlistment, copying from installation folder" ) ;
214+ context . Tracer . RelatedWarning ( hookName + " MissingFromEnlistment" , metadata ) ;
184215 }
185216 else
186217 {
@@ -197,8 +228,8 @@ private static bool TryUpdateHook(
197228 metadata . Add ( nameof ( enlistmentHookPath ) , enlistmentHookPath ) ;
198229 metadata . Add ( nameof ( installedHookPath ) , installedHookPath ) ;
199230 metadata . Add ( "Exception" , e . ToString ( ) ) ;
200- context . Tracer . RelatedError ( metadata , "Failed to compare " + hook . Name + " version" ) ;
201- errorMessage = "Error comparing " + hook . Name + " versions. " + ConsoleHelper . GetGVFSLogMessage ( context . Enlistment . EnlistmentRoot ) ;
231+ context . Tracer . RelatedError ( metadata , "Failed to compare " + hookName + " version" ) ;
232+ errorMessage = "Error comparing " + hookName + " versions. " + ConsoleHelper . GetGVFSLogMessage ( context . Enlistment . EnlistmentRoot ) ;
202233 return false ;
203234 }
204235 }
@@ -216,8 +247,8 @@ private static bool TryUpdateHook(
216247 metadata . Add ( nameof ( enlistmentHookPath ) , enlistmentHookPath ) ;
217248 metadata . Add ( nameof ( installedHookPath ) , installedHookPath ) ;
218249 metadata . Add ( "Exception" , e . ToString ( ) ) ;
219- context . Tracer . RelatedError ( metadata , "Failed to copy " + hook . Name + " to enlistment" ) ;
220- errorMessage = "Error copying " + hook . Name + " to enlistment. " + ConsoleHelper . GetGVFSLogMessage ( context . Enlistment . EnlistmentRoot ) ;
250+ context . Tracer . RelatedError ( metadata , "Failed to copy " + hookName + " to enlistment" ) ;
251+ errorMessage = "Error copying " + hookName + " to enlistment. " + ConsoleHelper . GetGVFSLogMessage ( context . Enlistment . EnlistmentRoot ) ;
221252 return false ;
222253 }
223254 }
0 commit comments