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] GitVersion is crashing when trying to update AssemblyInfo.cs files. #2605

Closed
robbrattonUPMC opened this issue Feb 24, 2021 · 7 comments · Fixed by #3064
Closed

[Bug] GitVersion is crashing when trying to update AssemblyInfo.cs files. #2605

robbrattonUPMC opened this issue Feb 24, 2021 · 7 comments · Fixed by #3064
Labels
Milestone

Comments

@robbrattonUPMC
Copy link

robbrattonUPMC commented Feb 24, 2021

Describe the bug
Command used in Windows 10 command prompt or PowerShell as well as Azure DevOps build pipeline:
gitversion /updateassemblyinfo
GitVersion is crashing when trying to update AssemblyInfo.cs files.

Expected Behavior

I expected the version in the GitVersion.yml file to be applied to the AssemblyInfo.cs files since it is higher than the latest tag.

Actual Behavior

INFO [02/24/21 12:02:31:25] Working directory: C:\git\Upmc.ServiceBus.Common.V3
INFO [02/24/21 12:02:31:29] Project root is: C:\git\Upmc.ServiceBus.Common.V3\
INFO [02/24/21 12:02:31:29] DotGit directory is: C:\git\Upmc.ServiceBus.Common.V3\.git
INFO [02/24/21 12:02:31:34] Begin: Loading version variables from disk cache
  INFO [02/24/21 12:02:31:34] Begin: Deserializing version variables from cache file C:\git\Upmc.ServiceBus.Common.V3\.git\gitversion_cache\C39A271AF962B211C0A0EB6135B5B939FBB199F0.yml
    WARN [02/24/21 12:02:31:40] Unable to read cache file C:\git\Upmc.ServiceBus.Common.V3\.git\gitversion_cache\C39A271AF962B211C0A0EB6135B5B939FBB199F0.yml, deleting it.
    INFO [02/24/21 12:02:31:41] System.InvalidOperationException: Sequence contains no matching element
   at GitVersion.OutputVariables.VersionVariables.FromFile(String filePath, IFileSystem fileSystem, ILog log)
   at GitVersion.VersionCalculation.Cache.GitVersionCache.LoadVersionVariablesFromDiskCache(GitVersionCacheKey key)
  INFO [02/24/21 12:02:31:41] End: Deserializing version variables from cache file C:\git\Upmc.ServiceBus.Common.V3\.git\gitversion_cache\C39A271AF962B211C0A0EB6135B5B939FBB199F0.yml (Took: 72.49ms)
  INFO [02/24/21 12:02:31:41] End: Loading version variables from disk cache (Took: 73.39ms)
  INFO [02/24/21 12:02:31:45] Using latest commit on specified branch
  INFO [02/24/21 12:02:31:46] Begin: Attempting to inherit branch configuration from parent branch
    INFO [02/24/21 12:02:31:47] Begin: Finding branch source of 'feature/UpdateEventConvention'
      INFO [02/24/21 12:02:31:48] Begin: Finding merge base between 'feature/UpdateEventConvention' and 'develop'.
        INFO [02/24/21 12:02:31:49] Found merge base of e50099d Merged PR 40222: refactored multi-client code
        INFO [02/24/21 12:02:31:49] Merge base of feature/UpdateEventConvention' and 'develop is e50099d Merged PR 40222: refactored multi-client code
      INFO [02/24/21 12:02:31:49] End: Finding merge base between 'feature/UpdateEventConvention' and 'develop'. (Took: 12.31ms)
      INFO [02/24/21 12:02:31:49] Begin: Finding merge base between 'feature/UpdateEventConvention' and 'master'.
      INFO [02/24/21 12:02:31:50] End: Finding merge base between 'feature/UpdateEventConvention' and 'master'. (Took: 4.28ms)
    INFO [02/24/21 12:02:31:50] End: Finding branch source of 'feature/UpdateEventConvention' (Took: 27.41ms)
  INFO [02/24/21 12:02:31:50] End: Attempting to inherit branch configuration from parent branch (Took: 41.27ms)
  ERROR [02/24/21 12:02:31:50] An unexpected error occurred:
System.AggregateException: One or more errors occurred. (Object reference not set to an instance of an object.)
 ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at GitVersion.GitObject..ctor(GitObject innerGitObject)
   at GitVersion.Commit..ctor(Commit innerCommit)
   at GitVersion.GitRepository.<>c__DisplayClass27_0.<FindMergeBase>b__0()
   at GitVersion.Helpers.OperationWithExponentialBackoff`2.ExecuteAsync()
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at System.Threading.Tasks.Task`1.get_Result()
   at GitVersion.GitRepository.FindMergeBase(ICommit commit, ICommit otherCommit)
   at GitVersion.RepositoryStore.FindMergeBase(IBranch branch, IBranch otherBranch)
   at GitVersion.RepositoryStore.<>c__DisplayClass29_0.<GetMergeCommitsForBranch>b__2(IBranch otherBranch)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.ToArray()
   at System.Linq.OrderedEnumerable`1.ToList()
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at GitVersion.RepositoryStore.GetMergeCommitsForBranch(IBranch branch, Config configuration, IEnumerable`1 excludedBranches)
   at GitVersion.RepositoryStore.FindCommitBranchWasBranchedFrom(IBranch branch, Config configuration, IBranch[] excludedBranches)
   at GitVersion.Configuration.BranchConfigurationCalculator.InheritBranchConfiguration(IBranch targetBranch, BranchConfig branchConfiguration, ICommit currentCommit, Config configuration, IList`1 excludedInheritBranches)
   at GitVersion.Configuration.BranchConfigurationCalculator.GetBranchConfiguration(IBranch targetBranch, ICommit currentCommit, Config configuration, IList`1 excludedInheritBranches)
   at GitVersion.GitVersionContextFactory.Create(GitVersionOptions gitVersionOptions)
   at GitVersion.GitVersionCoreModule.<>c__DisplayClass0_0.<RegisterTypes>b__3()
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.get_Value()
   at GitVersion.VersionCalculation.NextVersionCalculator.get_context()
   at GitVersion.VersionCalculation.NextVersionCalculator.FindVersion()
   at GitVersion.GitVersionCalculateTool.CalculateVersionVariables()
   at GitVersion.GitVersionExecutor.RunGitVersionTool(GitVersionOptions gitVersionOptions)
  INFO [02/24/21 12:02:31:50] Attempting to show the current git graph (please include in issue):
  INFO [02/24/21 12:02:31:50] Showing max of 100 commits
  INFO [02/24/21 12:02:31:64] * d6747b0 4 hours ago  (HEAD -> feature/UpdateEventConvention, origin/feature/UpdateEventConvention)
*   e50099d 3 months ago  (origin/develop, origin/HEAD, develop)
|\
| * 6f79c31 3 months ago
| * d7d38cc 3 months ago
| * 8afc799 3 months ago
| * 4694b49 3 months ago
| * 456f16b 3 months ago
| * aaf1cda 3 months ago
|/
*   57a1600 3 months ago
|\
| * 46fe446 3 months ago
| * 43eccb0 3 months ago
|/
*   dceedd3 3 months ago
|\
| * 68e98d5 3 months ago
| * a498213 3 months ago
| * 6ea2b1c 3 months ago
|/
*   82b1a08 3 months ago
|\
| * b73ff5b 3 months ago
| * a95447f 3 months ago
| * 9354355 3 months ago
| * bd08f2a 3 months ago
| * 3c14cf6 3 months ago
|/
*   7283a86 3 months ago
|\
| * 69a5031 3 months ago
| * d50b889 3 months ago
| * 977f94c 3 months ago
|/
* a2641e5 4 months ago
* 1855878 4 months ago
*   402dc3a 4 months ago
|\
| * 577636d 4 months ago
|/
*   0b317e6 5 months ago
|\
| * 5ac0df6 5 months ago
| *   b67e852 5 months ago
| |\
| |/
|/|
* |   efb2e3d 5 months ago
|\ \
| | * bc0ada2 5 months ago
| |/
| * 8eeb6ea 5 months ago
|/
*   702e36b 7 months ago
|\
| * fc1ef01 7 months ago
|/
*   89522b9 11 months ago
|\
| * 8855b5e 11 months ago
| * ed1858e 11 months ago
|/
*   df60e40 12 months ago
|\
| * 25be4e5 12 months ago
* | 0e243cc 12 months ago
|\|
| * 48a16b8 12 months ago
|/
*   71ce83b 12 months ago
|\
| * c66cc94 12 months ago
* | feeaf17 12 months ago
|\|
| * 40b0f17 12 months ago
| * 3b7d149 12 months ago
| * 55b655b 12 months ago
| * e849bf7 12 months ago
|/
*   b70bc0a 12 months ago
|\
| * 4deb182 12 months ago
| * 23d1ea7 12 months ago
| * 1625e5b 12 months ago
| * 36aeb2c 12 months ago
| * b6c1050 12 months ago
| * 0dbaaba 12 months ago
| * 9372f85 12 months ago
| * f3bdb09 12 months ago
| * 72b5e78 12 months ago
| * cad4f4d 12 months ago
| * f99323a 12 months ago
| * 45f3d8d 12 months ago
| * dd1c115 12 months ago
|/
*   5409029 1 year ago
|\
| * a4a01a9 1 year ago
|/
* 63c548d 1 year, 1 month ago
| * bb73ddf 12 months ago  (origin/master, master)
| * 132ae1b 1 year, 1 month ago  (tag: 2.3.1)
| *   f41353f 1 year, 2 months ago  (tag: 2.3.0)
| |\
| | * f268a2e 1 year, 2 months ago
| |/
|/|
* |   f4a6310 1 year, 2 months ago
|\ \
| * | 8d7e1a4 1 year, 2 months ago
| * | e137d84 1 year, 2 months ago
|/ /
* |   f04e6fe 1 year, 3 months ago
|\ \
| * | d377257 1 year, 3 months ago
|/| |
| * | 6cd047f 1 year, 3 months ago
| * | a93c885 1 year, 3 months ago
|/ /
* |   4a75a59 1 year, 4 months ago
|\ \
| * | 1b8d455 1 year, 4 months ago
| * | cb174f9 1 year, 4 months ago
|/ /
* |   f033008 1 year, 4 months ago
|\ \
| * | 60ea065 1 year, 4 months ago
| * |   7872bdc 1 year, 4 months ago
| |\ \
| |/ /
|/| |
* | |   f515d22 1 year, 5 months ago
|\ \ \
| * \ \   3caad66 1 year, 5 months ago
| |\ \ \
| |/ / /
|/| | |
| * | | 5a2365c 1 year, 5 months ago
| | * | 29f2400 1 year, 4 months ago
| |/ /
|/| |
* | |   a8f1ede 1 year, 5 months ago
|\ \ \
| |/ /
|/| |
| * | 74f7c7b 1 year, 5 months ago
| * | b1616ad 1 year, 5 months ago
|/ /
| *   26b501d 1 year, 6 months ago  (tag: 2.1.1)
| |\
| |/
|/|
* | a929ff5 1 year, 6 months ago
* | cc79df1 1 year, 6 months ago
* | 9c3a568 1 year, 6 months ago
* |   362e029 1 year, 7 months ago
|\ \
| * | 12fd747 1 year, 7 months ago
|/ /
| *   87c7bfd 1 year, 7 months ago  (tag: 2.0.5)
| |\
| | * 3c64ed5 1 year, 7 months ago
| |/
|/|
[GitVersion.yml.txt](https://github.com/GitTools/GitVersion/files/6038051/GitVersion.yml.txt)

Possible Fix

Steps to Reproduce

I am not able to share the source code from our internal Git source repository because of intellectual property.

Context

We use GitVersion as part of our Azure DevOps build pipelines to assign the assembly version information at build time.

Your Environment

Azure DevOps (hosted)
Classic Build Pipeline

  • Version Used: 5.6.6+Branch.main.Sha.80adc3f3b8919b655adca7b796b273fb10478c3f
  • Operating System and version (Windows 10 and Azure DevOps):
  • Link to your project: (Private)
  • Link to your CI build (if appropriate): (Private)
@robbrattonUPMC
Copy link
Author

robbrattonUPMC commented Feb 24, 2021

Here are the stdout and stderr streams from GitVersion /diag captured to text files.
outstderr.txt
outstdout.txt

@asbjornu
Copy link
Member

Are you able to reproduce this error in a public repository or RepositoryFixture test so it can be debugged properly?

@robbrattonUPMC
Copy link
Author

I am not. It is UPMC's internal Azure DevOps hosted Git repo.

I haven't seen it in my own repos on GitHub.

@SanjayGuntur
Copy link

I came across this issue as well, but on a different set of steps. I was experimenting with ways to limit git history to a particular folder by running git branch-filter command. Running GitVersion on the filtered repository worked with 5.5.0, but failed with 5.6.6, at the same place @robbrattonUPMC reported.

It is possible for a branch to have a different history than that of its parent branch, orphan branches for example.

Here is a simple powershell script that reproduces the problem.

# Create a folder that we can reproduce the issue in
$folder = "c:\temp\GitVersion-2605"
New-Item -ItemType Directory -Path $folder | Out-Null

# Init git on this folder
Set-Location $folder | Out-Null
git init

# Add a file and commit
"File on master branch" | Out-File -FilePath file-on-master.txt
git add file-on-master.txt
git commit -m "Commit on master"

# Ensure new and old version of GitVersion work
\Tools\GitVersion.CommandLine.5.5.0\Tools\GitVersion.exe /showvariable SemVer
\Tools\GitVersion.CommandLine.5.6.6\Tools\GitVersion.exe /showvariable SemVer

# Create an orphan branch
git checkout --orphan orphan

# Add a file and commit to the orphan branch
"File on orphan branch" | Out-File -FilePath file-on-orphan.txt
git add file-on-orphan.txt
git commit -a -m "Commit on orphan"

# Ensure new and old version of GitVersion work
\Tools\GitVersion.CommandLine.5.5.0\Tools\GitVersion.exe /showvariable SemVer
\Tools\GitVersion.CommandLine.5.6.6\Tools\GitVersion.exe /showvariable SemVer

I'm happy to fix and write tests for this issue, if this is identified as a bug, or as an improvement.

@asbjornu
Copy link
Member

asbjornu commented Mar 8, 2021

@SanjayGuntur, pull requests with tests and fixes are welcome and greatly appreciated! 🙏🏼

@JordanOberrathUPMC
Copy link

I was running into the same issue and discovered that it happened if any of the branches in the repository had no commits. In my case it was the Master branch, which was not initialized with a ReadMe.md.
I noticed it because it failed on a pull request right where it was trying to find the merge base between the feature and master branch.
So, my question is, how can I get the GitVersion.exe /updateassemblyinfo to only consider the branches relevant to the merge when determining the merge base, and to ignore all other branches?

@asbjornu asbjornu mentioned this issue Apr 2, 2022
5 tasks
@asbjornu asbjornu added this to the 5.x milestone Apr 2, 2022
@arturcic arturcic modified the milestones: 5.x, 5.10.0 Apr 14, 2022
@github-actions
Copy link

🎉 This issue has been resolved in version 5.10.0 🎉
The release is available on:

Your GitReleaseManager bot 📦🚀

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

Successfully merging a pull request may close this issue.

5 participants