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
4 changes: 2 additions & 2 deletions src/GitVersion.App.Tests/PullRequestInBuildAgentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ private static async Task VerifyPullRequestVersionIsCalculatedProperly(string pu
remoteRepository.Refs.Add(pullRequestRef, new ObjectId(mergeCommitSha));

// Checkout PR commit
Commands.Fetch((Repository)fixture.Repository, "origin", Array.Empty<string>(), new FetchOptions(), null);
Commands.Fetch(fixture.Repository, "origin", Array.Empty<string>(), new FetchOptions(), null);
Commands.Checkout(fixture.Repository, mergeCommitSha);
}

Expand Down Expand Up @@ -199,7 +199,7 @@ public void VerifyPullRequestInput(string pullRequestRef, string friendly, bool
var refName = new ReferenceName(pullRequestRef);

Assert.AreEqual(friendly, refName.Friendly);
Assert.AreEqual(isBranch, refName.IsBranch);
Assert.AreEqual(isBranch, refName.IsLocalBranch);
Assert.AreEqual(isPullRequest, refName.IsPullRequest);
Assert.AreEqual(isRemote, refName.IsRemoteBranch);
}
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersion.App.Tests/TagCheckoutInBuildAgentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private static async Task VerifyTagCheckoutVersionIsCalculatedProperly(Dictionar
remoteRepository.MergeNoFF("release/0.2.0", Generate.SignatureNow());
remoteRepository.MakeATaggedCommit("0.2.0");

Commands.Fetch((Repository)fixture.Repository, "origin", Array.Empty<string>(), new FetchOptions(), null);
Commands.Fetch(fixture.Repository, "origin", Array.Empty<string>(), new FetchOptions(), null);
Commands.Checkout(fixture.Repository, "0.2.0");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,37 @@ public void GetReleaseBranchConfigReturnsAllReleaseBranches()
result.Count.ShouldBe(2);
result.ShouldNotContain(b => b.Key == "foo");
}

[TestCase("release/2.0.0",
"refs/heads/release/2.0.0", "release/2.0.0", "release/2.0.0",
true, false, false, false, true)]
[TestCase("upstream/release/2.0.0",
"refs/heads/upstream/release/2.0.0", "upstream/release/2.0.0", "upstream/release/2.0.0",
true, false, false, false, false)]
[TestCase("origin/release/2.0.0",
"refs/heads/origin/release/2.0.0", "origin/release/2.0.0", "origin/release/2.0.0",
true, false, false, false, false)]
[TestCase("refs/remotes/upstream/release/2.0.0",
"refs/remotes/upstream/release/2.0.0", "upstream/release/2.0.0", "upstream/release/2.0.0",
false, false, true, false, false)]
[TestCase("refs/remotes/origin/release/2.0.0",
"refs/remotes/origin/release/2.0.0", "origin/release/2.0.0", "release/2.0.0",
false, false, true, false, true)]
public void EnsureIsReleaseBranchWithReferenceNameWorksAsExpected(string branchName, string expectedCanonical, string expectedFriendly, string expectedWithoutRemote,
bool expectedIsLocalBranch, bool expectedIsPullRequest, bool expectedIsRemoteBranch, bool expectedIsTag, bool expectedIsReleaseBranch)
{
var configuration = GitFlowConfigurationBuilder.New.Build();

var actual = ReferenceName.FromBranchName(branchName);
var isReleaseBranch = configuration.IsReleaseBranch(actual);

actual.Canonical.ShouldBe(expectedCanonical);
actual.Friendly.ShouldBe(expectedFriendly);
actual.WithoutRemote.ShouldBe(expectedWithoutRemote);
actual.IsLocalBranch.ShouldBe(expectedIsLocalBranch);
actual.IsPullRequest.ShouldBe(expectedIsPullRequest);
actual.IsRemoteBranch.ShouldBe(expectedIsRemoteBranch);
actual.IsTag.ShouldBe(expectedIsTag);
isReleaseBranch.ShouldBe(expectedIsReleaseBranch);
}
}
9 changes: 6 additions & 3 deletions src/GitVersion.Core.Tests/Core/RepositoryStoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,12 @@ public void FindCommitBranchWasBranchedFromShouldReturnNullIfTheRemoteIsTheOnlyS

var branch = localRepository.FindBranch("main");
branch.ShouldNotBeNull();
var branchedCommit = gitRepoMetadataProvider.FindCommitBranchWasBranchedFrom(branch, new GitVersionConfiguration(), Array.Empty<IBranch>());

Assert.IsNull(branchedCommit.Branch);
Assert.IsNull(branchedCommit.Commit);
var configuration = GitFlowConfigurationBuilder.New.Build();
var branchedCommit = gitRepoMetadataProvider.FindCommitBranchWasBranchedFrom(branch, configuration, Array.Empty<IBranch>());
branchedCommit.ShouldBe(BranchCommit.Empty);

var branchedCommits = gitRepoMetadataProvider.FindCommitBranchesWasBranchedFrom(branch, configuration).ToArray();
branchedCommits.ShouldBeEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ public static IBranch CreateMockBranch(string name, params ICommit[] commits)
return branch;
}

public static IBranch FindBranch(this IGitRepository repository, string branchName) => repository.Branches.First(x => x.Name.WithoutRemote == branchName) ?? throw new GitVersionException($"Branch {branchName} not found");
public static IBranch FindBranch(this IGitRepository repository, string branchName)
=> repository.Branches.FirstOrDefault(branch => branch.Name.WithoutRemote == branchName)
?? throw new GitVersionException($"Branch {branchName} not found");

public static void DumpGraph(this IGitRepository repository, Action<string>? writer = null, int? maxCommits = null) => GitExtensions.DumpGraph(repository.Path, writer, maxCommits);

Expand Down
7 changes: 4 additions & 3 deletions src/GitVersion.Core.Tests/Helpers/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ protected static IServiceProvider ConfigureServices(Action<IServiceCollection>?
return services.BuildServiceProvider();
}

protected static IServiceProvider BuildServiceProvider(string workingDirectory, IGitRepository repository, string branch, IReadOnlyDictionary<object, object?>? configuration = null)
protected static IServiceProvider BuildServiceProvider(IGitRepository repository,
string? targetBranch = null, IReadOnlyDictionary<object, object?>? configuration = null)
{
var options = Options.Create(new GitVersionOptions
{
WorkingDirectory = workingDirectory,
WorkingDirectory = repository.Path,
ConfigurationInfo = { OverrideConfiguration = configuration },
RepositoryInfo = { TargetBranch = branch }
RepositoryInfo = { TargetBranch = targetBranch }
});

var sp = ConfigureServices(services =>
Expand Down
4 changes: 2 additions & 2 deletions src/GitVersion.Core.Tests/IntegrationTests/OtherScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void DoNotBlowUpWhenMainAndDevelopPointAtSameCommit()
fixture.MakeACommit();
fixture.Repository.CreateBranch("develop");

Commands.Fetch((Repository)fixture.LocalRepositoryFixture.Repository, fixture.LocalRepositoryFixture.Repository.Network.Remotes.First().Name, Array.Empty<string>(), new FetchOptions(), null);
Commands.Fetch(fixture.LocalRepositoryFixture.Repository, fixture.LocalRepositoryFixture.Repository.Network.Remotes.First().Name, Array.Empty<string>(), new FetchOptions(), null);
Commands.Checkout(fixture.LocalRepositoryFixture.Repository, fixture.Repository.Head.Tip);
fixture.LocalRepositoryFixture.Repository.Branches.Remove(MainBranch);
fixture.InitializeRepo();
Expand Down Expand Up @@ -87,7 +87,7 @@ public void DoNotBlowUpWhenDevelopAndFeatureBranchPointAtSameCommit()
fixture.MakeACommit();
fixture.Repository.CreateBranch("feature/someFeature");

Commands.Fetch((Repository)fixture.LocalRepositoryFixture.Repository, fixture.LocalRepositoryFixture.Repository.Network.Remotes.First().Name, Array.Empty<string>(), new FetchOptions(), null);
Commands.Fetch(fixture.LocalRepositoryFixture.Repository, fixture.LocalRepositoryFixture.Repository.Network.Remotes.First().Name, Array.Empty<string>(), new FetchOptions(), null);
Commands.Checkout(fixture.LocalRepositoryFixture.Repository, fixture.Repository.Head.Tip);
fixture.LocalRepositoryFixture.Repository.Branches.Remove(MainBranch);
fixture.InitializeRepo();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void GivenARemoteGitRepositoryAheadOfLocalRepositoryThenChangesShouldPull
fixture.AssertFullSemver("0.0.1+6");
fixture.AssertFullSemver("0.0.1+5", repository: fixture.LocalRepositoryFixture.Repository);
var buildSignature = fixture.LocalRepositoryFixture.Repository.Config.BuildSignature(new DateTimeOffset(DateTime.Now));
Commands.Pull((Repository)fixture.LocalRepositoryFixture.Repository, buildSignature, new PullOptions());
Commands.Pull(fixture.LocalRepositoryFixture.Repository, buildSignature, new PullOptions());
fixture.AssertFullSemver("0.0.1+6", repository: fixture.LocalRepositoryFixture.Repository);
}

Expand Down Expand Up @@ -135,4 +135,22 @@ private static void CopyRemoteBranchesToHeads(IRepository repository)
}
}
}

[TestCase("origin", "release-2.0.0", "2.1.0-alpha.0")]
[TestCase("custom", "release-2.0.0", "0.1.0-alpha.5")]
[TestCase("origin", "release/3.0.0", "3.1.0-alpha.0")]
[TestCase("custom", "release/3.0.0", "0.1.0-alpha.5")]
public void EnsureRemoteReleaseBranchesAreTracked(string origin, string branchName, string expectedVersion)
{
using var fixture = new RemoteRepositoryFixture("develop");

fixture.CreateBranch(branchName);
fixture.MakeACommit();

if (origin != "origin") fixture.LocalRepositoryFixture.Repository.Network.Remotes.Rename("origin", origin);
fixture.LocalRepositoryFixture.Fetch(origin);
fixture.LocalRepositoryFixture.Checkout("develop");

fixture.LocalRepositoryFixture.AssertFullSemver(expectedVersion);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,24 @@ public void TakesVersionFromNameOfRemoteReleaseBranchInOrigin()
using var fixture = new RemoteRepositoryFixture();
fixture.BranchTo("release/2.0.0");
fixture.MakeACommit();
Commands.Fetch((Repository)fixture.LocalRepositoryFixture.Repository, fixture.LocalRepositoryFixture.Repository.Network.Remotes.First().Name, Array.Empty<string>(), new FetchOptions(), null);
Commands.Fetch(fixture.LocalRepositoryFixture.Repository, fixture.LocalRepositoryFixture.Repository.Network.Remotes.First().Name, Array.Empty<string>(), new FetchOptions(), null);

fixture.LocalRepositoryFixture.Checkout("origin/release/2.0.0");

fixture.LocalRepositoryFixture.AssertFullSemver("2.0.0-beta.1+1");
}

[Test]
public void TakesVersionFromNameOfRemoteReleaseBranchInCustom()
public void DoesNotTakeVersionFromNameOfRemoteReleaseBranchInCustomRemote()
{
using var fixture = new RemoteRepositoryFixture();
fixture.LocalRepositoryFixture.Repository.Network.Remotes.Rename("origin", "upstream");
fixture.BranchTo("release/2.0.0");
fixture.MakeACommit();
Commands.Fetch((Repository)fixture.LocalRepositoryFixture.Repository, fixture.LocalRepositoryFixture.Repository.Network.Remotes.First().Name, Array.Empty<string>(), new FetchOptions(), null);
Commands.Fetch(fixture.LocalRepositoryFixture.Repository, fixture.LocalRepositoryFixture.Repository.Network.Remotes.First().Name, Array.Empty<string>(), new FetchOptions(), null);

fixture.LocalRepositoryFixture.Checkout("upstream/release/2.0.0");

fixture.LocalRepositoryFixture.AssertFullSemver("2.0.0-beta.1+1");
fixture.LocalRepositoryFixture.AssertFullSemver("0.0.1-upstream-release-2-0-0.1+6");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void TakesVersionFromNameOfRemoteReleaseBranchInOrigin()
using var fixture = new RemoteRepositoryFixture();
fixture.BranchTo("release/2.0.0");
fixture.MakeACommit();
Commands.Fetch((Repository)fixture.LocalRepositoryFixture.Repository, fixture.LocalRepositoryFixture.Repository.Network.Remotes.First().Name, Array.Empty<string>(), new FetchOptions(), null);
Commands.Fetch(fixture.LocalRepositoryFixture.Repository, fixture.LocalRepositoryFixture.Repository.Network.Remotes.First().Name, Array.Empty<string>(), new FetchOptions(), null);

fixture.LocalRepositoryFixture.MergeNoFF("origin/release/2.0.0");

Expand All @@ -59,7 +59,7 @@ public void DoesNotTakeVersionFromNameOfRemoteReleaseBranchInCustomRemote()
fixture.LocalRepositoryFixture.Repository.Network.Remotes.Rename("origin", "upstream");
fixture.BranchTo("release/2.0.0");
fixture.MakeACommit();
Commands.Fetch((Repository)fixture.LocalRepositoryFixture.Repository, fixture.LocalRepositoryFixture.Repository.Network.Remotes.First().Name, Array.Empty<string>(), new FetchOptions(), null);
fixture.LocalRepositoryFixture.Fetch("upstream");

fixture.LocalRepositoryFixture.MergeNoFF("upstream/release/2.0.0");

Expand Down
Loading