Skip to content

Commit ecc92e2

Browse files
authored
Merge branch 'master' into fix/newtonsoft.json-usage
2 parents c48972f + c855918 commit ecc92e2

18 files changed

+89
-47
lines changed

src/Directory.Build.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020
<PackageVersion_LibGit2Sharp>0.26.2</PackageVersion_LibGit2Sharp>
2121
<PackageVersion_LibGit2Sharp_NativeBinaries>2.0.306</PackageVersion_LibGit2Sharp_NativeBinaries>
2222
<PackageVersion_JetBrainsAnnotations>2019.1.3</PackageVersion_JetBrainsAnnotations>
23-
<PackageVersion_YamlDotNet>8.0.0</PackageVersion_YamlDotNet>
23+
<PackageVersion_YamlDotNet>8.1.0</PackageVersion_YamlDotNet>
2424
<PackageVersion_NewtonsoftJson>12.0.3</PackageVersion_NewtonsoftJson>
2525

2626
<PackageVersion_MicrosoftTestSdk>16.4.0</PackageVersion_MicrosoftTestSdk>
2727
<PackageVersion_NSubstitute>4.2.1</PackageVersion_NSubstitute>
2828
<PackageVersion_CoverletMsBuild>2.8.0</PackageVersion_CoverletMsBuild>
2929
<PackageVersion_NUnit>3.12.0</PackageVersion_NUnit>
30-
<PackageVersion_NUnit3TestAdapter>3.16.0</PackageVersion_NUnit3TestAdapter>
30+
<PackageVersion_NUnit3TestAdapter>3.16.1</PackageVersion_NUnit3TestAdapter>
3131
<PackageVersion_NunitXmlTestLogger>2.1.41</PackageVersion_NunitXmlTestLogger>
3232
<PackageVersion_Shouldly>4.0.0-beta0002</PackageVersion_Shouldly>
3333

src/GitVersion.sln

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1212
ProjectSection(SolutionItems) = preProject
1313
..\.gitattributes = ..\.gitattributes
1414
..\.gitignore = ..\.gitignore
15-
..\.travis.yml = ..\.travis.yml
1615
..\appveyor.yml = ..\appveyor.yml
1716
..\azure-pipelines.yml = ..\azure-pipelines.yml
1817
..\BREAKING CHANGES.md = ..\BREAKING CHANGES.md
@@ -23,6 +22,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
2322
..\GitVersion.yml = ..\GitVersion.yml
2423
..\LICENSE = ..\LICENSE
2524
..\README.md = ..\README.md
25+
test.props = test.props
2626
EndProjectSection
2727
EndProject
2828
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GitVersionCore", "GitVersionCore\GitVersionCore.csproj", "{F9741A0D-B9D7-4557-9A1C-A7252C1071F5}"
@@ -31,7 +31,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GitVersionExe.Tests", "GitV
3131
EndProject
3232
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GitVersionTask", "GitVersionTask\GitVersionTask.csproj", "{F7AC0E71-3E9A-4F6D-B986-E004825A48E1}"
3333
EndProject
34-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitVersionTask.MsBuild", "GitVersionTask.MsBuild\GitVersionTask.MsBuild.csproj", "{0F1AEC4E-E81D-4F84-B2E8-3415A1A4DBF4}"
34+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GitVersionTask.MsBuild", "GitVersionTask.MsBuild\GitVersionTask.MsBuild.csproj", "{0F1AEC4E-E81D-4F84-B2E8-3415A1A4DBF4}"
3535
EndProject
3636
Global
3737
GlobalSection(SolutionConfigurationPlatforms) = preSolution

src/GitVersionCore.Tests/GitToolsTestingExtensions.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static class GitToolsTestingExtensions
1919

2020
static GitToolsTestingExtensions() => sp = ConfigureService();
2121

22-
public static VersionVariables GetVersion(this RepositoryFixtureBase fixture, Config configuration = null, IRepository repository = null, string commitId = null, bool isForTrackedBranchOnly = true, string targetBranch = null)
22+
public static VersionVariables GetVersion(this RepositoryFixtureBase fixture, Config configuration = null, IRepository repository = null, string commitId = null, bool onlyTrackedBranches = true, string targetBranch = null)
2323
{
2424
if (configuration == null)
2525
{
@@ -31,7 +31,7 @@ public static VersionVariables GetVersion(this RepositoryFixtureBase fixture, Co
3131
var variableProvider = sp.GetService<IVariableProvider>();
3232
var versionFinder = sp.GetService<IGitVersionFinder>();
3333

34-
var gitVersionContext = new GitVersionContext(repository ?? fixture.Repository, log, targetBranch, configuration, isForTrackedBranchOnly, commitId);
34+
var gitVersionContext = new GitVersionContext(repository ?? fixture.Repository, log, targetBranch, configuration, onlyTrackedBranches, commitId);
3535
var executeGitVersion = versionFinder.FindVersion(gitVersionContext);
3636
var variables = variableProvider.GetVariablesFor(executeGitVersion, gitVersionContext.Configuration, gitVersionContext.IsCurrentCommitTagged);
3737

@@ -47,19 +47,19 @@ public static VersionVariables GetVersion(this RepositoryFixtureBase fixture, Co
4747
}
4848
}
4949

50-
public static void AssertFullSemver(this RepositoryFixtureBase fixture, string fullSemver, IRepository repository = null, string commitId = null, bool isForTrackedBranchOnly = true, string targetBranch = null)
50+
public static void AssertFullSemver(this RepositoryFixtureBase fixture, string fullSemver, IRepository repository = null, string commitId = null, bool onlyTrackedBranches = true, string targetBranch = null)
5151
{
52-
fixture.AssertFullSemver(new Config(), fullSemver, repository, commitId, isForTrackedBranchOnly, targetBranch);
52+
fixture.AssertFullSemver(new Config(), fullSemver, repository, commitId, onlyTrackedBranches, targetBranch);
5353
}
5454

55-
public static void AssertFullSemver(this RepositoryFixtureBase fixture, Config configuration, string fullSemver, IRepository repository = null, string commitId = null, bool isForTrackedBranchOnly = true, string targetBranch = null)
55+
public static void AssertFullSemver(this RepositoryFixtureBase fixture, Config configuration, string fullSemver, IRepository repository = null, string commitId = null, bool onlyTrackedBranches = true, string targetBranch = null)
5656
{
5757
configuration.Reset();
5858
Console.WriteLine("---------");
5959

6060
try
6161
{
62-
var variables = fixture.GetVersion(configuration, repository, commitId, isForTrackedBranchOnly, targetBranch);
62+
var variables = fixture.GetVersion(configuration, repository, commitId, onlyTrackedBranches, targetBranch);
6363
variables.FullSemVer.ShouldBe(fullSemver);
6464
}
6565
catch (Exception)

src/GitVersionCore.Tests/GitVersionCore.Tests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
<PackageReference Include="FluentDateTime" Version="2.0.0" />
1515
<PackageReference Include="GitTools.Testing" Version="1.2.0" />
1616
<PackageReference Include="LibGit2Sharp.NativeBinaries" Version="$(PackageVersion_LibGit2Sharp_NativeBinaries)" />
17-
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.0.1" />
18-
<PackageReference Include="Microsoft.Extensions.Options" Version="3.0.1" />
17+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.1" />
18+
<PackageReference Include="Microsoft.Extensions.Options" Version="3.1.1" />
1919
<PackageReference Include="YamlDotNet" Version="$(PackageVersion_YamlDotNet)" />
2020
</ItemGroup>
2121
<ItemGroup>

src/GitVersionCore.Tests/IntegrationTests/DevelopScenarios.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public void WhenDevelopBranchedFromMasterDetachedHeadMinorIsIncreased()
143143
var commit = fixture.Repository.Head.Tip;
144144
fixture.Repository.MakeACommit();
145145
Commands.Checkout(fixture.Repository, commit);
146-
fixture.AssertFullSemver("1.1.0-alpha.1");
146+
fixture.AssertFullSemver("1.1.0-alpha.1", onlyTrackedBranches: false);
147147
}
148148

149149
[Test]

src/GitVersionCore.Tests/IntegrationTests/MasterScenarios.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using GitTools.Testing;
1+
using GitTools.Testing;
22
using LibGit2Sharp;
33
using NUnit.Framework;
44
using GitVersion.Configuration;
@@ -93,7 +93,7 @@ public void GivenARepositoryWithCommitsButNoTagsWithDetachedHeadVersionShouldBe0
9393
Commands.Checkout(fixture.Repository, commit);
9494

9595
// When
96-
fixture.AssertFullSemver("0.1.0+2");
96+
fixture.AssertFullSemver("0.1.0+2", onlyTrackedBranches: false);
9797
}
9898

9999
[Test]
@@ -207,4 +207,4 @@ public void AreTagsNotAdheringToTagPrefixIgnored()
207207
fixture.AssertFullSemver(config, "0.1.0+6"); //Fallback version + 6 commits since tag
208208
}
209209
}
210-
}
210+
}

src/GitVersionCore.Tests/IntegrationTests/RemoteRepositoryScenarios.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void GivenARemoteGitRepositoryWhenCheckingOutDetachedheadUsingExistingImp
6868
fixture.LocalRepositoryFixture.Repository,
6969
fixture.LocalRepositoryFixture.Repository.Head.Tip);
7070

71-
Should.Throw<WarningException>(() => fixture.AssertFullSemver("0.1.0+4", fixture.LocalRepositoryFixture.Repository, isForTrackedBranchOnly: false),
71+
Should.Throw<WarningException>(() => fixture.AssertFullSemver("0.1.0+4", fixture.LocalRepositoryFixture.Repository, onlyTrackedBranches: false),
7272
$"It looks like the branch being examined is a detached Head pointing to commit '{fixture.LocalRepositoryFixture.Repository.Head.Tip.Id.ToString(7)}'. Without a proper branch name GitVersion cannot determine the build version.");
7373
}
7474

src/GitVersionCore.Tests/VariableProviderTests.cs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,55 @@
1-
using System;
2-
using NUnit.Framework;
3-
using Shouldly;
1+
using GitVersion;
2+
using GitVersion.Logging;
43
using GitVersion.OutputFormatters;
54
using GitVersion.OutputVariables;
6-
using GitVersion;
75
using GitVersion.VersioningModes;
86
using GitVersionCore.Tests.Helpers;
97
using Microsoft.Extensions.DependencyInjection;
8+
using NUnit.Framework;
9+
using Shouldly;
10+
using System;
11+
using System.Collections.Generic;
1012

1113
namespace GitVersionCore.Tests
1214
{
1315
[TestFixture]
1416
public class VariableProviderTests : TestBase
1517
{
1618
private IVariableProvider variableProvider;
19+
private List<string> logMessages;
1720

1821
[SetUp]
1922
public void Setup()
2023
{
2124
ShouldlyConfiguration.ShouldMatchApprovedDefaults.LocateTestMethodUsingAttribute<TestAttribute>();
2225

23-
var sp = ConfigureServices();
26+
logMessages = new List<string>();
27+
28+
var sp = ConfigureServices(services =>
29+
{
30+
var log = new Log(new TestLogAppender(logMessages.Add));
31+
services.AddSingleton<ILog>(log);
32+
});
2433

2534
variableProvider = sp.GetService<IVariableProvider>();
2635
}
2736

37+
[Test]
38+
public void ShouldLogWarningWhenUsingDefaultInformationalVersionInCustomFormat()
39+
{
40+
var semVer = new SemanticVersion
41+
{
42+
Major = 1,
43+
Minor = 2,
44+
Patch = 3,
45+
};
46+
47+
var propertyName = nameof(SemanticVersionFormatValues.DefaultInformationalVersion);
48+
var config = new TestEffectiveConfiguration(assemblyInformationalFormat: $"{{{propertyName}}}");
49+
variableProvider.GetVariablesFor(semVer, config, false);
50+
logMessages.ShouldContain(message => message.Trim().StartsWith("WARN") && message.Contains(propertyName), 1, $"Expected a warning to be logged when using the variable {propertyName} in a configuration format template");
51+
}
52+
2853
[Test]
2954
[Category("NoMono")]
3055
[Description("Won't run on Mono due to source information not being available for ShouldMatchApproved.")]

src/GitVersionCore/Configuration/BranchConfigurationCalculator.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public BranchConfigurationCalculator(ILog log, GitVersionContext context)
2626
public BranchConfig GetBranchConfiguration(Branch targetBranch, IList<Branch> excludedInheritBranches = null)
2727
{
2828
var matchingBranches = context.FullConfiguration.GetConfigForBranch(targetBranch.NameWithoutRemote());
29-
29+
3030
if (matchingBranches == null)
3131
{
3232
log.Info($"No branch configuration found for branch {targetBranch.FriendlyName}, falling back to default configuration");
@@ -84,7 +84,7 @@ private BranchConfig InheritBranchConfiguration(Branch targetBranch, BranchConfi
8484
List<Branch> possibleParents;
8585
if (branchPoint == BranchCommit.Empty)
8686
{
87-
possibleParents = context.RepositoryMetadataProvider.GetBranchesContainingCommit(targetBranch.Tip, branchesToEvaluate, true)
87+
possibleParents = context.RepositoryMetadataProvider.GetBranchesContainingCommit(targetBranch.Tip, branchesToEvaluate, false)
8888
// It fails to inherit Increment branch configuration if more than 1 parent;
8989
// therefore no point to get more than 2 parents
9090
.Take(2)
@@ -93,11 +93,11 @@ private BranchConfig InheritBranchConfiguration(Branch targetBranch, BranchConfi
9393
else
9494
{
9595
var branches = context.RepositoryMetadataProvider
96-
.GetBranchesContainingCommit(branchPoint.Commit, branchesToEvaluate, true).ToList();
96+
.GetBranchesContainingCommit(branchPoint.Commit, branchesToEvaluate, false).ToList();
9797
if (branches.Count > 1)
9898
{
9999
var currentTipBranches = context.RepositoryMetadataProvider
100-
.GetBranchesContainingCommit(context.CurrentCommit, branchesToEvaluate, true).ToList();
100+
.GetBranchesContainingCommit(context.CurrentCommit, branchesToEvaluate, false).ToList();
101101
possibleParents = branches.Except(currentTipBranches).ToList();
102102
}
103103
else

src/GitVersionCore/GitRepoMetadataProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public IEnumerable<Branch> GetBranchesContainingCommit(Commit commit, IList<Bran
8181
// TODO: It looks wasteful looping through the branches twice. Can't these loops be merged somehow? @asbjornu
8282
foreach (var branch in branches)
8383
{
84-
if (branch.Tip != null && branch.Tip.Sha != commit.Sha || (onlyTrackedBranches && !branch.IsTracking))
84+
if (branch.Tip != null && branch.Tip.Sha != commit.Sha || ((onlyTrackedBranches && branch.IsTracking) || !onlyTrackedBranches))
8585
{
8686
continue;
8787
}
@@ -97,7 +97,7 @@ public IEnumerable<Branch> GetBranchesContainingCommit(Commit commit, IList<Bran
9797
}
9898

9999
log.Info($"No direct branches found, searching through {(onlyTrackedBranches ? "tracked" : "all")} branches.");
100-
foreach (var branch in branches.Where(b => onlyTrackedBranches && !b.IsTracking))
100+
foreach (var branch in branches.Where(b => (onlyTrackedBranches && b.IsTracking) || !onlyTrackedBranches))
101101
{
102102
log.Info($"Searching for commits reachable from '{branch.FriendlyName}'.");
103103

0 commit comments

Comments
 (0)