Skip to content

Use .git directory for mutex name #2676

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/GitVersion.App/GitVersionExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public int Execute(GitVersionOptions gitVersionOptions)

private int RunGitVersionTool(GitVersionOptions gitVersionOptions)
{
var mutexName = gitVersionOptions.WorkingDirectory.Replace(Path.DirectorySeparatorChar.ToString(), "");
using var mutex = new Mutex(true, $@"Global\{mutexName}", out var acquired);
var mutexName = repositoryInfo.DotGitDirectory.Replace(Path.DirectorySeparatorChar.ToString(), "");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps prefixing gitversion to the mutex to avoid anyone else using the same mutex?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems a bit unlikely that another mutex with the exact name of the path of the .git folder would exist, but it probably wouldn't hurt to be a bit more defensive.

Looking at the mutex documentation, there is some vague stuff about potential maximum lengths of mutex names, but there are no actual values given, so I guess we'll have to see if there are any bug reports about names being too long and determine what do to if that happens.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The maximum length of mutex names is MAX_PATH, which is defined as 260 characters. So you should be fine here. (Source: CreateMutexW documentation)
Please note that mutex names are case sensitive. Should be ok as long as repositoryInfo.DotGitDirectoryrepositoryInfo.DotGitDirectory has always the same casing.

using var mutex = new Mutex(true, $@"Global\gitversion{mutexName}", out var acquired);

try
{
Expand Down