Skip to content

Conversation

@pwiens
Copy link
Contributor

@pwiens pwiens commented Jul 12, 2017

I encountered an issue where in a repository without a master or develop branch if we change the regex for master and develop to point to branches which do exist (and are used as master and develop branches) if there are no tags in the repo gitversion throws the following

  INFO [07/12/17 12:06:02:30] End: Getting branches containing the commit 'fa406c74e8eea6aa5a01cee62acc7f5ce1f6416e'. (Took: 3.49ms)
  INFO [07/12/17 12:06:02:30] Found possible parent branches:
INFO [07/12/17 12:06:02:30] End: Attempting to inherit branch configuration from parent branch (Took: 68.00ms)
ERROR [07/12/17 12:06:02:30] An unexpected error occurred:
System.InvalidOperationException: Could not find a 'develop' or 'master' branch, neither locally nor remotely.
   at GitVersion.BranchConfigurationCalculator.InheritBranchConfiguration(GitVersionContext context, Branch targetBranch, BranchConfig branchConfiguration, IList`1 excludedInheritBranches)
   at GitVersion.BranchConfigurationCalculator.GetBranchConfiguration(GitVersionContext context, Branch targetBranch, IList`1 excludedInheritBranches)
   at GitVersion.GitVersionContext.CalculateEffectiveConfiguration()
   at GitVersion.GitVersionContext..ctor(IRepository repository, Branch currentBranch, Config configuration, Boolean onlyEvaluateTrackedBranches, String commitId)
   at GitVersion.ExecuteCore.<>c__DisplayClass6_0.<ExecuteInternal>b__0(IRepository repo)
   at GitVersion.GitPreparer.WithRepository[TResult](Func`2 action)
   at GitVersion.ExecuteCore.ExecuteGitVersion(String targetUrl, String dynamicRepositoryLocation, Authentication authentication, String targetBranch, Boolean noFetch, String workingDirectory, String commitId, Config overrideConfig, Boolean noCache)
   at GitVersion.SpecifiedArgumentRunner.Run(Arguments arguments, IFileSystem fileSystem)
   at GitVersion.Program.VerifyArgumentsAndRun()

This fix changes the fallback to use the regex in the config instead of using a hardcoded regex.

Copy link
Member

@asbjornu asbjornu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! Just a couple of minor changes and this looks mergeable!


var chosenBranch = repository.Branches.FirstOrDefault(b => Regex.IsMatch(b.FriendlyName, "^develop", RegexOptions.IgnoreCase)
|| Regex.IsMatch(b.FriendlyName, "master$", RegexOptions.IgnoreCase));
var chosenBranch = repository.Branches.FirstOrDefault(b => Regex.IsMatch(b.FriendlyName, config.Branches[ConfigurationProvider.DevelopBranchKey].Regex, RegexOptions.IgnoreCase)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please extract this to a developBranchRegex variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

var chosenBranch = repository.Branches.FirstOrDefault(b => Regex.IsMatch(b.FriendlyName, "^develop", RegexOptions.IgnoreCase)
|| Regex.IsMatch(b.FriendlyName, "master$", RegexOptions.IgnoreCase));
var chosenBranch = repository.Branches.FirstOrDefault(b => Regex.IsMatch(b.FriendlyName, config.Branches[ConfigurationProvider.DevelopBranchKey].Regex, RegexOptions.IgnoreCase)
|| Regex.IsMatch(b.FriendlyName, config.Branches[ConfigurationProvider.MasterBranchKey].Regex, RegexOptions.IgnoreCase));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please extract this to a masterBranchRegex variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if what I did isn't what you meant.

@asbjornu asbjornu merged commit 29cb260 into GitTools:master Jul 13, 2017
@pwiens
Copy link
Contributor Author

pwiens commented Jul 13, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants