Skip to content

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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
207 changes: 207 additions & 0 deletions CommitsSinceVersionSource.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@


@startuml
skinparam participantMargin 10
skinparam noteMargin 10
skinparam shadowing false

participant main
participant develop
participant feature_f1
participant release_1_1_0
participant feature_f2
participant release_1_2_0
participant hotfix_hf

note right of main #LightBlue
📝 Commit: A
Version Source: A (initial commit)
Commits beyond Version Source: none
Version: 1.0.0
end note

main --> develop: 🌿 branch develop from A

note right of develop #LightSkyBlue
📝 Commit: B
Version Source: A (already merged to develop)
Commits beyond Version Source: B
Version: 1.1.0-alpha.1
end note

develop --> feature_f1: 🌿 branch feature/f1 from B

note right of feature_f1 #LightGreen
📝 Commit: C
Version Source: B (already merged to develop)
Commits beyond Version Source: C
Version: 1.1.0-f1.1+2
end note

feature_f1 --> develop: 🔀 E (merge f1 → develop)

note right of develop #Khaki
📝 Commit: E
Version Source: E (develop tip)
Commits beyond Version Source: none
Version: 1.1.0-alpha.3
end note

develop --> release_1_1_0: 🌿 branch release/1.1.0 from E

note right of release_1_1_0 #PaleGreen
📝 Commit: F
Version Source: E (already merged to develop)
Commits beyond Version Source: F
Version: 1.1.0-beta.1+4
end note

release_1_1_0 --> main: 🔀 G (merge release/1.1.0 → main)

note right of main #Gold
📝 Commit: G
🏷 Tag: 1.1.0
Version Source: G (main tip)
Commits beyond Version Source: none
Version: 1.1.0-5
end note

main -> main: 🏷 tag 1.1.0

note right of main #Gold
Version: 1.1.0
end note

release_1_1_0 --> develop: 🔀 H (merge release/1.1.0 → develop)

note right of develop #Khaki
📝 Commit: H
Version Source: H (develop tip)
Commits beyond Version Source: none
Version: 1.2.0-alpha.1
end note

develop --> feature_f2: 🌿 branch feature/f2 from H

note right of feature_f2 #LightGreen
📝 Commit: I
Version Source: H (already merged to develop)
Commits beyond Version Source: I
Version: 1.2.0-f2.1+2
end note

feature_f2 -> feature_f2: Commit 'feature 2 additional commit (J)'

note right of feature_f2 #LightGreen
📝 Commit: J
Version Source: H (already merged to develop)
Commits beyond Version Source: J
Version: 1.3.0-f2.1+0
end note

feature_f2 --> develop: 🔀 K (merge f2 → develop)

note right of develop #Khaki
📝 Commit: K
Version Source: K (develop tip)
Commits beyond Version Source: none
Version: 1.2.0-alpha.3
end note

develop --> release_1_2_0: 🌿 branch release/1.2.0 from K

note right of release_1_2_0 #PaleGreen
📝 Commit: L
Version Source: K (already merged to develop)
Commits beyond Version Source: L
Beta parent: B.. E,F,G,H,I,J,K
Version: 1.2.0-beta.1+8
end note

release_1_2_0 --> main: 🔀 M (merge release/1.2.0 → main)

note right of main #Gold
📝 Commit: M
🏷 Tag: 1.2.0
Version Source: M (main tip)
Commits beyond Version Source: none
Version: 1.2.0-5
end note

main -> main: 🏷 tag 1.2.0

note right of main #Gold
Version: 1.2.0
end note

release_1_2_0 --> develop: 🔀 N (merge release/1.2.0 → develop)

note right of develop #Khaki
📝 Commit: N
Version Source: N (develop tip)
Commits beyond Version Source: none
Version: 1.3.0-alpha.1
end note

main --> hotfix_hf: 🌿 branch hotfix/hf from M

note right of hotfix_hf #LightCoral
📝 Commit: O
Version Source: M (already merged to main)
Commits beyond Version Source: O
Version: 1.2.1-beta.1+1
end note

hotfix_hf --> main: 🔀 P (merge hotfix → main)

note right of main #Gold
📝 Commit: P
🏷 Tag: 1.2.1
Version Source: P (main tip)
Commits beyond Version Source: none
Version: 1.2.1-2
end note

main -> main: 🏷 tag 1.2.1

note right of main #Gold
Version: 1.2.1
end note

hotfix_hf --> develop: 🔀 Q (merge hotfix → develop)

note right of develop #Khaki
📝 Commit: Q
Version Source: Q (develop tip)
Commits beyond Version Source: none
Version: 1.3.0-alpha.2
end note

note right of feature_f2 #Orange
⬅ Returned to feature/f2 at Commit J
Version Source: J (already merged to develop)
Commits beyond Version Source: none
Version recalculates to: 1.3.0-f2.1+0
end note

note right of feature_f2 #LightGreen
Version: 1.3.0-f2.1+0
end note

note right of feature_f2 #LightGreen
📝 Commit: R
Version Source: J (already merged to develop)
Commits beyond Version Source: R
Version: 1.3.0-f2.1+1
end note

feature_f2 --> develop: --> rebase R onto develop tip Q

note right of feature_f2 #Thistle
📝 Commit: R′
Version Source: Q (develop tip)
Commits beyond Version Source: R′
Version: 1.3.0-f2.1+1 (after rebase)
end note

@enduml
23 changes: 23 additions & 0 deletions src/GitVersion.Core.Tests/Core/RepositoryStoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,33 +86,56 @@ public void FindsCorrectMergeBaseForForwardMergeMovesOn()
//*91bf945 58 minutes ago(main)
using var fixture = new EmptyRepositoryFixture();
fixture.MakeACommit("initial");
fixture.AssertFullSemver("0.0.1-1");
fixture.AssertCommitsSinceVersionSource(1);
fixture.BranchTo("develop");
fixture.AssertFullSemver("0.1.0-alpha.1");
var fixtureRepository = fixture.Repository.ToGitRepository();
var expectedReleaseMergeBase = fixtureRepository.Head.Tip;
fixture.SequenceDiagram.NoteOver(string.Join(System.Environment.NewLine, ("Expected Release Merge Base" + System.Environment.NewLine + System.Environment.NewLine +
"This is the first common ancestor of both develop and release, from release's perspective.").SplitIntoLines(30)), "main", "develop");

// Create release from develop
fixture.BranchTo("release-2.0.0");
fixture.AssertFullSemver("2.0.0-beta.1+1");

// Make some commits on release
fixture.MakeACommit("release 1");
fixture.AssertCommitsSinceVersionSource(2);
fixture.AssertFullSemver("2.0.0-beta.1+2");
fixture.MakeACommit("release 2");
fixture.AssertCommitsSinceVersionSource(3);
fixture.AssertFullSemver("2.0.0-beta.1+3");
fixture.SequenceDiagram.NoteOver(string.Join(System.Environment.NewLine, ("Expected Develop Merge Base" + System.Environment.NewLine + System.Environment.NewLine +
"This is a common ancestor from develop's perspective because it is aware of the merge from release." + System.Environment.NewLine +
"It is NOT an common ancestor from release's perspective because release is NOT aware of the merge to develop.").SplitIntoLines(30)), "release-2.0.0");
var expectedDevelopMergeBase = fixtureRepository.Head.Tip;

// First forward merge release to develop
fixture.Checkout("develop");
fixture.MergeNoFF("release-2.0.0");
fixture.AssertFullSemver("2.1.0-alpha.3");
fixture.AssertCommitsSinceVersionSource(3);

// Make some new commit on release
fixture.Checkout("release-2.0.0");
fixture.MakeACommit("release 3 - after first merge");
fixture.AssertFullSemver("2.0.0-beta.1+4");
fixture.AssertCommitsSinceVersionSource(4);

// Make new commit on develop
fixture.Checkout("develop");
fixture.AssertFullSemver("2.1.0-alpha.3");
// Checkout to release (no new commits)
fixture.MakeACommit("develop after merge");
fixture.AssertFullSemver("2.1.0-alpha.4");
fixture.AssertCommitsSinceVersionSource(4);

// Checkout to release (no new commits)
fixture.Checkout("release-2.0.0");
fixture.SequenceDiagram.NoteOver("Checkout release-2.0.0 again", "release-2.0.0");
fixture.AssertFullSemver("2.0.0-beta.1+4");
fixture.AssertCommitsSinceVersionSource(4);

var develop = fixtureRepository.FindBranch("develop");
var release = fixtureRepository.FindBranch("release-2.0.0");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,55 @@ public static void WriteVersionVariables(this RepositoryFixtureBase fixture, str
}

public static void AssertFullSemver(this RepositoryFixtureBase fixture, string fullSemver,
IGitVersionConfiguration? configuration = null, IRepository? repository = null, string? commitId = null, bool onlyTrackedBranches = true, string? targetBranch = null)
IGitVersionConfiguration? configuration = null, IRepository? repository = null, string? commitId = null, bool onlyTrackedBranches = true, string? targetBranch = null, string? customMessage = null)
{
repository ??= fixture.Repository;

var variables = GetVersion(fixture, configuration, repository, commitId, onlyTrackedBranches, targetBranch);
variables.FullSemVer.ShouldBe(fullSemver);
variables.FullSemVer.ShouldBe(fullSemver, customMessage);
if (commitId == null)
{
fixture.SequenceDiagram.NoteOver(fullSemver, repository.Head.FriendlyName, color: "#D3D3D3");
}
}

public static void AssertCommitsSinceVersionSource(this RepositoryFixtureBase fixture, int commitsSinceVersionSourceExpected,
IGitVersionConfiguration? configuration = null, IRepository? repository = null, string? commitId = null, bool onlyTrackedBranches = true, string? targetBranch = null, string? customMessage = null)
{
repository ??= fixture.Repository;

var variables = GetVersion(fixture, configuration, repository, commitId, onlyTrackedBranches, targetBranch);
variables.CommitsSinceVersionSource.ShouldBe(commitsSinceVersionSourceExpected.ToString(), customMessage);
if (commitId == null)
{
var message = new StringBuilder();
var versionSourceLabel = fixture.SequenceDiagram.GetOrAddSourceLabel(variables.VersionSourceSha);
message.AppendLine($" Commit: {fixture.SequenceDiagram.GetOrAddLabel(variables.Sha)}");
message.Append($" Version source: {versionSourceLabel}");
if (commitsSinceVersionSourceExpected != 0 && variables.CommitsSinceVersionSourceList != null)
{
bool isFirst = true;
foreach (var sha in variables.CommitsSinceVersionSourceList.Split(", ").Reverse())
{
if (isFirst)
{
message.Append(System.Environment.NewLine);
message.Append($"Commits since version source: {variables.CommitsSinceVersionSource} - ");
isFirst = false;
}
else
{
message.Append(", ");
}

message.Append($"{fixture.SequenceDiagram.GetOrAddLabel(sha)}");
}
}

fixture.SequenceDiagram.NoteOver(message.ToString(), repository.Head.FriendlyName, color: "#A9B7C6");
}
}

/// <summary>
/// Simulates running on build server
/// </summary>
Expand Down
Loading
Loading