Skip to content

[Bug] Gitversion could not determine which branch to treat as the development branch #3091

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

Closed
sanjivpurohit opened this issue Apr 18, 2022 · 9 comments
Labels

Comments

@sanjivpurohit
Copy link

sanjivpurohit commented Apr 18, 2022

Describe the bug

ERROR [04/18/22 16:49:40:48] An unexpected error occurred:
System.InvalidOperationException: Gitversion could not determine which branch to treat as the development branch (default is 'develop') nor release-able 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(Int[32](https://github.com/Logitech/astro-leia/runs/6065381621?check_suite_focus=true#step:5:32) recursions, IBranch targetBranch, BranchConfig branchConfiguration, ICommit currentCommit, Config configuration, IList`1 excludedInheritBranches) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Configuration\BranchConfigurationCalculator.cs:line 150
   at GitVersion.Configuration.BranchConfigurationCalculator.GetBranchConfigurationInternal(Int32 recursions, IBranch targetBranch, ICommit currentCommit, Config configuration, IList`1 excludedInheritBranches) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Configuration\BranchConfigurationCalculator.cs:line 54
   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 28
   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](https://github.com/Logitech/astro-leia/runs/6065381621?check_suite_focus=true#step:5: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 52
   at GitVersion.GitVersionExecutor.RunGitVersionTool(GitVersionOptions gitVersionOptions) in D:\a\GitVersion\GitVersion\src\GitVersion.App\GitVersionExecutor.cs:line 66

Expected Behavior

SemVer

Actual Behavior

Unexpected error

Possible Fix

Steps to Reproduce

Context

Your Environment

Gitversion 5.10.1
  • Version Used:
  • Operating System and version (Windows 10, Ubuntu 18.04): Ubuntu 18.04 Gitversion 5.10.1
  • Link to your project:
  • Link to your CI build (if appropriate):
@asbjornu
Copy link
Member

asbjornu commented Apr 19, 2022

We would need more information to resolve this. My hunch is that the checkout is a detached HEAD or a shallow clone. Please refer to GitVersion's requirements.

@sanjivpurohit
Copy link
Author

The checkout was on a branch. The clone was a deep clone using checkout@v2 actions with fetch-depth set to 0.

@asbjornu
Copy link
Member

Are you able to reproduce this in a public repository?

@sanjivpurohit
Copy link
Author

I don't work much with public repository. The github repository contained Main and master branch but the default branch was master. I have now deleted the main branch and would test again. I would add more logs as I keep testing it.

@PaulFarry
Copy link

If you are running this inside Azure Devops, make sure that you have set the Pipeline to not shallow Fetch .

Edit Pipeline -> Elipsis(top right) -> Triggers -> YAML -> Get Sources

image

This took me quite some time to figure out.

@pavelmateju
Copy link

pavelmateju commented Sep 8, 2022

This one sort it out for us ( we are using azure repos / devops )

- stage: One
    variables:
    #preventing git shallow clone
    Agent.Source.Git.ShallowFetchDepth: 0    
    #. . rest of your pipeline

This prevents azure default checkout task from running a git shallow clone.

Other option is to set this in the azure DevOps UI on the pipeline triggers (UNCHECK "Shallow fetch"). As @PaulFarry mentioned just above me :-)

image

@asbjornu asbjornu changed the title [Bug]Unexpected Error [Bug] Gitversion could not determine which branch to treat as the development branch Sep 10, 2022
@s-marrone
Copy link

Worked for us! Thanks @pavelmateju

@github-actions
Copy link

github-actions bot commented Mar 4, 2023

This issue has been automatically marked as stale because it has not had recent activity. After 30 days from now, it will be closed if no further activity occurs.

@github-actions github-actions bot added the stale label Mar 4, 2023
@github-actions
Copy link

github-actions bot commented Apr 4, 2023

This issue was closed because it has been stalled for 30 days with no activity. Thank you for your contributions

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 4, 2023
@arturcic arturcic removed the stale label Oct 30, 2023
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

6 participants