@@ -462,7 +462,9 @@ public bool TryGetFromConfig(string settingName, bool forceOutsideEnlistment, ou
462462
463463 public ConfigResult GetOriginUrl ( )
464464 {
465- return new ConfigResult ( this . InvokeGitAgainstDotGitFolder ( "config --local remote.origin.url" ) , "remote.origin.url" ) ;
465+ /* Disable precommand hook because this config call is used during mounting process
466+ * which needs to be able to fix a bad precommand hook configuration. */
467+ return new ConfigResult ( this . InvokeGitAgainstDotGitFolder ( "config --local remote.origin.url" , usePreCommandHook : false ) , "remote.origin.url" ) ;
466468 }
467469
468470 public Result DiffTree ( string sourceTreeish , string targetTreeish , Action < string > onResult )
@@ -670,7 +672,7 @@ public Result MultiPackIndexRepack(string gitObjectDirectory, string batchSize)
670672 return this . InvokeGitAgainstDotGitFolder ( $ "-c pack.threads=1 -c repack.packKeptObjects=true multi-pack-index repack --object-dir=\" { gitObjectDirectory } \" --batch-size={ batchSize } --no-progress") ;
671673 }
672674
673- public Process GetGitProcess ( string command , string workingDirectory , string dotGitDirectory , bool useReadObjectHook , bool redirectStandardError , string gitObjectsDirectory )
675+ public Process GetGitProcess ( string command , string workingDirectory , string dotGitDirectory , bool useReadObjectHook , bool redirectStandardError , string gitObjectsDirectory , bool usePreCommandHook )
674676 {
675677 ProcessStartInfo processInfo = new ProcessStartInfo ( this . gitBinPath ) ;
676678 processInfo . WorkingDirectory = workingDirectory ;
@@ -719,6 +721,11 @@ public Process GetGitProcess(string command, string workingDirectory, string dot
719721 command = "-c " + GitConfigSetting . CoreVirtualizeObjectsName + "=false " + command ;
720722 }
721723
724+ if ( ! usePreCommandHook )
725+ {
726+ processInfo . EnvironmentVariables [ "COMMAND_HOOK_LOCK" ] = "true" ;
727+ }
728+
722729 if ( ! string . IsNullOrEmpty ( dotGitDirectory ) )
723730 {
724731 command = "--git-dir=\" " + dotGitDirectory + "\" " + command ;
@@ -740,7 +747,8 @@ protected virtual Result InvokeGitImpl(
740747 Action < StreamWriter > writeStdIn ,
741748 Action < string > parseStdOutLine ,
742749 int timeoutMs ,
743- string gitObjectsDirectory = null )
750+ string gitObjectsDirectory = null ,
751+ bool usePreCommandHook = true )
744752 {
745753 if ( failedToSetEncoding && writeStdIn != null )
746754 {
@@ -752,7 +760,7 @@ protected virtual Result InvokeGitImpl(
752760 // From https://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardoutput.aspx
753761 // To avoid deadlocks, use asynchronous read operations on at least one of the streams.
754762 // Do not perform a synchronous read to the end of both redirected streams.
755- using ( this . executingProcess = this . GetGitProcess ( command , workingDirectory , dotGitDirectory , useReadObjectHook , redirectStandardError : true , gitObjectsDirectory : gitObjectsDirectory ) )
763+ using ( this . executingProcess = this . GetGitProcess ( command , workingDirectory , dotGitDirectory , useReadObjectHook , redirectStandardError : true , gitObjectsDirectory : gitObjectsDirectory , usePreCommandHook : usePreCommandHook ) )
756764 {
757765 StringBuilder output = new StringBuilder ( ) ;
758766 StringBuilder errors = new StringBuilder ( ) ;
@@ -904,15 +912,16 @@ private Result InvokeGitInWorkingDirectoryRoot(
904912 /// Invokes git.exe against an enlistment's .git folder.
905913 /// This method should be used only with git-commands that ignore the working directory
906914 /// </summary>
907- private Result InvokeGitAgainstDotGitFolder ( string command )
915+ private Result InvokeGitAgainstDotGitFolder ( string command , bool usePreCommandHook = true )
908916 {
909- return this . InvokeGitAgainstDotGitFolder ( command , null , null ) ;
917+ return this . InvokeGitAgainstDotGitFolder ( command , null , null , usePreCommandHook : usePreCommandHook ) ;
910918 }
911919
912920 private Result InvokeGitAgainstDotGitFolder (
913921 string command ,
914922 Action < StreamWriter > writeStdIn ,
915923 Action < string > parseStdOutLine ,
924+ bool usePreCommandHook = true ,
916925 string gitObjectsDirectory = null )
917926 {
918927 // This git command should not need/use the working directory of the repo.
@@ -926,7 +935,8 @@ private Result InvokeGitAgainstDotGitFolder(
926935 writeStdIn : writeStdIn ,
927936 parseStdOutLine : parseStdOutLine ,
928937 timeoutMs : - 1 ,
929- gitObjectsDirectory : gitObjectsDirectory ) ;
938+ gitObjectsDirectory : gitObjectsDirectory ,
939+ usePreCommandHook : usePreCommandHook ) ;
930940 }
931941
932942 public class Result
0 commit comments