Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public void WhenMultipleDevelopBranchesExistAndCurrentBranchHasIncrementInheritP
fixture.Repository.MakeACommit();
fixture.Repository.MergeNoFF("develop");

fixture.AssertFullSemver("1.0.1-x.1+3");
fixture.AssertFullSemver("1.1.0-x.1+3");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -552,4 +552,49 @@ public void PickUpVersionFromMasterMarkedWithIsTracksReleaseBranches()
fixture.AssertFullSemver(config, "0.10.1-MyFeatureD.1+1");
}
}

[Test]
public void ShouldHaveAGreaterSemVerAfterDevelopIsMergedIntoFeature()
{
var config = new Config()
{
VersioningMode = VersioningMode.ContinuousDeployment,
AssemblyVersioningScheme = AssemblyVersioningScheme.Major,
AssemblyFileVersioningFormat = "{MajorMinorPatch}.{env:WeightedPreReleaseNumber ?? 0}",
LegacySemVerPadding = 4,
BuildMetaDataPadding = 4,
CommitsSinceVersionSourcePadding = 4,
CommitMessageIncrementing = CommitMessageIncrementMode.Disabled,
Branches = new Dictionary<string, BranchConfig>
{
{
"develop", new BranchConfig()
{
PreventIncrementOfMergedBranchVersion = true
}
},
{
"feature", new BranchConfig()
{
Tag = "feat-{BranchName}"
}
}
}
};
using (var fixture = new EmptyRepositoryFixture())
{
fixture.MakeACommit();
fixture.BranchTo("develop");
fixture.MakeACommit();
fixture.ApplyTag("16.23.0");
fixture.MakeACommit();
fixture.BranchTo("feature/featX");
fixture.MakeACommit();
fixture.Checkout("develop");
fixture.MakeACommit();
fixture.Checkout("feature/featX");
fixture.MergeNoFF("develop");
fixture.AssertFullSemver(config, "16.24.0-feat-featX.4");
}
}
}
54 changes: 49 additions & 5 deletions src/GitVersionCore/BranchConfigurationCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,21 @@ static BranchConfig InheritBranchConfiguration(GitVersionContext context, Branch
// To prevent infinite loops, make sure that a new branch was chosen.
if (targetBranch.IsSameBranch(chosenBranch))
{
Logger.WriteWarning("Fallback branch wants to inherit Increment branch configuration from itself. Using patch increment instead.");
return new BranchConfig(branchConfiguration)
BranchConfig developOrMasterConfig =
ChooseMasterOrDevelopIncrementStrategyIfTheChosenBranchIsOneOfThem(
chosenBranch, branchConfiguration, config);
if (developOrMasterConfig != null)
{
Increment = IncrementStrategy.Patch
};
return developOrMasterConfig;
}
else
{
Logger.WriteWarning("Fallback branch wants to inherit Increment branch configuration from itself. Using patch increment instead.");
return new BranchConfig(branchConfiguration)
{
Increment = IncrementStrategy.Patch
};
}
}

var inheritingBranchConfig = GetBranchConfiguration(context, chosenBranch, excludedInheritBranches);
Expand Down Expand Up @@ -201,5 +211,39 @@ static Branch[] CalculateWhenMultipleParents(IRepository repository, Commit curr

return excludedBranches;
}

private static BranchConfig
ChooseMasterOrDevelopIncrementStrategyIfTheChosenBranchIsOneOfThem(Branch ChosenBranch,
BranchConfig BranchConfiguration, Config config)
{
BranchConfig masterOrDevelopConfig = null;
var developBranchRegex = config.Branches[ConfigurationProvider.DevelopBranchKey].Regex;
var masterBranchRegex = config.Branches[ConfigurationProvider.MasterBranchKey].Regex;
if (Regex.IsMatch(ChosenBranch.FriendlyName, developBranchRegex, RegexOptions.IgnoreCase))
{
// Normally we would not expect this to happen but for safety we add a check
if (config.Branches[ConfigurationProvider.DevelopBranchKey].Increment !=
IncrementStrategy.Inherit)
{
masterOrDevelopConfig = new BranchConfig(BranchConfiguration)
{
Increment = config.Branches[ConfigurationProvider.DevelopBranchKey].Increment
};
}
}
else if (Regex.IsMatch(ChosenBranch.FriendlyName, masterBranchRegex, RegexOptions.IgnoreCase))
{
// Normally we would not expect this to happen but for safety we add a check
if (config.Branches[ConfigurationProvider.MasterBranchKey].Increment !=
IncrementStrategy.Inherit)
{
masterOrDevelopConfig = new BranchConfig(BranchConfiguration)
{
Increment = config.Branches[ConfigurationProvider.DevelopBranchKey].Increment
};
}
}
return masterOrDevelopConfig;
}
}
}
}