GitVersion icon indicating copy to clipboard operation
GitVersion copied to clipboard

[Bug] When multiple remote `master` branches exist, gitversion fails

Open rcdailey opened this issue 3 years ago • 3 comments

Describe the bug I have a topic branch named change-versioning with origin/master set to my remote tracking branch. When I only have one remote (named origin) everything works fine. However, once I add a second remote (named test) which also has a master branch, I get a failure stating it could not determine the development branch.

Expected Behavior

The dotnet-gitversion command should not fail because the remote tracking branch provides a hint as to which of the two master branches should be used.

Actual Behavior

The following failure occurs:

INFO [01/22/22 11:37:49:15] Working directory: E:\code\personal\trash-updater
INFO [01/22/22 11:37:49:17] Project root is: E:\code\personal\trash-updater\
INFO [01/22/22 11:37:49:17] DotGit directory is: E:\code\personal\trash-updater\.git
INFO [01/22/22 11:37:49:19] Begin: Loading version variables from disk cache
  INFO [01/22/22 11:37:49:19] Cache file E:\code\personal\trash-updater\.git\gitversion_cache\1FC769FD5AAEBDB659148C2D5A434CB23A1433C9.yml not found.
  INFO [01/22/22 11:37:49:19] End: Loading version variables from disk cache (Took: 0.46ms)
  INFO [01/22/22 11:37:49:28] Using latest commit on specified branch
  INFO [01/22/22 11:37:49:29] No branch configuration found for branch change-versioning, falling back to default configuration
  INFO [01/22/22 11:37:49:29] Begin: Attempting to inherit branch configuration from parent branch
    INFO [01/22/22 11:37:49:30] Begin: Finding branch source of 'change-versioning'
      INFO [01/22/22 11:37:49:31] Begin: Finding merge base between 'change-versioning' and 'origin/master'.
        INFO [01/22/22 11:37:49:32] Found merge base of d7295d4 build: Move to Composite Ready2Run
        INFO [01/22/22 11:37:49:33] Merge base of change-versioning' and 'origin/master is d7295d4 build: Move to Composite Ready2Run
      INFO [01/22/22 11:37:49:33] End: Finding merge base between 'change-versioning' and 'origin/master'. (Took: 13.81ms)
      INFO [01/22/22 11:37:49:33] Begin: Finding merge base between 'change-versioning' and 'test/master'.
        INFO [01/22/22 11:37:49:33] Found merge base of 9135f49 ci: Do full build in SonarCloud step
        INFO [01/22/22 11:37:49:33] Merge base of change-versioning' and 'test/master is 9135f49 ci: Do full build in SonarCloud step
      INFO [01/22/22 11:37:49:33] End: Finding merge base between 'change-versioning' and 'test/master'. (Took: 1.45ms)
      INFO [01/22/22 11:37:49:33] Multiple source branches have been found, picking the first one (test/master).
This may result in incorrect commit counting.
Options were:
test/master, origin/master
    INFO [01/22/22 11:37:49:33] End: Finding branch source of 'change-versioning' (Took: 27.83ms)
    INFO [01/22/22 11:37:49:34] Begin: Getting branches containing the commit '9135f49'.
      INFO [01/22/22 11:37:49:34] Trying to find direct branches.
      INFO [01/22/22 11:37:49:34] No direct branches found, searching through all branches.
      INFO [01/22/22 11:37:49:34] Searching for commits reachable from 'origin/master'.
      INFO [01/22/22 11:37:49:35] The branch 'origin/master' has no matching commits.
    INFO [01/22/22 11:37:49:35] End: Getting branches containing the commit '9135f49'. (Took: 11.65ms)
    INFO [01/22/22 11:37:49:35] Found possible parent branches: 
  INFO [01/22/22 11:37:49:35] End: Attempting to inherit branch configuration from parent branch (Took: 57.10ms)
  ERROR [01/22/22 11:37:49:36] An unexpected error occurred:
System.InvalidOperationException: Gitversion could not determine which branch to treat as the development branch (default is 'develop') nor releaseable branch (default is 'main' or 'master'), either locally or remotely. Ensure the local clone and checkout match the requirements or considering using 'GitVersion Dynamic Repositories'
   at GitVersion.Configuration.BranchConfigurationCalculator.InheritBranchConfiguration(IBranch targetBranch, BranchConfig branchConfiguration, ICommit currentCommit, Config configuration, IList`1 excludedInheritBranches) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Configuration\BranchConfigurationCalculator.cs:line 134
   at GitVersion.Configuration.BranchConfigurationCalculator.GetBranchConfiguration(IBranch targetBranch, ICommit currentCommit, Config configuration, IList`1 excludedInheritBranches) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Configuration\BranchConfigurationCalculator.cs:line 44
   at GitVersion.GitVersionContextFactory.Create(GitVersionOptions gitVersionOptions) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Core\GitVersionContextFactory.cs:line 39
   at GitVersion.GitVersionCoreModule.<>c__DisplayClass0_0.<RegisterTypes>b__1() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\GitVersionCoreModule.cs:line 37
   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() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\VersionCalculation\NextVersionCalculator.cs:line 15
   at GitVersion.VersionCalculation.NextVersionCalculator.FindVersion() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\VersionCalculation\NextVersionCalculator.cs:line 30
   at GitVersion.GitVersionCalculateTool.CalculateVersionVariables() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Core\GitVersionCalculateTool.cs:line 51
   at GitVersion.GitVersionExecutor.RunGitVersionTool(GitVersionOptions gitVersionOptions) in D:\a\GitVersion\GitVersion\src\GitVersion.App\GitVersionExecutor.cs:line 66
  INFO [01/22/22 11:37:49:36] Attempting to show the current git graph (please include in issue): 
  INFO [01/22/22 11:37:49:36] Showing max of 100 commits
  INFO [01/22/22 11:37:49:43] * bb60d77 2 minutes ago  (HEAD -> change-versioning)
| * 38d83e7 61 minutes ago  (test/master)
|/  
* 9135f49 66 minutes ago 
| * 33180d3 72 minutes ago  (origin/change-versioning)
|/  
* ecec240 14 hours ago 
| * f5a5ef7 14 hours ago  (git-release-manager)
| * 92a0477 14 hours ago 
|/  
* d7295d4 15 hours ago  (origin/master, origin/HEAD)
* 0da080f 15 hours ago 
* fadd8bd 15 hours ago 

Possible Fix

The remote tracking branch should be an additional factor in resolving the ambiguity between origin/master and test/master. In my case, I have my remote tracking branch set to origin/master, so that should be treated as the development branch (in the same way it would be treated that way if the test remote was removed)

Steps to Reproduce

  1. git clone https://github.com/rcdailey/trash-updater.git
  2. cd trash-updater
  3. git remote add test https://github.com/rcdailey/tu-test.git
  4. git fetch --all
  5. git checkout change-versioning-bug
  6. git branch -u origin/master
  7. dotnet-gitversion

Context

I typically utilize secondary remotes like this (which point to mirror copies of my origin repo) to test github workflow changes, especially those that affect my release process. However I imagine this would also happen in any tri-workflow situation where a user has more than one remote. Typically for other projects, I set my fork as fork remote and keep the upstream named origin. In this case, there will be a fork/master and origin/master. So I'm guessing the same issue will happen there as well.

Your Environment

Windows 10

  • Version Used: dotnet-gitversion: GitVersion 5.8.1+Branch.main.Sha.5c21ee61e344c142c7d18342d0a8ac4422636569
  • Operating System and version (Windows 10, Ubuntu 18.04): Windows 10 x64
  • Link to your project:
    • Main Repo: https://github.com/rcdailey/trash-updater
    • Test Repo: https://github.com/rcdailey/tu-test
  • Link to your CI build (if appropriate): N/A

rcdailey avatar Jan 22 '22 18:01 rcdailey

Sounds like this should be possible to reproduce in a test. Could you please create one in a PR?

asbjornu avatar Mar 02 '22 23:03 asbjornu

Unfortunately, I already have too many time commitments. That is why I spent so much time on this issue providing a great amount of detail.

rcdailey avatar Mar 03 '22 00:03 rcdailey

@rcdailey, I followed your recipe and cannot reproduce the error. GitVersion 5.8.2 executes successfully:

$ dotnet gitversion
{
  "Major": 1,
  "Minor": 7,
  "Patch": 0,
  "PreReleaseTag": "change-versioning-bug.1",
  "PreReleaseTagWithDash": "-change-versioning-bug.1",
  "PreReleaseLabel": "change-versioning-bug",
  "PreReleaseLabelWithDash": "-change-versioning-bug",
  "PreReleaseNumber": 1,
  "WeightedPreReleaseNumber": 1,
  "BuildMetaData": 96,
  "BuildMetaDataPadded": "0096",
  "FullBuildMetaData": "96.Branch.change-versioning-bug.Sha.bb60d77e71a917684e077dbe5241b392d8496094",
  "MajorMinorPatch": "1.7.0",
  "SemVer": "1.7.0-change-versioning-bug.1",
  "LegacySemVer": "1.7.0-change-versioning-b1",
  "LegacySemVerPadded": "1.7.0-change-versionin0001",
  "AssemblySemVer": "1.7.0.0",
  "AssemblySemFileVer": "1.7.0.0",
  "FullSemVer": "1.7.0-change-versioning-bug.1+96",
  "InformationalVersion": "1.7.0-change-versioning-bug.1+96.Branch.change-versioning-bug.Sha.bb60d77e71a917684e077dbe5241b392d8496094",
  "BranchName": "change-versioning-bug",
  "EscapedBranchName": "change-versioning-bug",
  "Sha": "bb60d77e71a917684e077dbe5241b392d8496094",
  "ShortSha": "bb60d77",
  "NuGetVersionV2": "1.7.0-change-versionin0001",
  "NuGetVersion": "1.7.0-change-versionin0001",
  "NuGetPreReleaseTagV2": "change-versionin0001",
  "NuGetPreReleaseTag": "change-versionin0001",
  "VersionSourceSha": "dc6bcdb43074ffcd3cafaeeb0e6f93ffb61ac8b3",
  "CommitsSinceVersionSource": 96,
  "CommitsSinceVersionSourcePadded": "0096",
  "UncommittedChanges": 0,
  "CommitDate": "2022-01-22"
}

asbjornu avatar Mar 03 '22 19:03 asbjornu

I cannot reproduce this with latest 6.0.0 beta-2 Closing

arturcic avatar Apr 13 '23 15:04 arturcic