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

Changing hardcoded master/develop regex #1259

Merged
merged 4 commits into from Jul 13, 2017

Conversation

@pwiens
Copy link
Contributor

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

left a comment

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

@@ -109,8 +109,8 @@ static BranchConfig InheritBranchConfiguration(GitVersionContext context, Branch
else
errorMessage = "Failed to inherit Increment branch configuration, ended up with: " + string.Join(", ", possibleParents.Select(p => p.FriendlyName));

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)

This comment has been minimized.

Copy link
@asbjornu

asbjornu Jul 12, 2017

Member

Can you please extract this to a developBranchRegex variable?

This comment has been minimized.

Copy link
@pwiens

pwiens Jul 12, 2017

Author Contributor

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));

This comment has been minimized.

Copy link
@asbjornu

asbjornu Jul 12, 2017

Member

Can you please extract this to a masterBranchRegex variable?

This comment has been minimized.

Copy link
@pwiens

pwiens Jul 12, 2017

Author Contributor

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

@asbjornu asbjornu merged commit 29cb260 into GitTools:master Jul 13, 2017
2 checks passed
2 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@pwiens

This comment has been minimized.

Copy link
Contributor Author

commented Jul 13, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.