Skip to content

BUG: Could not find a 'develop' or 'master' branch, neither locally nor remotely #1049

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
MrHinsh opened this issue Sep 28, 2016 · 12 comments
Closed
Labels

Comments

@MrHinsh
Copy link

MrHinsh commented Sep 28, 2016

Guys,

I have a very strange problem... System.InvalidOperationException: Could not find a 'develop' or 'master' branch, neither locally nor remotely is the message I get when trying to build a pull request. From either MASTER or a topic branch this all works perfectly.

2016-09-28T09:06:44.8095056Z ERROR [09/28/16 9:06:44:68] An unexpected error occurred:
2016-09-28T09:06:44.8095056Z System.InvalidOperationException: Could not find a 'develop' or 'master' branch, neither locally nor remotely.
2016-09-28T09:06:44.8095056Z    at GitVersion.BranchConfigurationCalculator.InheritBranchConfiguration(Boolean onlyEvaluateTrackedBranches, IRepository repository, Commit currentCommit, Branch currentBranch, KeyValuePair`2 keyValuePair, BranchConfig branchConfiguration, Config config, IList`1 excludedInheritBranches)
2016-09-28T09:06:44.8095056Z    at GitVersion.BranchConfigurationCalculator.GetBranchConfiguration(Commit currentCommit, IRepository repository, Boolean onlyEvaluateTrackedBranches, Config config, Branch currentBranch, IList`1 excludedInheritBranches)
2016-09-28T09:06:44.8095056Z    at GitVersion.GitVersionContext.CalculateEffectiveConfiguration()
2016-09-28T09:06:44.8095056Z    at GitVersion.GitVersionContext..ctor(IRepository repository, Branch currentBranch, Config configuration, Boolean onlyEvaluateTrackedBranches, String commitId)
2016-09-28T09:06:44.8095056Z    at GitVersion.ExecuteCore.<>c__DisplayClass6_0.<ExecuteInternal>b__0(IRepository repo)
2016-09-28T09:06:44.8095056Z    at GitVersion.GitPreparer.WithRepository[TResult](Func`2 action)
2016-09-28T09:06:44.8095056Z    at GitVersion.ExecuteCore.ExecuteGitVersion(String targetUrl, String dynamicRepositoryLocation, Authentication authentication, String targetBranch, Boolean noFetch, String workingDirectory, String commitId, Config overrideConfig)
2016-09-28T09:06:44.8095056Z    at GitVersion.SpecifiedArgumentRunner.Run(Arguments arguments, IFileSystem fileSystem)
2016-09-28T09:06:44.8095056Z    at GitVersion.Program.VerifyArgumentsAndRun()

Why might this be happening?

I have attached the full log and you can see it finds tags and lists the graph...

assembly-versioning-scheme: MajorMinorPatch
mode: ContinuousDeployment
continuous-delivery-fallback-tag: ''
branches:
  master:
    mode: ContinuousDeployment
    tag: ''
ignore:
  sha: []

GitVersion-Log.txt

@MrHinsh MrHinsh changed the title Failed to find version for PullRequest on VSTS BUG: Could not find a 'develop' or 'master' branch, neither locally nor remotely Sep 28, 2016
@asbjornu
Copy link
Member

@MrHinsh: This looks like a duplicate of #912. Can you please peek at it and see if there's anything in there that can help? Also, if this is a duplicate, please close and continue the discussion in #912. 😄

@pascalberger
Copy link
Member

@MrHinsh See #993 for a workaround by adding an additional git fetch task to the build pipeline

@MrHinsh
Copy link
Author

MrHinsh commented Sep 28, 2016

Looks like this is the same issue as #993 and I am closing it here. You can also find more info at #912

@MrHinsh MrHinsh closed this as completed Sep 28, 2016
@tkrafael
Copy link

tkrafael commented Feb 13, 2020

I found in bitbucket that when it does a clone passing branch as command line arg, git clone result does not create neither master or develop branch and thus GitVersion is unable to find local branch.
In that case, I tweaked GitVersion file to accept remote branch as valid develop/master branch.
This code is my config:

mode: ContinuousDeployment
branches:
    master:
        regex: (^master$|^origin\/master$)
    develop:
        regex: (^dev(elop)?(ment)?$|^origin\/dev(elop)?(ment)?$)

This solved the issue in question.

@andlaz
Copy link

andlaz commented Dec 7, 2020

This solved the issue in question.

thanks for this! i would've never checked default configuration because of the error message below

System.InvalidOperationException: Could not find a 'develop' or 'master' branch, neither locally nor remotely.

in my case the jenkins git-plugin did fetch all remote refs, it just did not create local branches tracking remote ones. I figured this should've been sufficient, given the above error message.. after the update to the regex outlined above, it is. Maybe this should be the actual default configuration unless i'm missing something ( and i may be .. )

@asbjornu
Copy link
Member

asbjornu commented Dec 7, 2020

Maybe this should be the actual default configuration

Yep, indeed it seems like it should. A PR changing the default regex and adding a new test for origin/master would be warmly welcomed. 🙏

@andlaz
Copy link

andlaz commented Dec 7, 2020

On second thought.. can you think of no use case where someone would depend on these regex values being what they are, by default? Additionally, what of remotes not named origin ? What if the regular expression ( (^master$|^origin\/master$) as above or even (^master$|^.*\/master$) ) returns multiple refs?

Maybe this is as simple as the exception message not assuming any kind of particular configuration and just guiding the user towards the config keys that were used to draw this conclusion, e.g. Could not find a 'develop' or 'master' branch, verify develop.regex and master.regex configuration values ?

@asbjornu
Copy link
Member

asbjornu commented Dec 7, 2020

Those are good points, @andlaz. But I think we can base GitVersion's assumptions on Git's defaults, which is to name the default branch master or main and the clone remote origin. Hard coding those defaults in GitVersion is therefore fine, imho. It should also be unnecessary to have a local tracking branch, since the branch references provided by origin are exactly the same, only placed differently.

@asbjornu asbjornu reopened this Dec 7, 2020
@stale
Copy link

stale bot commented Mar 19, 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 Mar 19, 2021
@joaosantana
Copy link

I've come across this problem recently, and the regex solution works fine. I wonder if the GitVersion init command couldn't retrieve the repo's main branch and apply it to a regex entry in the GitVersion.yml file?

@stale stale bot removed the stale label Mar 25, 2021
@asbjornu
Copy link
Member

That's a great idea, @joaosantana. Pull requests are welcome! 🙏🏼

@stale
Copy link

stale bot commented Jun 26, 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 26, 2021
@stale stale bot closed this as completed Jul 30, 2021
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