Sorry, I'm just starting to look at this but I have an exception that occurs only on 1 branch that we have. The rest are working.
This is in version 3.5.3 building on a TFS vNext agent.
`ERROR [05/18/16 11:44:42:43] An unexpected error occurred:
2016-05-17T23:44:42.4352442Z LibGit2Sharp.NameConflictException: Failed to write reference 'refs/heads/feature/Morpheus_v12.2': a reference with that name already exists.
2016-05-17T23:44:42.4352442Z at LibGit2Sharp.Core.Ensure.HandleError(Int32 result)
2016-05-17T23:44:42.4352442Z at LibGit2Sharp.Core.Ensure.ZeroResult(Int32 result)
2016-05-17T23:44:42.4352442Z at LibGit2Sharp.Core.Proxy.git_reference_create(RepositoryHandle repo, String name, ObjectId targetId, Boolean allowOverwrite, String logMessage)
2016-05-17T23:44:42.4352442Z at LibGit2Sharp.ReferenceCollection.Add(String name, ObjectId targetId, String logMessage, Boolean allowOverwrite)
2016-05-17T23:44:42.4352442Z at LibGit2Sharp.ReferenceCollection.Add(String name, ObjectId targetId)
2016-05-17T23:44:42.4352442Z at GitTools.Git.GitRepositoryHelper.EnsureLocalBranchExistsForCurrentBranch(Repository repo, String currentBranch)
2016-05-17T23:44:42.4352442Z at GitTools.Git.GitRepositoryHelper.NormalizeGitDirectory(String gitDirectory, AuthenticationInfo authentication, Boolean noFetch, String currentBranch)
2016-05-17T23:44:42.4352442Z at GitVersion.GitPreparer.Initialise(Boolean normaliseGitDirectory, String currentBranch)
2016-05-17T23:44:42.4352442Z at GitVersion.ExecuteCore.ExecuteInternal(String targetBranch, String commitId, IRepository repo, GitPreparer gitPreparer, String projectRoot, IBuildServer buildServer, Config overrideConfig)
2016-05-17T23:44:42.4352442Z at GitVersion.ExecuteCore.ExecuteGitVersion(String targetUrl, String dynamicRepositoryLocation, Authentication authentication, String targetBranch, Boolean noFetch, String workingDirectory, String commitId, Config overrideConfig)
2016-05-17T23:44:42.4352442Z at GitVersion.SpecifiedArgumentRunner.Run(Arguments arguments, IFileSystem fileSystem)
2016-05-17T23:44:42.4352442Z at GitVersion.Program.VerifyArgumentsAndRun()
2016-05-17T23:44:42.4352442Z INFO [05/18/16 11:44:42:43]
2016-05-17T23:44:42.4352442Z INFO [05/18/16 11:44:42:43] Here is the current git graph (please include in issue):
2016-05-17T23:44:42.4352442Z INFO [05/18/16 11:44:42:43] Showing max of 100 commits
2016-05-17T23:44:43.3258635Z INFO [05/18/16 11:44:43:32] * e1e8217 47 minutes ago (HEAD, origin/Feature/Morpheus_v12.2)
2016-05-17T23:44:43.3258635Z |\
2016-05-17T23:44:43.3258635Z | | * 497957a 58 minutes ago (origin/pull/US751)
2016-05-17T23:44:43.3414884Z | | * daf77dc 2 hours ago
2016-05-17T23:44:43.3414884Z | | |\
2016-05-17T23:44:43.3414884Z | |_|/
2016-05-17T23:44:43.3414884Z |/| |
2016-05-17T23:44:43.3414884Z * | | 4d340a3 2 hours ago
2016-05-17T23:44:43.3414884Z |\ \ \
2016-05-17T23:44:43.3414884Z | * \ \ f5d110e 21 hours ago (Feature/Morpheus_v12.2)
2016-05-17T23:44:43.3414884Z | |\ \ \
2016-05-17T23:44:43.3414884Z | | * \ \ 7c614e2 2 days ago (origin/pull/US968, pull/US968)
2016-05-17T23:44:43.3414884Z | | |\ \ \
2016-05-17T23:44:43.3414884Z | | * | | | 4b6cb49 2 days ago
2016-05-17T23:44:43.3414884Z * | | | | | 8858504 2 hours ago
2016-05-17T23:44:43.3414884Z |/ / / / /
2016-05-17T23:44:43.3414884Z | | | | * 853b994 2 hours ago
2016-05-17T23:44:43.3414884Z | | | | * 5245501 21 hours ago
2016-05-17T23:44:43.3414884Z | |_|_|/
2016-05-17T23:44:43.3414884Z |/| | |
2016-05-17T23:44:43.3414884Z * | | | 0ca06fd 22 hours ago
2016-05-17T23:44:43.3414884Z |\ \ \ \
2016-05-17T23:44:43.3414884Z | |_|/ /
2016-05-17T23:44:43.3414884Z |/| | |
2016-05-17T23:44:43.3414884Z | | | | * 32923d9 3 hours ago (origin/Feature/VRecalls)
2016-05-17T23:44:43.3414884Z | | | | |\
2016-05-17T23:44:43.3414884Z | | | | |/
2016-05-17T23:44:43.3571133Z | | | |/|
2016-05-17T23:44:43.3571133Z | | | * | 7aa63d9 3 hours ago (origin/master, master)
2016-05-17T23:44:43.3571133Z | | | |\ \
2016-05-17T23:44:43.3571133Z | | | | * | 027a9e5 3 hours ago
2016-05-17T23:44:43.3571133Z | | | |/ /
2016-05-17T23:44:43.3571133Z | | | * | 9625f39 4 hours ago
2016-05-17T23:44:43.3571133Z | | | |\ \
2016-05-17T23:44:43.3571133Z | | | | * | 2da01c4 4 hours ago
2016-05-17T23:44:43.3571133Z | | | * | | 3e808dc 19 hours ago
2016-05-17T23:44:43.3571133Z | | | |\ \ \
2016-05-17T23:44:43.3571133Z | | | | * | | a87dd32 20 hours ago
2016-05-17T23:44:43.3571133Z | | | | * | | 279f6cf 20 hours ago
2016-05-17T23:44:43.3571133Z | | | | |\ \ \
2016-05-17T23:44:43.3571133Z | | | | | * | | 1eb4bd6 20 hours ago
2016-05-17T23:44:43.3571133Z | | |_|_|/ / /
2016-05-17T23:44:43.3571133Z | |/| | | | |
2016-05-17T23:44:43.3571133Z | | | | * | | 4b846e7 20 hours ago
2016-05-17T23:44:43.3571133Z | | |_|/ / /
2016-05-17T23:44:43.3571133Z | |/| | | |
2016-05-17T23:44:43.3571133Z | | | * | | 36918e5 20 hours ago
2016-05-17T23:44:43.3571133Z | | | |\ \ \
2016-05-17T23:44:43.3571133Z | | |/ / / /
2016-05-17T23:44:43.3571133Z | |/| | | |
2016-05-17T23:44:43.3571133Z | | | * | | 01e3c52 21 hours ago
2016-05-17T23:44:43.3571133Z | | |/ / /
2016-05-17T23:44:43.3571133Z | |/| | |
2016-05-17T23:44:43.3571133Z | | | | * 9cc356b 21 hours ago (Feature/VRecalls)
2016-05-17T23:44:43.3571133Z | | | | |\
2016-05-17T23:44:43.3571133Z | | | | | * de88a2a 21 hours ago
2016-05-17T23:44:43.3571133Z | | | | | * 4ad26d2 21 hours ago
2016-05-17T23:44:43.3571133Z | | | | | |\
2016-05-17T23:44:43.3571133Z | | | | | | * dfb8e2a 22 hours ago
2016-05-17T23:44:43.3571133Z | | | | | | |\
2016-05-17T23:44:43.3571133Z | | |_|_|_|_|/
2016-05-17T23:44:43.3571133Z | |/| | | | |
2016-05-17T23:44:43.3571133Z | * | | | | | 726e6cb 24 hours ago
2016-05-17T23:44:43.3571133Z | |\ \ \ \ \ \
2016-05-17T23:44:43.3571133Z | | * | | | | | 5856f76 25 hours ago (origin/pull/M49638, pull/M49638)
2016-05-17T23:44:43.3727382Z | | * | | | | | c9f186c 2 days ago
2016-05-17T23:44:43.3727382Z | * | | | | | | 53a095b 24 hours ago
2016-05-17T23:44:43.3727382Z | |\ \ \ \ \ \ \
2016-05-17T23:44:43.3727382Z | | * | | | | | | a71dff4 2 days ago (origin/pull/lightinstaller, pull/lightinstaller)
2016-05-17T23:44:43.3727382Z | | * | | | | | | 14b9c79 2 days ago
2016-05-17T23:44:43.3727382Z | | * | | | | | | 11e2e91 2 days ago
2016-05-17T23:44:43.3727382Z | | * | | | | | | 78c956a 2 days ago
2016-05-17T23:44:43.3727382Z | | * | | | | | | cae8e9d 2 days ago
2016-05-17T23:44:43.3727382Z | | * | | | | | | 7f08e37 2 days ago
2016-05-17T23:44:43.3727382Z | | * | | | | | | 3c3d76a 2 days ago
2016-05-17T23:44:43.3727382Z | | * | | | | | | a4ffa79 2 days ago
2016-05-17T23:44:43.3727382Z | | * | | | | | | d6d5d4b 2 days ago
2016-05-17T23:44:43.3727382Z | | * | | | | | | be6aef8 2 days ago
2016-05-17T23:44:43.3727382Z | | * | | | | | | 3c16f81 5 days ago
2016-05-17T23:44:43.3727382Z | | * | | | | | | c4a47f8 5 days ago
2016-05-17T23:44:43.3727382Z | | * | | | | | | 0d1e995 5 days ago
2016-05-17T23:44:43.3727382Z | | * | | | | | | bbcc78c 5 days ago
2016-05-17T23:44:43.3727382Z | | * | | | | | | 53680e0 5 days ago
2016-05-17T23:44:43.3727382Z | | * | | | | | | e5cdff6 6 days ago
2016-05-17T23:44:43.3727382Z | | |\ \ \ \ \ \ \
2016-05-17T23:44:43.3727382Z | | | | |/ / / / /
2016-05-17T23:44:43.3727382Z | | | |/| | | | |
2016-05-17T23:44:43.3727382Z | | * | | | | | | 47c468d 6 days ago
2016-05-17T23:44:43.3727382Z | * | | | | | | | e5850f1 25 hours ago
2016-05-17T23:44:43.3727382Z | |\ \ \ \ \ \ \ \
2016-05-17T23:44:43.3727382Z | | |_|_|_|/ / / /
2016-05-17T23:44:43.3727382Z | |/| | | | | | |
2016-05-17T23:44:43.3727382Z | * | | | | | | | c2eb9ac 26 hours ago
2016-05-17T23:44:43.3727382Z | |\ \ \ \ \ \ \ \
2016-05-17T23:44:43.3727382Z | | * \ \ \ \ \ \ \ 628b35b 2 days ago (origin/pull/M49556, pull/M49556)
2016-05-17T23:44:43.3727382Z | | |\ \ \ \ \ \ \ \
2016-05-17T23:44:43.3727382Z | | |/ / / / / / / /
2016-05-17T23:44:43.3727382Z | |/| | | | | | | |
2016-05-17T23:44:43.3727382Z | | * | | | | | | | df15870 6 weeks ago (origin/M49556, M49556)
2016-05-17T23:44:43.3727382Z | | | | | | | | * | 892a7c0 23 hours ago
2016-05-17T23:44:43.3727382Z | | | | | | | | |\ \
2016-05-17T23:44:43.3727382Z | | | | | | | | | |/
2016-05-17T23:44:43.3727382Z | | | | | | | | * | a119604 25 hours ago
2016-05-17T23:44:43.3883631Z | | | | | | | | |\ \
2016-05-17T23:44:43.3883631Z | | | | | | | | * | | 392e639 25 hours ago
2016-05-17T23:44:43.3883631Z | | | | | | | * | | | 602ab82 21 hours ago
2016-05-17T23:44:43.3883631Z | | | | | | | | |_|/
2016-05-17T23:44:43.3883631Z | | | | | | | |/| |
2016-05-17T23:44:43.3883631Z | | | | | | | * | | d31cda9 24 hours ago
2016-05-17T23:44:43.3883631Z | | | | | | | |\ \ \
2016-05-17T23:44:43.3883631Z | | | | | | | | * \ \ 6565e63 24 hours ago
2016-05-17T23:44:43.3883631Z | | | | | | | | |\ \ \
2016-05-17T23:44:43.3883631Z | | | | | | | | | * \ \ b6e60fc 2 days ago
2016-05-17T23:44:43.3883631Z | | | | | | | | | |\ \ \
2016-05-17T23:44:43.3883631Z | | |_|_|_|_|_|_|_|/ / /
2016-05-17T23:44:43.3883631Z | |/| | | | | | | | | |
2016-05-17T23:44:43.3883631Z | * | | | | | | | | | | 04518f5 2 days ago (origin/Feature/MedicalHistoryFix, origin/Feature/M47228-DAFAlerts, Feature/MedicalHistoryFix, Feature/M47228-DAFAlerts)
2016-05-17T23:44:43.3883631Z | |\ \ \ \ \ \ \ \ \ \ \
2016-05-17T23:44:43.3883631Z | * \ \ \ \ \ \ \ \ \ \ \ 24a1fc5 2 days ago
2016-05-17T23:44:43.3883631Z | |\ \ \ \ \ \ \ \ \ \ \ \
2016-05-17T23:44:43.3883631Z | | |_|_|_|_|_|/ / / / / /
2016-05-17T23:44:43.3883631Z | |/| | | | | | | | | | |
2016-05-17T23:44:43.3883631Z | | | | | | | | | | * | | 1d0ce6c 2 days ago
2016-05-17T23:44:43.3883631Z | | |_|_|_|_|_|_|_|/ / /
2016-05-17T23:44:43.3883631Z | |/| | | | | | | | | |
2016-05-17T23:44:43.3883631Z | | | | | | | | * | | | 9cdedf7 24 hours ago
2016-05-17T23:44:43.3883631Z | | | | | | | | |/ / /
2016-05-17T23:44:43.3883631Z | | | | | | | | * | | 9a185e6 24 hours ago
2016-05-17T23:44:43.3883631Z | | | | | | | | | |/
2016-05-17T23:44:43.3883631Z | | | | | | | | |/|
2016-05-17T23:44:43.3883631Z | | | | | | | | * | 874d120 25 hours ago
2016-05-17T23:44:43.3883631Z | | | | | | | | * | 4d72ce0 2 days ago
2016-05-17T23:44:43.3883631Z | | | | | | | | |/
2016-05-17T23:44:43.3883631Z | | | | | | | | * 4f445a3 2 days ago
2016-05-17T23:44:43.3883631Z | | |_|_|_|_|_|/
2016-05-17T23:44:43.3883631Z | |/| | | | | |
2016-05-17T23:44:43.3883631Z | | | | | | | | * 2289d18 20 hours ago (origin/pull/TFS-949, pull/TFS-949)
2016-05-17T23:44:43.3883631Z | |_|_|_|_|_|_|/
2016-05-17T23:44:43.3883631Z |/| | | | | | |
2016-05-17T23:44:43.3883631Z * | | | | | | | 94f3b17 2 days ago
2016-05-17T23:44:43.4039880Z |\ \ \ \ \ \ \ \
2016-05-17T23:44:43.4039880Z | * | | | | | | | 2412edc 5 days ago (origin/pull/US962, pull/US962)
2016-05-17T23:44:43.4039880Z | | |_|_|_|_|_|/
2016-05-17T23:44:43.4039880Z | |/| | | | | |
2016-05-17T23:44:43.4039880Z * | | | | | | | 48ae8c6 2 days ago
2016-05-17T23:44:43.4039880Z |\ \ \ \ \ \ \ \
2016-05-17T23:44:43.4039880Z | |/ / / / / / /
2016-05-17T23:44:43.4039880Z |/| | | | | | |
2016-05-17T23:44:43.4039880Z | * | | | | | | fdc04f5 2 days ago (origin/pull/US966, pull/US966)
<snip>
This occurs sporadically on build agents using build vNext. Logging into to the agent locally and running c:tasksGitVersion3.5.3GitVersion.exe /output buildserver /nofetch (the same command as reported in the log) has some strange behavior.
It takes _a very long time_ and then eventually succeeds.
Could this have anything to do with the %tmp% file?
From the looks of it its a case sensitivity issue.
refs/heads/feature/Morpheus_v12.2 vs (Feature/Morpheus_v12.2)
That would be my first guess. Possibly https://github.com/GitTools/GitTools.Core/blob/master/src/GitTools.Core/GitTools.Core.Shared/Git/Helpers/GitRepositoryHelper.cs#L120 needs to be a case insensitive check.
What is the resolution here? I am seeing same error on one of my branch
So we just ran into this as well and it's because we had some history where we had someone use a capital F for a feature branch (i.e. Feature/whatever) in the past so when it goes through history and the first Feature/... it comes across is upper, but newer branches are lowercase (i.e. feature/...) it has already established the Feature/ virtual folder (if you will) as upper case. Obviously _some_ of the code is treating things as case-insensitive, while other code is treating it as case-sensitive (i.e. _Equals_ vs _Equals(..., StringComparisonOptions.OridinalIgnoreCase)) and so you end up with this disagreement in the two different parts of the code.
Judging by the stack trace, it looks to me like this is a bug in Lib2GitSharp though, _not_ GitVersion, right?
I am receiving this error with TeamCity now.
I got the same.
This was the first google hit and the comments are fitting with my history.
I made a big Story/... instead of story/...
Deleted the old Story/... and recreated the branch as story/...
The error occurred after an PullRequest in TFS. The build failed at git version. My error looks the same as above, without the git log, that's failing too, because the team don't have git in the path 馃槄 .
I'll recheck on that with our dev-team. I requested a Build again, which successfully handled this case.
May be there is an old build folder from my first story trial, that is related to the first story.
@drub0y Maybe it is a problem from Lib2GitSharp. But maybe it is the use or a missing parameters of it.
I'm having the problem too. Any solution yet?
Ditto, we're also hitting the same issue - someone created a Feature/ branch in our repo and now subsequent builds from feature/ branches are failing. Is there any way around this?
+1
As mentioned above the issue seems to be with the code at
https://github.com/GitTools/GitTools.Core/blob/master/src/GitTools.Core/Git/Helpers/GitRepositoryHelper.cs#L155
2018-06-08T01:23:04.6228083Z ERROR [06/08/18 13:23:04:62] An unexpected error occurred:
2018-06-08T01:23:04.6228083Z LibGit2Sharp.NameConflictException: Failed to write reference 'refs/heads/feature/Config/Add_Config': a reference with that name already exists.
2018-06-08T01:23:04.6228083Z at LibGit2Sharp.Core.Ensure.HandleError(Int32 result)
2018-06-08T01:23:04.6228083Z at LibGit2Sharp.Core.Ensure.ZeroResult(Int32 result)
2018-06-08T01:23:04.6228083Z at LibGit2Sharp.Core.Proxy.git_reference_create(RepositoryHandle repo, String name, ObjectId targetId, Boolean allowOverwrite, String logMessage)
2018-06-08T01:23:04.6228083Z at LibGit2Sharp.ReferenceCollection.Add(String name, ObjectId targetId, String logMessage, Boolean allowOverwrite)
2018-06-08T01:23:04.6228083Z at LibGit2Sharp.ReferenceCollection.Add(String name, ObjectId targetId)
2018-06-08T01:23:04.6228083Z at GitTools.Git.GitRepositoryHelper.EnsureLocalBranchExistsForCurrentBranch(Repository repo, String currentBranch)
2018-06-08T01:23:04.6228083Z at GitTools.Git.GitRepositoryHelper.NormalizeGitDirectory(String gitDirectory, AuthenticationInfo authentication, Boolean noFetch, String currentBranch)
2018-06-08T01:23:04.6228083Z at GitVersion.GitPreparer.Initialise(Boolean normaliseGitDirectory, String currentBranch)
2018-06-08T01:23:04.6228083Z at GitVersion.ExecuteCore.ExecuteInternal(String targetBranch, String commitId, IRepository repo, GitPreparer gitPreparer, String projectRoot, IBuildServer buildServer, Config overrideConfig)
2018-06-08T01:23:04.6228083Z at GitVersion.ExecuteCore.ExecuteGitVersion(String targetUrl, String dynamicRepositoryLocation, Authentication authentication, String targetBranch, Boolean noFetch, String workingDirectory, String commitId, Config overrideConfig)
2018-06-08T01:23:04.6228083Z at GitVersion.SpecifiedArgumentRunner.Run(Arguments arguments, IFileSystem fileSystem)
2018-06-08T01:23:04.6228083Z at GitVersion.Program.VerifyArgumentsAndRun()
As GitVersion stopped using GitTools.Core in #1581 and after upgrading to LibGit2Sharp 0.26 in #1713, I'm not sure this problem still exists. Can you please try the latest build of GitVersion and report back whether it fixes this problem or not? Please reopen this issue if the problem persists.
Hi @asbjornu , it's still happening with the latest version 5.0.1. Should this issue be reopened or should I open another issue?
In my case I have two branches that cause the conflict:
Error below:
_An unexpected error occurred:
LibGit2Sharp.NameConflictException: Failed to write reference 'refs/heads/hotfix/DEVOPS-819': a reference with that name already exists.
at LibGit2Sharp.Core.Ensure.HandleError(Int32 result)
at LibGit2Sharp.Core.Proxy.git_reference_create(RepositoryHandle repo, String name, ObjectId targetId, Boolean allowOverwrite, String logMessage)
at LibGit2Sharp.ReferenceCollection.Add(String name, ObjectId targetId, String logMessage, Boolean allowOverwrite)
at LibGit2Sharp.ReferenceCollection.Add(String name, ObjectId targetId)
at GitTools.Git.GitRepositoryHelper.EnsureLocalBranchExistsForCurrentBranch(Repository repo, String currentBranch)
at GitTools.Git.GitRepositoryHelper.NormalizeGitDirectory(String gitDirectory, AuthenticationInfo authentication, Boolean noFetch, String currentBranch)
at GitVersion.GitPreparer.Initialise(Boolean normaliseGitDirectory, String currentBranch)
at GitVersion.ExecuteCore.ExecuteGitVersion(String targetUrl, String dynamicRepositoryLocation, Authentication authentication, String targetBranch, Boolean noFetch, String workingDirectory, String commitId, Config overrideConfig)
at GitVersion.SpecifiedArgumentRunner.Run(Arguments arguments, IFileSystem fileSystem)
at GitVersion.Program.VerifyArgumentsAndRun()_
@zapr-16, are you able to reproduce this problem in a RepositoryFixture test akin to the following?
It's still happening with 5.1.2 馃槥
@thoemmi, are you able to reproduce the problem in a RepositoryFixture as per https://github.com/GitTools/GitVersion/issues/864#issuecomment-537256798?
Unfortunately, it does not occur locally but on the Azure DevOps build server.
Actually, it happens in DevOps Pull Requests only. If I queue an build of the branch explicitly, it succeeds. I guess it's how Azure DevOps handles the implicit PR branches.
This issue still occurs every now and then in our Pull Request builds on Azure DevOps. Unfortunately, I am not able to reproduce it locally. (BTW, GitVersionTask is 5.1.2)
@asbjornu Since this issue is closed already, should I open a new issue, or can you re-open this one?
I am having this on our master branch in one of our projects. We have 5 other Azure DevOps pipeline builds running fine with the "GitVersionTask" referenced in multiple projects.
But this 6th build is giving an error:
##[error]C:\Users\VssAdministrator\.nuget\packages\gitversiontask\5.2.4\build\GitVersionTask.targets(10,9): Error : NameConflictException: failed to write reference 'refs/heads/master': a reference with that name already exists.
This branch obviously always has been called "master", so it is not a casing issue in our case.
We have PR triggered builds turned off. We trigger builds on every checkin. So in our case it is not on PR builds.
I also cannot reproduce it locally
Our VS solution has 3 projects with "GitVersionTask" installed. When I remove the "GitVersionTask" from 1 project (an leave it in the other 2). The build succeeds. So the task works fine in the other 2 projects. If I then add the "GitVersionTask" back to the 3th project, the build still succeeds. But when I then make any other change/checkin, the build fails again with the same error message.
Does this make any sense to anyone?
I see here that some more information is being logged:
https://github.com/GitTools/GitTools.Core/blob/master/src/GitTools.Core/Git/Helpers/GitRepositoryHelper.cs#L155
Is there a way to turn this logging on, on the GitVersionTask?
LibGit2Sharp was upgraded to version 0.27.0-preview-0034 in 438d45004092e2f6b9aa4d12b07c64becfff4031 and released as a part of version 5.3.2 of GitVersion. Can you please perform an upgrade and see whether the problem still exists there?
Regarding logging in the task, @eriksteinebach, I believe that is something you need to adjust with MSBuild on the command line when you build the solution/project.
Still failing with version 5.3.2:
[Step 1/13] LibGit2Sharp.NameConflictException: failed to write reference 'refs/heads/feature/ESF-875-branch-cleanup': a reference with that name already exists.
[Step 1/13] at LibGit2Sharp.Core.Ensure.HandleError(Int32 result)
[Step 1/13] at LibGit2Sharp.Core.Ensure.ZeroResult(Int32 result)
[Step 1/13] at LibGit2Sharp.Core.Proxy.git_reference_create(RepositoryHandle repo, String name, ObjectId targetId, Boolean allowOverwrite, String logMessage)
[Step 1/13] at LibGit2Sharp.ReferenceCollection.Add(String name, ObjectId targetId, String logMessage, Boolean allowOverwrite)[09:25:23]
[Step 1/13] at LibGit2Sharp.ReferenceCollection.Add(String name, ObjectId targetId)
[Step 1/13] at GitVersion.Extensions.RepositoryExtensions.EnsureLocalBranchExistsForCurrentBranch(IRepository repo, ILog log, Remote remote, String currentBranch)
[Step 1/13] at GitVersion.GitPreparer.NormalizeGitDirectory(String gitDirectory, Boolean noFetch, String currentBranch, Boolean isDynamicRepository)
[Step 1/13] at GitVersion.GitPreparer.NormalizeGitDirectory(String targetBranch, String gitDirectory, Boolean isDynamicRepository)
[Step 1/13] at GitVersion.GitPreparer.PrepareInternal(Boolean normalizeGitDirectory, String currentBranch, Boolean shouldCleanUpRemotes)
[Step 1/13] at GitVersion.GitPreparer.Prepare()
[Step 1/13] at GitVersion.GitVersionTool.CalculateVersionVariables()
[Step 1/13] at GitVersion.GitVersionExecutor.RunGitVersionTool(GitVersionOptions gitVersionOptions)
Ok, so these are most likely the problematic lines:
So I suppose CanonicalName and localCanonicalName must differ, somehow. If someone could dig up the logs for when this is failing, it would be interesting to see what the log.Info() statement on line 59 writes to the log.
After hours of debugging and scratching my head, I managed to solve this problem for my case. I noticed that the exception was thrown on one build node, and others had no problems running GitVersion. Running it manually also worked fine. After excluding my problematic build node and having merged a change to master, I got a new error:
[Updating sources] Failed to perform checkout on agent: '"C:\Program Files\Git\bin\git.exe" update-ref --stdin -z' command failed.
exit code: 128
stderr: fatal: cannot lock ref 'refs/heads/featurE/feat-test': Unable to create '<path to build node area>/system/git/git-<somehash>.git/refs/heads/featurE/feat-test.lock': File exists.
This made me realize I had a typo in the name of my feature branch (note the capitalized E). After some testing, it seems I am able to reproduce this bug with the following steps (it is important that everything is built on the same build node):
featurE/feat-1, add a commit, push, and let the build server build this, this will go fine.feature/feat-2, add a commit, and push it. GitVersion will then crash with the NameConflictException error above.I managed to get out of this problem by removing all the feature branches remotely and deleting the git data cache (my case this was in <path to build node area>\system\git\git-<somehash>.git). My CI server would then be able to build feature branches again. Since I am running on Windows, I get the feeling this problem can be related to how Windows is non-case-sensitive and some parts of git is not handling this well. It could also be related to how my CI server interacts with git, since the featurE typo somehow spread onto the name of other feature branches that it pulled remotely.
Great discovery, @martinmine. Case sensitivity explains the problem quite well. We need to fix this in GitVersion so branches are always compared case insensitively.
Interesting thing is that my problem went away by switching from using the GitVersionTask nuget package in the projects to using GitVersionTask (installed through the marketplace) as a step in my build and using the generated version number during the build of the project.
Not sure why, maybe the problematic code is limited to the nuget package or maybe I started using a new build agent. But the task has worked very stable for me where I had multiple problems with the nuget package. And the task gives me better insight in the version being used, so I really like the Task approach better (for anyone else running into this issue).
:tada: This issue has been resolved in version 5.3.3 :tada:
The release is available on:
Your GitReleaseManager bot :package::rocket:
I can confirm that the 5.3.3 solved the problem for my case 鉂わ笍
Thanks for the confirmation, @martinmine! 馃檹
Most helpful comment
I can confirm that the 5.3.3 solved the problem for my case 鉂わ笍