-
Notifications
You must be signed in to change notification settings - Fork 656
Extend git flow complex example to post merge and rebase behaviour #4585
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
using GitVersion.Configuration; | ||
using GitVersion.Core.Tests.Helpers; | ||
using GitVersion.Helpers; | ||
using LibGit2Sharp; | ||
|
||
namespace GitVersion.Core.Tests.IntegrationTests; | ||
|
||
|
@@ -8,75 +11,140 @@ public class GitflowScenarios : TestBase | |
[Test] | ||
public void GitflowComplexExample() | ||
{ | ||
var keepBranches = true; | ||
const string developBranch = "develop"; | ||
const string feature1Branch = "feature/f1"; | ||
const string feature2Branch = "feature/f2"; | ||
const string release1Branch = "release/1.1.0"; | ||
const string release2Branch = "release/1.2.0"; | ||
const string hotfixBranch = "hotfix/hf"; | ||
|
||
using var fixture = new BaseGitFlowRepositoryFixture("1.0.0"); | ||
fixture.AssertFullSemver("1.1.0-alpha.1"); | ||
var configuration = GitFlowConfigurationBuilder.New.Build(); | ||
|
||
using var fixture = new BaseGitFlowRepositoryFixture(initialMainAction, deleteOnDispose: false); | ||
var fullSemver = "1.1.0-alpha.1"; | ||
fixture.AssertFullSemver(fullSemver, configuration); | ||
|
||
// Feature 1 | ||
fixture.BranchTo(feature1Branch); | ||
fixture.MakeACommit("added feature 1"); | ||
fixture.AssertFullSemver("1.1.0-f1.1+2"); | ||
|
||
fixture.MakeACommit($"added feature 1 >> {fullSemver}"); | ||
fullSemver = "1.1.0-f1.1+2"; | ||
fixture.AssertFullSemver(fullSemver, configuration); | ||
fixture.Checkout(developBranch); | ||
fixture.MergeNoFF(feature1Branch); | ||
fixture.Repository.Branches.Remove(fixture.Repository.Branches[feature1Branch]); | ||
fixture.AssertFullSemver("1.1.0-alpha.3"); | ||
if (!keepBranches) fixture.Repository.Branches.Remove(fixture.Repository.Branches[feature1Branch]); | ||
fixture.AssertFullSemver("1.1.0-alpha.3", configuration); | ||
|
||
// Release 1.1.0 | ||
fixture.BranchTo(release1Branch); | ||
fixture.MakeACommit("release stabilization"); | ||
fixture.AssertFullSemver("1.1.0-beta.1+4"); | ||
fixture.AssertFullSemver("1.1.0-beta.1+4", configuration); | ||
fixture.Checkout(MainBranch); | ||
fixture.MergeNoFF(release1Branch); | ||
fixture.AssertFullSemver("1.1.0-5"); | ||
fixture.AssertFullSemver("1.1.0-5", configuration); | ||
fixture.ApplyTag("1.1.0"); | ||
fixture.AssertFullSemver("1.1.0"); | ||
fixture.AssertFullSemver("1.1.0", configuration); | ||
fixture.Checkout(developBranch); | ||
fixture.MergeNoFF(release1Branch); | ||
fixture.Repository.Branches.Remove(fixture.Repository.Branches[release1Branch]); | ||
fixture.AssertFullSemver("1.2.0-alpha.1"); | ||
fixture.AssertFullSemver("1.2.0-alpha.1", configuration); | ||
|
||
// Feature 2 | ||
fixture.BranchTo(feature2Branch); | ||
fixture.MakeACommit("added feature 2"); | ||
fixture.AssertFullSemver("1.2.0-f2.1+2"); | ||
fullSemver = "1.2.0-f2.1+2"; | ||
fixture.MakeACommit($"added feature 2 >> {fullSemver}"); | ||
fixture.AssertFullSemver(fullSemver, configuration); | ||
fixture.Checkout(developBranch); | ||
fixture.MergeNoFF(feature2Branch); | ||
fixture.Repository.Branches.Remove(fixture.Repository.Branches[feature2Branch]); | ||
fixture.AssertFullSemver("1.2.0-alpha.3"); | ||
if (!keepBranches) fixture.Repository.Branches.Remove(fixture.Repository.Branches[feature2Branch]); | ||
fixture.AssertFullSemver("1.2.0-alpha.3", configuration); | ||
|
||
// Release 1.2.0 | ||
fixture.BranchTo(release2Branch); | ||
fixture.MakeACommit("release stabilization"); | ||
fixture.AssertFullSemver("1.2.0-beta.1+8"); | ||
fullSemver = "1.2.0-beta.1+8"; | ||
fixture.MakeACommit($"release stabilization >> {fullSemver}"); | ||
fixture.AssertFullSemver(fullSemver, configuration); | ||
fixture.Checkout(MainBranch); | ||
fixture.MergeNoFF(release2Branch); | ||
fixture.AssertFullSemver("1.2.0-5"); | ||
fixture.AssertFullSemver("1.2.0-5", configuration); | ||
fixture.ApplyTag("1.2.0"); | ||
fixture.AssertFullSemver("1.2.0"); | ||
fixture.AssertFullSemver("1.2.0", configuration); | ||
fixture.Checkout(developBranch); | ||
fixture.MergeNoFF(release2Branch); | ||
fixture.Repository.Branches.Remove(fixture.Repository.Branches[release2Branch]); | ||
fixture.AssertFullSemver("1.3.0-alpha.1"); | ||
if (!keepBranches) fixture.Repository.Branches.Remove(fixture.Repository.Branches[release2Branch]); | ||
fixture.AssertFullSemver("1.3.0-alpha.1", configuration); | ||
|
||
// Hotfix | ||
fixture.Checkout(MainBranch); | ||
fixture.BranchTo(hotfixBranch); | ||
fixture.MakeACommit("added hotfix"); | ||
fixture.AssertFullSemver("1.2.1-beta.1+1"); | ||
fullSemver = "1.2.1-beta.1+1"; | ||
fixture.MakeACommit($"added hotfix >> {fullSemver}"); | ||
fixture.AssertFullSemver(fullSemver, configuration); | ||
fixture.Checkout(MainBranch); | ||
fixture.MergeNoFF(hotfixBranch); | ||
fixture.AssertFullSemver("1.2.1-2"); | ||
fixture.AssertFullSemver("1.2.1-2", configuration); | ||
fixture.ApplyTag("1.2.1"); | ||
fixture.AssertFullSemver("1.2.1"); | ||
fixture.AssertFullSemver("1.2.1", configuration); | ||
fixture.Checkout(developBranch); | ||
fixture.MergeNoFF(hotfixBranch); | ||
fixture.Repository.Branches.Remove(fixture.Repository.Branches[hotfixBranch]); | ||
fixture.AssertFullSemver("1.3.0-alpha.2"); | ||
if (!keepBranches) fixture.Repository.Branches.Remove(fixture.Repository.Branches[hotfixBranch]); | ||
fixture.AssertFullSemver("1.3.0-alpha.2", configuration); | ||
|
||
fixture.Checkout(feature2Branch); | ||
fixture.AssertFullSemver( | ||
"1.3.0-f2.1+0", | ||
configuration, | ||
customMessage: | ||
"Feature branches use inherited versioning (increment: inherit), " + System.Environment.NewLine + | ||
"and your config inherits from develop." + System.Environment.NewLine + System.Environment.NewLine + | ||
"GitVersion uses the merge base between the feature and develop to determine the version." + System.Environment.NewLine + System.Environment.NewLine + | ||
"As develop progresses (e.g., by releasing 1.2.0), rebuilding old feature branches can" + System.Environment.NewLine + | ||
"produce different versions."); | ||
|
||
fullSemver = "1.3.0-f2.1+1"; | ||
fixture.MakeACommit( | ||
"feature 2 additional commit after original feature has been merged to develop " + System.Environment.NewLine + | ||
$"and release/1.2.0 has already happened >> {fullSemver}" + | ||
"Problem #1: 1.3.0-f2.1+0 is what I observe when I run dotnet-gitversion 6.3.0 but in the repo the assertion is 1.3.0-f2.1+1" + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Problem 1:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
"After rebase 1.3.0-f2.1+3 is both what the test asserts and what I observe when I run dotnet-gitversion 6.3.0." + | ||
"Problem #2: I expected to get the same before and after the rebase." + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Problem 2:
I'd have anticipated1.3.0-f2.1+1 both before and after rebase, in this specific scenario. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Odd. If I run the test now and flip out to the command line the config that's being persisted by the test is no longer valid for running with 6.3.0 but it works for you? I'll look again when it's a more sensible o'clock. In the meantime, as I said on my opening post, if my expectations aren't correct then I would like to understand what would be correct. How does +1 jump to +3? If there's documentation, point me at it as I do appreciate you've been generous with your time already. To be fair working out how to configure the majority minor patch bumps work now is what I'd expected to be playing with in the tests, not the CommitsSinceVersionSource idiosyncrasies... |
||
"" + | ||
"Whether my expectations are correct or not could we at least build upon the documentation I have started to add " + | ||
"as an explanation of observed behaviour. I'm happy to translate an explanation in to test " + | ||
"documentation if you confirm it would be accepted on PR." | ||
); | ||
|
||
var identity = new Identity( | ||
fixture.Repository.Head.Tip.Committer.Name, | ||
fixture.Repository.Head.Tip.Committer.Email); | ||
fixture.AssertFullSemver(fullSemver, configuration); | ||
var rebaseResult = fixture.Repository.Rebase.Start( | ||
fixture.Repository.Branches[feature2Branch], | ||
fixture.Repository.Branches[developBranch], | ||
fixture.Repository.Branches[developBranch], | ||
identity, | ||
new RebaseOptions()); | ||
while (rebaseResult != null && rebaseResult.Status != RebaseStatus.Complete) | ||
{ | ||
rebaseResult = fixture.Repository.Rebase.Continue(identity, new RebaseOptions()); | ||
} | ||
|
||
fixture.AssertFullSemver(fullSemver, configuration, customMessage: "I expected to get the same before and after the rebase."); | ||
|
||
void initialMainAction(IRepository r) | ||
{ | ||
if (configuration is GitVersionConfiguration concreteConfig) | ||
{ | ||
var yaml = new ConfigurationSerializer().Serialize(concreteConfig); | ||
const string fileName = "GitVersion.yml"; | ||
var filePath = FileSystemHelper.Path.Combine(r.Info.Path, "..", fileName); | ||
File.WriteAllText(filePath, yaml); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Intentionally writing out the GitVersion.yml to demonstrate inconsistency between UnitTest version calculation and running dotnet-gitversion from the commandline. Refer to 2 problems in commentary. |
||
r.Index.Add(fileName); | ||
r.Index.Write(); | ||
} | ||
|
||
r.MakeATaggedCommit("1.0.0", $"Initial commit on {MainBranch}"); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
namespace GitVersion.Testing; | ||
|
||
public class EmptyRepositoryFixture(string branchName = "main") : RepositoryFixtureBase(path => CreateNewRepository(path, branchName)); | ||
public class EmptyRepositoryFixture(string branchName = RepositoryFixtureBase.MainBranch, bool deleteOnDispose = true) : RepositoryFixtureBase(path => CreateNewRepository(path, branchName), deleteOnDispose); |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#4589 Magic strings >> BranchConfigurationKey.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May I ask you: Why do you care about how the branch is named in the unit tests? Does it make any different if it is named master or main? From the configuration point of view both are included and treated the same. At the end everyone can use their own name and their own configuration in the unit tests. There is no need for unification IMO.