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

[Improvement] Confusing Exception message: "Could not find a 'develop' or 'main' branch, neither locally nor remotely." #2598

Closed
odalet opened this issue Feb 16, 2021 · 10 comments · Fixed by #2738
Milestone

Comments

@odalet
Copy link
Contributor

odalet commented Feb 16, 2021

When I read this error message, I thought my 'master' branch was not recognized by GitVersion whereas the problem was completely unrelated.

Detailed Description

I was trying to have GitVersion work on a private GitLab instance of ours (I'm still a beginner concerning GitLab) and was presented with this exception. I wrongly assumed there was a problem with GitVersion not finding my 'master' branch... Even tried to declare it in GitVersion.yml but that was for naught. It appears the problem was on the GitLab side due to how we had configured the way it retrieves a git clone (a detached head only listing a unique (non-master) remote branch, no wonder GitVersion didn't work).

I understand, by reading GitVersion code, that 'develop' and 'main' are not real branch names, but rather monikers to whatever the development and the main/principal branch are, but the quotation and the fact they can be real branch names as well is, I suppose, the source of my confusion.

I think that the message either:

  • should list 'master' along 'main' as one of the branches that could not be found:

Could not find a 'develop' or 'main' or 'master' branch, neither locally nor remotely.

  • or avoid the use of the quotes and try to have the reader understand we are talking about branch roles rather than branch names. Something along this line:

Could not find any development or main branch, neither locally nor remotely.

Context

I think this (obvioulsy simple and dispendable) change may help diagnose issues like the one I had.

Possible Implementation

If one or the other of my propositions is accepted, I'll gladly modify the relevant string in a PR

@arturcic
Copy link
Member

I guess even better would be if we could use the actual names found in the configuration, as not all are using develop or main, but could be dev or other names. So better if the message displays that name instead

@odalet
Copy link
Contributor Author

odalet commented Feb 16, 2021

Yes, I suppose it'd be even better, but this is raised by an Exception... Note that I didn't have a look at the code (yet), so I can't say whether this is easy or not. For information, here is the Exception trace:

    ERROR [02/16/21 10:01:23:02] An unexpected error occurred:
  System.InvalidOperationException: Could not find a 'develop' or 'main' branch, neither locally nor remotely.
     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) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Configuration\BranchConfigurationCalculator.cs:line 47
     at GitVersion.GitVersionContextFactory.Create(GitVersionOptions gitVersionOptions) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Core\GitVersionContextFactory.cs:line 40
     at GitVersion.GitVersionCoreModule.<>c__DisplayClass0_0.<RegisterTypes>b__3() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\GitVersionCoreModule.cs:line 61
     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 17
     at GitVersion.VersionCalculation.NextVersionCalculator.FindVersion() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\VersionCalculation\NextVersionCalculator.cs:line 32
     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 61

@arturcic
Copy link
Member

throw new InvalidOperationException("Could not find a 'develop' or 'main' branch, neither locally nor remotely.");

@stale
Copy link

stale bot commented Jun 2, 2021

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. Thank you for your contributions.

@stale stale bot added the stale label Jun 2, 2021
@DarwinJS
Copy link
Contributor

DarwinJS commented Jun 24, 2021

I am having this exact problem here when using the default config and I agree that the error seems almost intentionally misleading.

I think the error should be more explicit than the original @odalet suggests:

'Gitversion could not determine which branch to treat as the development branch (default = develop) nor release branch (default = main or master), neither locally nor remotely. Consider diagnosing with git status ; git log -n 1"

@asbjornu
Copy link
Member

I agree the error message is bad. Pull requests to improve it are welcome.

@DarwinJS
Copy link
Contributor

@asbjornu - yes I actually submitted a PR against this issue.

@asbjornu
Copy link
Member

@DarwinJS, which PR is that?

@DarwinJS
Copy link
Contributor

Opps I had done it back to my own fork - fixed now!

@asbjornu asbjornu added this to the 5.6.11 milestone Jun 28, 2021
@github-actions
Copy link

🎉 This issue has been resolved in version 5.6.11 🎉
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
Projects
None yet
4 participants