Skip to content

Commit 9abf29f

Browse files
authored
Merge branch 'master' into feature/support_for_wix_format
2 parents 17b24ba + 14b7365 commit 9abf29f

File tree

3 files changed

+95
-6
lines changed

3 files changed

+95
-6
lines changed

src/GitVersionCore.Tests/IntegrationTests/DevelopScenarios.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public void WhenMultipleDevelopBranchesExistAndCurrentBranchHasIncrementInheritP
201201
fixture.Repository.MakeACommit();
202202
fixture.Repository.MergeNoFF("develop");
203203

204-
fixture.AssertFullSemver("1.0.1-x.1+3");
204+
fixture.AssertFullSemver("1.1.0-x.1+3");
205205
}
206206
}
207207
}

src/GitVersionCore.Tests/IntegrationTests/FeatureBranchScenarios.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,4 +552,49 @@ public void PickUpVersionFromMasterMarkedWithIsTracksReleaseBranches()
552552
fixture.AssertFullSemver(config, "0.10.1-MyFeatureD.1+1");
553553
}
554554
}
555+
556+
[Test]
557+
public void ShouldHaveAGreaterSemVerAfterDevelopIsMergedIntoFeature()
558+
{
559+
var config = new Config()
560+
{
561+
VersioningMode = VersioningMode.ContinuousDeployment,
562+
AssemblyVersioningScheme = AssemblyVersioningScheme.Major,
563+
AssemblyFileVersioningFormat = "{MajorMinorPatch}.{env:WeightedPreReleaseNumber ?? 0}",
564+
LegacySemVerPadding = 4,
565+
BuildMetaDataPadding = 4,
566+
CommitsSinceVersionSourcePadding = 4,
567+
CommitMessageIncrementing = CommitMessageIncrementMode.Disabled,
568+
Branches = new Dictionary<string, BranchConfig>
569+
{
570+
{
571+
"develop", new BranchConfig()
572+
{
573+
PreventIncrementOfMergedBranchVersion = true
574+
}
575+
},
576+
{
577+
"feature", new BranchConfig()
578+
{
579+
Tag = "feat-{BranchName}"
580+
}
581+
}
582+
}
583+
};
584+
using (var fixture = new EmptyRepositoryFixture())
585+
{
586+
fixture.MakeACommit();
587+
fixture.BranchTo("develop");
588+
fixture.MakeACommit();
589+
fixture.ApplyTag("16.23.0");
590+
fixture.MakeACommit();
591+
fixture.BranchTo("feature/featX");
592+
fixture.MakeACommit();
593+
fixture.Checkout("develop");
594+
fixture.MakeACommit();
595+
fixture.Checkout("feature/featX");
596+
fixture.MergeNoFF("develop");
597+
fixture.AssertFullSemver(config, "16.24.0-feat-featX.4");
598+
}
599+
}
555600
}

src/GitVersionCore/BranchConfigurationCalculator.cs

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,21 @@ static BranchConfig InheritBranchConfiguration(GitVersionContext context, Branch
142142
// To prevent infinite loops, make sure that a new branch was chosen.
143143
if (targetBranch.IsSameBranch(chosenBranch))
144144
{
145-
Logger.WriteWarning("Fallback branch wants to inherit Increment branch configuration from itself. Using patch increment instead.");
146-
return new BranchConfig(branchConfiguration)
145+
BranchConfig developOrMasterConfig =
146+
ChooseMasterOrDevelopIncrementStrategyIfTheChosenBranchIsOneOfThem(
147+
chosenBranch, branchConfiguration, config);
148+
if (developOrMasterConfig != null)
147149
{
148-
Increment = IncrementStrategy.Patch
149-
};
150+
return developOrMasterConfig;
151+
}
152+
else
153+
{
154+
Logger.WriteWarning("Fallback branch wants to inherit Increment branch configuration from itself. Using patch increment instead.");
155+
return new BranchConfig(branchConfiguration)
156+
{
157+
Increment = IncrementStrategy.Patch
158+
};
159+
}
150160
}
151161

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

202212
return excludedBranches;
203213
}
214+
215+
private static BranchConfig
216+
ChooseMasterOrDevelopIncrementStrategyIfTheChosenBranchIsOneOfThem(Branch ChosenBranch,
217+
BranchConfig BranchConfiguration, Config config)
218+
{
219+
BranchConfig masterOrDevelopConfig = null;
220+
var developBranchRegex = config.Branches[ConfigurationProvider.DevelopBranchKey].Regex;
221+
var masterBranchRegex = config.Branches[ConfigurationProvider.MasterBranchKey].Regex;
222+
if (Regex.IsMatch(ChosenBranch.FriendlyName, developBranchRegex, RegexOptions.IgnoreCase))
223+
{
224+
// Normally we would not expect this to happen but for safety we add a check
225+
if (config.Branches[ConfigurationProvider.DevelopBranchKey].Increment !=
226+
IncrementStrategy.Inherit)
227+
{
228+
masterOrDevelopConfig = new BranchConfig(BranchConfiguration)
229+
{
230+
Increment = config.Branches[ConfigurationProvider.DevelopBranchKey].Increment
231+
};
232+
}
233+
}
234+
else if (Regex.IsMatch(ChosenBranch.FriendlyName, masterBranchRegex, RegexOptions.IgnoreCase))
235+
{
236+
// Normally we would not expect this to happen but for safety we add a check
237+
if (config.Branches[ConfigurationProvider.MasterBranchKey].Increment !=
238+
IncrementStrategy.Inherit)
239+
{
240+
masterOrDevelopConfig = new BranchConfig(BranchConfiguration)
241+
{
242+
Increment = config.Branches[ConfigurationProvider.DevelopBranchKey].Increment
243+
};
244+
}
245+
}
246+
return masterOrDevelopConfig;
247+
}
204248
}
205-
}
249+
}

0 commit comments

Comments
 (0)