Skip to content
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

[Bug] Build failing with "failed to write reference" error #2593

Closed
joaorosado opened this issue Feb 10, 2021 · 6 comments
Closed

[Bug] Build failing with "failed to write reference" error #2593

joaorosado opened this issue Feb 10, 2021 · 6 comments
Labels

Comments

@joaorosado
Copy link

joaorosado commented Feb 10, 2021

Describe the bug
I'm trying to update from GitVersionTask 5.5.1 to GitVersion.MsBuild 5.6.6 and the builds fail on my Azure DevOps pipeline.
It doesn't seem to happen on all repositories. Was able to update one successfully but fails on another.

The error I get is
LibGit2Sharp.NameConflictException: failed to write reference 'refs/heads/pull/53/merge': a reference with that name already exists.

I cannot replicate it with a local checkout of the branch nor on Azure if the requested build if for the branch instead of the pull request.

Expected Behavior

The build to work in PR on Azure DevOps

Actual Behavior

Fails with failed to write reference error in PR

Steps to Reproduce

Not sure how to reproduce the issue with a simple example.
Found an old issue that talked about the branch names being case sensitive but it does not seem to apply since only the PR build has issues.

Here is the log context:

2021-02-10T15:57:50.4812770Z Executing: "C:/Program Files/dotnet/dotnet.exe" msbuild /property:configuration=Release "../"
2021-02-10T15:57:51.0945795Z Microsoft (R) Build Engine version 16.8.3+39993bd9d for .NET
2021-02-10T15:57:51.0946710Z Copyright (C) Microsoft Corporation. All rights reserved.
2021-02-10T15:57:51.0946944Z 
2021-02-10T15:57:54.1970242Z   Sonar: (Redacted.ProjectName.Sources.csproj) Project processed successfully
2021-02-10T15:57:56.8943420Z   INFO [02/10/21 15:57:55:78] Applicable build agent found: 'AzurePipelines'.
2021-02-10T15:57:56.8946628Z   INFO [02/10/21 15:57:55:89] Working directory: D:\a\1\s\src\Redacted.ProjectName.IntegrationStudio
2021-02-10T15:57:56.8952312Z   INFO [02/10/21 15:57:56:12] Branch from build environment: refs/pull/53/merge
2021-02-10T15:57:56.8958389Z   INFO [02/10/21 15:57:56:12] Project root is: D:\a\1\s\
2021-02-10T15:57:56.8964508Z   INFO [02/10/21 15:57:56:12] DotGit directory is: D:\a\1\s\.git
2021-02-10T15:57:56.9076196Z   INFO [02/10/21 15:57:56:12] Begin: Normalizing git directory for branch 'refs/pull/53/merge'
2021-02-10T15:57:56.9091860Z     INFO [02/10/21 15:57:56:21] One remote found (origin -> 'https://github.com/Redacted/Redacted.ProjectName').
2021-02-10T15:57:56.9100187Z     INFO [02/10/21 15:57:56:22] Skipping fetching, if GitVersion does not calculate your version as expected you might need to allow fetching or use dynamic repositories
2021-02-10T15:57:56.9104102Z     INFO [02/10/21 15:57:56:23] Creating local branch pull/53/merge pointing at 32ff85a
2021-02-10T15:57:56.9112539Z     INFO [02/10/21 15:57:56:28] End: Normalizing git directory for branch 'refs/pull/53/merge' (Took: 161.89ms)
2021-02-10T15:57:56.9696597Z     ERROR [02/10/21 15:57:56:59] An unexpected error occurred:
2021-02-10T15:57:56.9745674Z   LibGit2Sharp.NameConflictException: failed to write reference 'refs/heads/pull/53/merge': a reference with that name already exists.
2021-02-10T15:57:56.9754227Z      at LibGit2Sharp.Core.Ensure.HandleError(Int32 result)
2021-02-10T15:57:56.9758808Z      at LibGit2Sharp.Core.Ensure.ZeroResult(Int32 result)
2021-02-10T15:57:56.9764769Z      at LibGit2Sharp.Core.Proxy.git_reference_create(RepositoryHandle repo, String name, ObjectId targetId, Boolean allowOverwrite, String logMessage)
2021-02-10T15:57:56.9974024Z      at LibGit2Sharp.ReferenceCollection.Add(String name, ObjectId targetId, String logMessage, Boolean allowOverwrite)
2021-02-10T15:57:57.0054593Z      at LibGit2Sharp.ReferenceCollection.Add(String name, String canonicalRefNameOrObjectish, String logMessage, Boolean allowOverwrite)
2021-02-10T15:57:57.0070712Z      at LibGit2Sharp.ReferenceCollection.Add(String name, String canonicalRefNameOrObjectish, Boolean allowOverwrite)
2021-02-10T15:57:57.0074893Z      at GitVersion.ReferenceCollection.Add(String name, String canonicalRefNameOrObjectish, Boolean allowOverwrite) in D:\a\GitVersion\GitVersion\src\GitVersion.LibGit2Sharp\Git\ReferenceCollection.cs:line 20
2021-02-10T15:57:57.0078047Z      at GitVersion.GitPreparer.EnsureLocalBranchExistsForCurrentBranch(IRemote remote, String currentBranch) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Core\GitPreparer.cs:line 387
2021-02-10T15:57:57.0081005Z      at GitVersion.GitPreparer.NormalizeGitDirectory(Boolean noFetch, String currentBranchName, Boolean isDynamicRepository) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Core\GitPreparer.cs:line 191
2021-02-10T15:57:57.0085759Z      at GitVersion.GitPreparer.NormalizeGitDirectory(String targetBranch, Boolean isDynamicRepository) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Core\GitPreparer.cs:line 144
2021-02-10T15:57:57.0089668Z      at GitVersion.GitPreparer.PrepareInternal(Boolean normalizeGitDirectory, String currentBranch, Boolean shouldCleanUpRemotes) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Core\GitPreparer.cs:line 76
2021-02-10T15:57:57.0096181Z      at GitVersion.GitPreparer.Prepare() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Core\GitPreparer.cs:line 57
2021-02-10T15:57:57.0099779Z      at GitVersion.GitVersionCalculateTool.CalculateVersionVariables() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Core\GitVersionCalculateTool.cs:line 45
2021-02-10T15:57:57.0134101Z      at GitVersion.GitVersionExecutor.RunGitVersionTool(GitVersionOptions gitVersionOptions) in D:\a\GitVersion\GitVersion\src\GitVersion.App\GitVersionExecutor.cs:line 61
2021-02-10T15:57:57.0138843Z     INFO [02/10/21 15:57:56:59] Attempting to show the current git graph (please include in issue): 
2021-02-10T15:57:57.0144980Z     INFO [02/10/21 15:57:56:59] Showing max of 100 commits
2021-02-10T15:57:57.0147579Z     INFO [02/10/21 15:57:56:87] *   32ff85a 3 minutes ago  (HEAD -> pull/53/merge, pull/53/merge, origin/32ff85a16f645d6f8f7156fa4ad44ee5f58752e9, 32ff85a16f645d6f8f7156fa4ad44ee5f58752e9)
2021-02-10T15:57:57.0150444Z   |\  
2021-02-10T15:57:57.0152512Z   | *   7888c39 3 minutes ago  (origin/rename-gitversion, rename-gitversion)
2021-02-10T15:57:57.0156515Z   | |\  
2021-02-10T15:57:57.0159394Z   | |/  
2021-02-10T15:57:57.0165564Z   |/|   
2021-02-10T15:57:57.0167762Z   * | 2bb232c 58 minutes ago  (origin/master, master)
2021-02-10T15:57:57.0169858Z   * | 83bbb37 68 minutes ago 
2021-02-10T15:57:57.0171816Z   | * f77e917 2 hours ago 
2021-02-10T15:57:57.0174614Z   |/  
2021-02-10T15:57:57.0176728Z   | *   9e67aa1 3 hours ago  (origin/RRCT-3467-RabbitMQDispose, RRCT-3467-RabbitMQDispose)
2021-02-10T15:57:57.0178896Z   | |\  
2021-02-10T15:57:57.0180652Z   | |/  
2021-02-10T15:57:57.0189704Z   |/|   
2021-02-10T15:57:57.0191880Z   * | 53ff862 3 hours ago 
2021-02-10T15:57:57.0194742Z   | * fc7384d 19 hours ago 
2021-02-10T15:57:57.0197508Z   | * ee7a934 19 hours ago 
2021-02-10T15:57:57.0199536Z   | * 5270da7 20 hours ago 
2021-02-10T15:57:57.0201275Z   | * 942e75f 20 hours ago 
2021-02-10T15:57:57.0205035Z   | * 8576196 20 hours ago 
2021-02-10T15:57:57.0211006Z   | * 7f9a5d8 20 hours ago 
2021-02-10T15:57:57.0215678Z   | * f2b7128 20 hours ago 
2021-02-10T15:57:57.0217757Z   | * f6e8796 23 hours ago 
2021-02-10T15:57:57.0221854Z   | * 2344dfb 23 hours ago 
2021-02-10T15:57:57.0265429Z   | *   4149eae 24 hours ago 
2021-02-10T15:57:57.0270674Z   | |\  
2021-02-10T15:57:57.0280334Z   | |/  
2021-02-10T15:57:57.0287237Z   |/|   
2021-02-10T15:57:57.0289229Z   * | 5d94352 24 hours ago 
2021-02-10T15:57:57.0292478Z   | *   d986fcc 25 hours ago 
2021-02-10T15:57:57.0297509Z   | |\  
2021-02-10T15:57:57.0302576Z   | |/  
2021-02-10T15:57:57.0305591Z   |/|   
2021-02-10T15:57:57.0315212Z   * |   aa1a811 26 hours ago 
2021-02-10T15:57:57.0317349Z   |\ \  
2021-02-10T15:57:57.0320610Z   | * | 9c95318 27 hours ago 
2021-02-10T15:57:57.0322676Z   |/ /  
2021-02-10T15:57:57.0326639Z   | * c792213 25 hours ago 
2021-02-10T15:57:57.0328849Z   | * 4858157 26 hours ago 
2021-02-10T15:57:57.0344910Z   | * 6e60c52 26 hours ago 
2021-02-10T15:57:57.0346803Z   | * 6ed8b6e 26 hours ago 
2021-02-10T15:57:57.0348550Z   | * 474fe4d 26 hours ago 
2021-02-10T15:57:57.0350219Z   | * d78aea0 26 hours ago 
2021-02-10T15:57:57.0356786Z   | * 512a288 26 hours ago 
2021-02-10T15:57:57.0359128Z   | * 3df4761 26 hours ago 
2021-02-10T15:57:57.0362320Z   | * fedf07f 27 hours ago 
2021-02-10T15:57:57.0366570Z   | * ca9105e 27 hours ago 
2021-02-10T15:57:57.0368623Z   | * 4127e0e 27 hours ago 
2021-02-10T15:57:57.0370344Z   | * c7aa7edc 27 hours ago 
2021-02-10T15:57:57.0373163Z   | * 9a0a16f 27 hours ago 
2021-02-10T15:57:57.0375817Z   | * f6f397c 28 hours ago 
2021-02-10T15:57:57.0378280Z   | * 54d2018 28 hours ago 
2021-02-10T15:57:57.0380213Z   | * 46c7352 28 hours ago 
2021-02-10T15:57:57.0382647Z   | * 2bbc132 29 hours ago 
2021-02-10T15:57:57.0384675Z   | * 58d623e 29 hours ago 
2021-02-10T15:57:57.0386551Z   | * 75043d5 29 hours ago 
2021-02-10T15:57:57.0405246Z   | * eaa5e1e 29 hours ago 
2021-02-10T15:57:57.0408941Z   | * 0c67853 30 hours ago 
2021-02-10T15:57:57.0444778Z   | * 92f1511 30 hours ago 
2021-02-10T15:57:57.0456556Z   | * dede3c2 30 hours ago 
2021-02-10T15:57:57.0570786Z   | * 50efe70 2 days ago 
2021-02-10T15:57:57.0574803Z   | * 7525c69 2 days ago 
2021-02-10T15:57:57.0579214Z   | * 0b12bc8 2 days ago 
2021-02-10T15:57:57.0582276Z   | * b59b565 2 days ago 
2021-02-10T15:57:57.0587039Z   | * df481d6 2 days ago 
2021-02-10T15:57:57.0619525Z   | * e55752e 2 days ago 
2021-02-10T15:57:57.0622226Z   | * fc0651c 7 days ago 
2021-02-10T15:57:57.0625796Z   |/  
2021-02-10T15:57:57.0628894Z   *   bb3a0ae 4 weeks ago 
2021-02-10T15:57:57.0629611Z   |\  
2021-02-10T15:57:57.0634329Z   | * 9ecd195 4 weeks ago 
2021-02-10T15:57:57.0635710Z   |/  
2021-02-10T15:57:57.0643045Z   *   d29ca53 5 weeks ago 
2021-02-10T15:57:57.0658421Z   |\  
2021-02-10T15:57:57.0667038Z   | * 96b980f 5 weeks ago 
2021-02-10T15:57:57.0673210Z   |/  
2021-02-10T15:57:57.0678113Z   | * 32e5b34 5 weeks ago  (origin/opendays2021_messages, opendays2021_messages)
2021-02-10T15:57:57.0684408Z   | * be0d79a 8 weeks ago 
2021-02-10T15:57:57.0688699Z   |/  
2021-02-10T15:57:57.0693822Z   | * 18ad696 7 weeks ago  (origin/paulomf-patch-1, paulomf-patch-1)
2021-02-10T15:57:57.0696114Z   |/  
2021-02-10T15:57:57.0697164Z   *   f28165f 8 weeks ago 
2021-02-10T15:57:57.0698957Z   |\  
2021-02-10T15:57:57.0700275Z   | * da22e59 9 weeks ago 
2021-02-10T15:57:57.0723630Z   | * 16be8eb 9 weeks ago 
2021-02-10T15:57:57.0746065Z   | * efd67b0 9 weeks ago 
2021-02-10T15:57:57.0747236Z   | * 422f236 9 weeks ago 
2021-02-10T15:57:57.0753954Z   | * 0b543cb 9 weeks ago 
2021-02-10T15:57:57.0755081Z   | * 3279d1c 9 weeks ago 
2021-02-10T15:57:57.0756343Z   | * f3379ad 9 weeks ago 
2021-02-10T15:57:57.0757349Z   | * 20d8096 9 weeks ago 
2021-02-10T15:57:57.0758532Z   | * 875535e 9 weeks ago 
2021-02-10T15:57:57.0765793Z   | * c6a160c 9 weeks ago 
2021-02-10T15:57:57.0767255Z   | * 93a35c7 9 weeks ago 
2021-02-10T15:57:57.0768713Z   | * c9f2fc0 9 weeks ago 
2021-02-10T15:57:57.0769727Z   | * 2993869 9 weeks ago 
2021-02-10T15:57:57.0770674Z   | * be500ec 9 weeks ago 
2021-02-10T15:57:57.0773036Z   | * 51f2c48 9 weeks ago 
2021-02-10T15:57:57.0775700Z   | * 186aa07 9 weeks ago 
2021-02-10T15:57:57.0781907Z   | * b6fb930 9 weeks ago 
2021-02-10T15:57:57.0783394Z   | * 7605c65 9 weeks ago 
2021-02-10T15:57:57.0784781Z   | * e38003d 9 weeks ago 
2021-02-10T15:57:57.0785755Z   | * 4e5a534 9 weeks ago 
2021-02-10T15:57:57.0787427Z   | * f5c93ab 9 weeks ago 
2021-02-10T15:57:57.0788646Z   | * 38c03de 9 weeks ago 
2021-02-10T15:57:57.0789890Z   | * b71b56c 9 weeks ago 
2021-02-10T15:57:57.0790935Z   | * 5f1df58 9 weeks ago 
2021-02-10T15:57:57.0792313Z   | * d40b591 9 weeks ago 
2021-02-10T15:57:57.0793292Z   | * f8fd1e1 9 weeks ago 
2021-02-10T15:57:57.0794195Z   | * da40ab9 9 weeks ago 
2021-02-10T15:57:57.0796326Z   | * d8edd1c 9 weeks ago 
2021-02-10T15:57:57.0797210Z   | * a95019b 9 weeks ago 
2021-02-10T15:57:57.0798308Z   | * 3400b2a 9 weeks ago 
2021-02-10T15:57:57.0801535Z   | * 7ee5919 9 weeks ago 
2021-02-10T15:57:57.0802445Z   | * 3ba89a8 9 weeks ago 
2021-02-10T15:57:57.0803344Z   | * 2bee27c 9 weeks ago 
2021-02-10T15:57:57.0804208Z   | * 43f7493 9 weeks ago 
2021-02-10T15:57:57.0806391Z   | * 681acb3 9 weeks ago 
2021-02-10T15:57:57.0810280Z   | * c3288ae 9 weeks ago 
2021-02-10T15:57:57.0812877Z   | * 993d1f1 9 weeks ago 
2021-02-10T15:57:57.0813559Z   | * 88c4210 9 weeks ago 
2021-02-10T15:57:57.0814184Z   | * 67aefe7 9 weeks ago 
2021-02-10T15:57:57.0814812Z   | * 69f803b 9 weeks ago 
2021-02-10T15:57:57.0815456Z   | * 2c3a92d 9 weeks ago 
2021-02-10T15:57:57.0816014Z   
2021-02-10T15:57:57.0818462Z C:\Users\VssAdministrator\.nuget\packages\gitversion.msbuild\5.6.6\tools\GitVersion.MsBuild.targets(9,9): error MSB3073: The command "dotnet --roll-forward Major "C:\Users\VssAdministrator\.nuget\packages\gitversion.msbuild\5.6.6\tools\netcoreapp3.1/gitversion.dll" "D:\a\1\s\src\Redacted.ProjectName.IntegrationStudio" -output file -outputfile obj\gitversion.json" exited with code 1.```



## Context
Cannot upgrade to GitVersion.MsBuild 5.6.6

## Your Environment
Azure DevOps

- Version Used:
- Using "Image: windows-latest"
- Microsoft Windows Server 2019 10.0.17763
- Link to your project: <private repository>
- Link to your CI build: <private CI>
@joaorosado joaorosado added the bug label Feb 10, 2021
@joaorosado
Copy link
Author

Any idea what else I can check to get around this? Any command I could run to log more details?

I have no idea what is wrong on the repository structure that is causing it.

@asbjornu
Copy link
Member

A public repository that portrays the same error would be the only way I can assist you in finding the source of this bug.

@joaorosado
Copy link
Author

Hi @asbjornu

Was able to fix it on this repository. One of the differences between this was that on the others I already had workaround the #1381 issue with /maxcpucount:1 on the build/package commands.

Applying the same workaround here seems to have fixed this as well, so it looks like a concurrency issue again :(

I can't really share the repository but I does not have anything special in terms of structure: just a solution with 3 library projects and 1 test project.

@asbjornu
Copy link
Member

asbjornu commented Mar 2, 2021

Thanks for the information. Sounds like a race condition that #2581 should have helped remedy, but perhaps this is in another code path.

@jbaehr
Copy link
Contributor

jbaehr commented Jun 22, 2022

Today I got hit by this too -- out of the blue. Using GitLab-CI on Linux containers in Kubernetes.
Upgrading GitVersion.MsBuild from 5.6.9 to 5.10.3 fixed the issue here. However, as it started to appear without any other obvious change, it maybe just has disappears the same mysterious way, independently of the update.

@asbjornu
Copy link
Member

Since you saw the error being fixed, @jbaehr, and we haven't received any other reports of this error, I'm closing this as fixed. Please comment if you experience this again and I'll reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants