This repository was archived by the owner on Oct 16, 2020. It is now read-only.
File tree Expand file tree Collapse file tree
src/AddIns/VersionControl/GitAddIn/Src Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1818
1919using System ;
2020using System . IO ;
21+ using System . Threading ;
2122using System . Threading . Tasks ;
2223using ICSharpCode . Core ;
2324using ICSharpCode . SharpDevelop ;
@@ -79,14 +80,24 @@ public static string AdaptFileName(string wcRoot, string fileName)
7980 return relFileName . Replace ( '\\ ' , '/' ) ;
8081 }
8182
82- public static Task < int > RunGitAsync ( string workingDir , params string [ ] arguments )
83+ static SemaphoreSlim gitMutex = new SemaphoreSlim ( 1 ) ;
84+
85+ public static async Task < int > RunGitAsync ( string workingDir , params string [ ] arguments )
8386 {
8487 string git = FindGit ( ) ;
8588 if ( git == null )
86- return Task . FromResult ( 9009 ) ;
87- ProcessRunner p = new ProcessRunner ( ) ;
88- p . WorkingDirectory = workingDir ;
89- return p . RunInOutputPadAsync ( GitMessageView . Category , git , arguments ) ;
89+ return 9009 ;
90+ // Wait until other git calls have finished running
91+ // This prevents git from failing due to a locked index when several files
92+ // are added concurrently
93+ await gitMutex . WaitAsync ( ) ;
94+ try {
95+ ProcessRunner p = new ProcessRunner ( ) ;
96+ p . WorkingDirectory = workingDir ;
97+ await p . RunInOutputPadAsync ( GitMessageView . Category , git , arguments ) ;
98+ } finally {
99+ gitMutex . Release ( ) ;
100+ }
90101 }
91102
92103 /// <summary>
You can’t perform that action at this time.
0 commit comments