Skip to content
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

introduce in memory git metadata 2 #1244

Closed
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 @@ -47,7 +47,6 @@ branches:
- develop
- master
- support
- release
tracks-release-branches: false
is-release-branch: true
is-mainline: false
Expand Down
1 change: 1 addition & 0 deletions src/GitVersionCore.Tests/ConfigProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ public void VerifyAliases()
var config = typeof(Config);
var propertiesMissingAlias = config.GetProperties()
.Where(p => p.GetCustomAttribute<ObsoleteAttribute>() == null)
.Where(p => p.GetCustomAttribute<YamlIgnoreAttribute>() == null)
.Where(p => p.GetCustomAttribute(typeof(YamlMemberAttribute)) == null)
.Select(p => p.Name);

Expand Down
8 changes: 4 additions & 4 deletions src/GitVersionCore.Tests/ExecuteCoreTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using GitTools.Testing;
using GitVersion;
using GitVersion.Helpers;
using LibGit2Sharp;
using NUnit.Framework;
using Shouldly;
using System;
Expand Down Expand Up @@ -189,6 +190,8 @@ public void ConfigChangeInvalidatesCache()

var configPath = Path.Combine(fixture.RepositoryPath, "GitVersionConfig.yaml");
fileSystem.WriteAllText(configPath, "next-version: 5.0");
Commands.Stage(fixture.Repository, configPath);
fixture.Repository.Commit("Added config", Generate.SignatureNow(), Generate.SignatureNow());

vv = versionAndBranchFinder.ExecuteGitVersion(null, null, null, null, false, fixture.RepositoryPath, null);
vv.AssemblySemVer.ShouldBe("5.0.0.0");
Expand Down Expand Up @@ -300,10 +303,7 @@ LogMessages RepositoryScope(ExecuteCore executeCore = null, Action<EmptyReposito
vv.AssemblySemVer.ShouldBe("0.1.0.0");
vv.FileName.ShouldNotBeNullOrEmpty();

if (fixtureAction != null)
{
fixtureAction(fixture, vv);
}
fixtureAction?.Invoke(fixture, vv);
}

return new LogMessages
Expand Down
35 changes: 35 additions & 0 deletions src/GitVersionCore.Tests/GitRepoInformation/QueryRequirements.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using GitTools;
using GitTools.Testing;
using GitVersion;
using GitVersion.GitRepoInformation;
using NUnit.Framework;
using Shouldly;
using System;

[TestFixture]
public class QueryRequirements
{
[Test]
public void ListsAllMergeCommits()
{
var config = new Config();
ConfigurationProvider.ApplyDefaultsTo(config);
using (var fixture = new EmptyRepositoryFixture())
{
fixture.MakeACommit();
fixture.MakeACommit();
fixture.BranchTo("feature/foo");
fixture.MakeACommit();
fixture.Checkout("master");
fixture.MergeNoFF("feature/foo");

fixture.Repository.DumpGraph();

var metadata = Libgit2RepoMetadataProvider.ReadMetadata(
new GitVersionContext(fixture.Repository, fixture.Repository.FindBranch("master"), config)
);

metadata.CurrentBranch.MergeMessages.Count.ShouldBe(1);
}
}
}
3 changes: 2 additions & 1 deletion src/GitVersionCore.Tests/GitVersionContextBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ IRepository CreateRepository()
mockBranch
},
Tags = new MockTagCollection(),
Head = mockBranch
Head = mockBranch,
ObjectDatabase = new MockObjectDatabase()
};

return mockRepository;
Expand Down
3 changes: 3 additions & 0 deletions src/GitVersionCore.Tests/GitVersionContextTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public void CanInheritVersioningMode(VersioningMode mode)
var mockBranch = new MockBranch("master") { new MockCommit { CommitterEx = Generate.SignatureNow() } };
var mockRepository = new MockRepository
{
Head = mockBranch,
Branches = new MockBranchCollection
{
mockBranch
Expand Down Expand Up @@ -81,6 +82,7 @@ public void UsesBranchSpecificConfigOverTopLevelDefaults()
var develop = new MockBranch("develop") { new MockCommit { CommitterEx = Generate.SignatureNow() } };
var mockRepository = new MockRepository
{
Head = develop,
Branches = new MockBranchCollection
{
new MockBranch("master") { new MockCommit { CommitterEx = Generate.SignatureNow() } },
Expand Down Expand Up @@ -109,6 +111,7 @@ public void UsesFirstBranchConfigWhenMultipleMatch()

var mockRepository = new MockRepository
{
Head = releaseLatestBranch,
Branches = new MockBranchCollection
{
releaseLatestBranch,
Expand Down
10 changes: 6 additions & 4 deletions src/GitVersionCore.Tests/GitVersionCore.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\NUnit3TestAdapter.3.8.0-alpha1\build\net35\NUnit3TestAdapter.props" Condition="Exists('..\packages\NUnit3TestAdapter.3.8.0-alpha1\build\net35\NUnit3TestAdapter.props')" />
<Import Project="..\packages\LibGit2Sharp.NativeBinaries.1.0.160\build\LibGit2Sharp.NativeBinaries.props" Condition="Exists('..\packages\LibGit2Sharp.NativeBinaries.1.0.160\build\LibGit2Sharp.NativeBinaries.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
Expand Down Expand Up @@ -58,9 +59,8 @@
<HintPath>..\packages\NSubstitute.1.10.0.0\lib\net45\NSubstitute.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="nunit.framework, Version=3.6.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.6.0\lib\net45\nunit.framework.dll</HintPath>
<Private>True</Private>
<Reference Include="nunit.framework, Version=3.7.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.7.1\lib\net45\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="Shouldly, Version=2.7.0.0, Culture=neutral, PublicKeyToken=6042cbcb05cbc941, processorArchitecture=MSIL">
<HintPath>..\packages\Shouldly.2.7.0\lib\net40\Shouldly.dll</HintPath>
Expand Down Expand Up @@ -97,6 +97,7 @@
<Compile Include="CommitDateTests.cs" />
<Compile Include="Configuration\IgnoreConfigTests.cs" />
<Compile Include="DynamicRepositoryTests.cs" />
<Compile Include="GitRepoInformation\QueryRequirements.cs" />
<Compile Include="GitRepoMetadataProviderTests.cs" />
<Compile Include="GitToolsTestingExtensions.cs" />
<Compile Include="DocumentationTests.cs" />
Expand All @@ -107,6 +108,7 @@
<Compile Include="IntegrationTests\FileSystemTests.cs" />
<Compile Include="IntegrationTests\MainlineDevelopmentMode.cs" />
<Compile Include="LogMessages.cs" />
<Compile Include="MockObjectDatabase.cs" />
<Compile Include="Mocks\MockThreadSleep.cs" />
<Compile Include="OperationWithExponentialBackoffTests.cs" />
<Compile Include="Init\InitScenarios.cs" />
Expand Down Expand Up @@ -149,7 +151,6 @@
<Compile Include="TestStream.cs" />
<Compile Include="VariableProviderTests.cs" />
<Compile Include="ExecuteCoreTests.cs" />
<Compile Include="VersionCalculation\BaseVersionCalculatorTests.cs" />
<Compile Include="VersionCalculation\NextVersionCalculatorTests.cs" />
<Compile Include="VersionCalculation\Strategies\ConfigNextVersionBaseVersionStrategyTests.cs" />
<Compile Include="GitVersionContextBuilder.cs" />
Expand Down Expand Up @@ -215,6 +216,7 @@
</PropertyGroup>
<Error Condition="!Exists('..\packages\LibGit2Sharp.NativeBinaries.1.0.160\build\LibGit2Sharp.NativeBinaries.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\LibGit2Sharp.NativeBinaries.1.0.160\build\LibGit2Sharp.NativeBinaries.props'))" />
<Error Condition="!Exists('..\packages\Fody.2.0.8\build\dotnet\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Fody.2.0.8\build\dotnet\Fody.targets'))" />
<Error Condition="!Exists('..\packages\NUnit3TestAdapter.3.8.0-alpha1\build\net35\NUnit3TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit3TestAdapter.3.8.0-alpha1\build\net35\NUnit3TestAdapter.props'))" />
</Target>
<Import Project="..\packages\Fody.2.0.8\build\dotnet\Fody.targets" Condition="Exists('..\packages\Fody.2.0.8\build\dotnet\Fody.targets')" />
</Project>
5 changes: 4 additions & 1 deletion src/GitVersionCore.Tests/IntegrationTests/MasterScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ public void GivenARepositoryWithTagAndNextVersionInConfig_VersionShouldMatchVers
fixture.Repository.MakeATaggedCommit(TaggedVersion);
fixture.Repository.MakeCommits(5);

fixture.AssertFullSemver(config, "1.1.0+5");
// GitVersion uses commit count from where the config file was updated
// because we didn't check this change into the test repo
// it's 0
fixture.AssertFullSemver(config, "1.1.0+0");
}
}

Expand Down
24 changes: 24 additions & 0 deletions src/GitVersionCore.Tests/IntegrationTests/OtherScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using LibGit2Sharp;
using NUnit.Framework;
using System.Collections.Generic;
using System;

[TestFixture]
public class OtherScenarios
Expand Down Expand Up @@ -105,5 +106,28 @@ public void DoNotBlowUpWhenDevelopAndFeatureBranchPointAtSameCommit()
fixture.AssertFullSemver("1.1.0-alpha.1");
}
}

[Test]
public void AllowUnrelatedBranchesInRepo()
{
// This test unsures we handle when GitVersion cannot find mergebases etc
using (var fixture = new EmptyRepositoryFixture())
{
fixture.Repository.MakeACommit();
fixture.Repository.MakeACommit();

// Create a new root commit and then a branch pointing at that commit
var treeDefinition = new TreeDefinition();
var tree = fixture.Repository.ObjectDatabase.CreateTree(treeDefinition);
var commit = fixture.Repository.ObjectDatabase.CreateCommit(
new Signature("name", "mail", DateTimeOffset.Now),
new Signature("name", "mail", DateTimeOffset.Now),
"Create new empty branch",
tree, new Commit[0], false);
fixture.Repository.Branches.Add("gh-pages", commit);

fixture.AssertFullSemver("0.1.0+1");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ public void MergeOnReleaseBranchShouldNotResetCount()
fixture.AssertFullSemver(config, "2.0.0-beta.1");

fixture.Repository.MergeNoFF("release/2.0.0-xxx");
fixture.AssertFullSemver(config, "2.0.0-beta.2");
fixture.AssertFullSemver(config, "2.0.0-beta.3");
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/GitVersionCore.Tests/MockObjectDatabase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using LibGit2Sharp;

public class MockObjectDatabase : ObjectDatabase
{
public override Commit FindMergeBase(Commit first, Commit second)
{
return second;
}
}
2 changes: 1 addition & 1 deletion src/GitVersionCore.Tests/Mocks/MockQueryableCommitLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public ICommitLog QueryBy(CommitFilter filter)

public IEnumerable<LogEntry> QueryBy(string path)
{
throw new NotImplementedException();
return new[] { new LogEntry () };
}

#pragma warning disable CS0618 // Type or member is obsolete
Expand Down
1 change: 1 addition & 0 deletions src/GitVersionCore.Tests/Mocks/MockRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public MockRepository()
{
Tags = new MockTagCollection();
Refs = new MockReferenceCollection();
ObjectDatabase = new MockObjectDatabase();
}

public void Dispose()
Expand Down
Loading