Skip to content

Commit f2791bb

Browse files
bordingarturcic
authored andcommitted
Add global mutex to prevent concurrent use
1 parent e67db0b commit f2791bb

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/GitVersion.App/GitVersionExecutor.cs

+13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.IO;
33
using System.Reflection;
4+
using System.Threading;
45
using GitVersion.Configuration;
56
using GitVersion.Extensions;
67
using GitVersion.Logging;
@@ -56,8 +57,16 @@ public int Execute(GitVersionOptions gitVersionOptions)
5657

5758
private int RunGitVersionTool(GitVersionOptions gitVersionOptions)
5859
{
60+
var mutexName = gitVersionOptions.WorkingDirectory.Replace("\\", "");
61+
using var mutex = new Mutex(true, $@"Global\{mutexName}", out var acquired);
62+
5963
try
6064
{
65+
if (!acquired)
66+
{
67+
mutex.WaitOne();
68+
}
69+
6170
var variables = gitVersionCalculateTool.CalculateVersionVariables();
6271

6372
var configuration = configProvider.Provide(overrideConfig: gitVersionOptions.ConfigInfo.OverrideConfig);
@@ -92,6 +101,10 @@ private int RunGitVersionTool(GitVersionOptions gitVersionOptions)
92101
}
93102
return 1;
94103
}
104+
finally
105+
{
106+
mutex.ReleaseMutex();
107+
}
95108

96109
return 0;
97110
}

0 commit comments

Comments
 (0)