Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 4be7990

Browse files
committed
Fix #533: Use a mutex to prevent concurrent git add/rm calls.
1 parent 71e2387 commit 4be7990

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

  • src/AddIns/VersionControl/GitAddIn/Src

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
using System;
2020
using System.IO;
21+
using System.Threading;
2122
using System.Threading.Tasks;
2223
using ICSharpCode.Core;
2324
using 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>

0 commit comments

Comments
 (0)