Browse Source

Fix #533: Use a mutex to prevent concurrent git add/rm calls.

pull/505/merge
Daniel Grunwald 11 years ago
parent
commit
4be799023b
  1. 17
      src/AddIns/VersionControl/GitAddIn/Src/Git.cs

17
src/AddIns/VersionControl/GitAddIn/Src/Git.cs

@ -18,6 +18,7 @@
using System; using System;
using System.IO; using System.IO;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop;
@ -79,14 +80,24 @@ namespace ICSharpCode.GitAddIn
return relFileName.Replace('\\', '/'); return relFileName.Replace('\\', '/');
} }
public static Task<int> RunGitAsync(string workingDir, params string[] arguments) static SemaphoreSlim gitMutex = new SemaphoreSlim(1);
public static async Task<int> RunGitAsync(string workingDir, params string[] arguments)
{ {
string git = FindGit(); string git = FindGit();
if (git == null) if (git == null)
return Task.FromResult(9009); return 9009;
// Wait until other git calls have finished running
// This prevents git from failing due to a locked index when several files
// are added concurrently
await gitMutex.WaitAsync();
try {
ProcessRunner p = new ProcessRunner(); ProcessRunner p = new ProcessRunner();
p.WorkingDirectory = workingDir; p.WorkingDirectory = workingDir;
return p.RunInOutputPadAsync(GitMessageView.Category, git, arguments); await p.RunInOutputPadAsync(GitMessageView.Category, git, arguments);
} finally {
gitMutex.Release();
}
} }
/// <summary> /// <summary>

Loading…
Cancel
Save