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
2 changes: 1 addition & 1 deletion source/OctoVersion.Core/Configuration/AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,4 @@ public IEnumerable<ValidationResult> Validate(ValidationContext validationContex
if (string.IsNullOrWhiteSpace(CurrentBranch) && string.IsNullOrWhiteSpace(FullSemVer))
yield return new ValidationResult($"At least one of {nameof(CurrentBranch)} or {nameof(FullSemVer)} must be provided.", new[] { nameof(CurrentBranch), nameof(FullSemVer) });
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class VersionCalculatorFactory
readonly bool _allowShallowClone;

public VersionCalculatorFactory(string repositorySearchPath)
: this(repositorySearchPath, allowShallowClone: false)
: this(repositorySearchPath, false)
{
}

Expand Down Expand Up @@ -67,12 +67,12 @@ public VersionCalculator Create()
if (!commits.TryGetValue(parent.Sha, out var simpleParent))
{
// In a shallow clone, boundary commits may reference parents outside the available history. Skip them rather than blowing up with a KeyNotFoundException.
if (_allowShallowClone)
if (_allowShallowClone)
continue;

throw new KeyNotFoundException("Unable to find parent commit with hash " + parent.Sha);
}

simpleCommit.AddParent(simpleParent);
}
}
Expand Down Expand Up @@ -104,4 +104,4 @@ public VersionCalculator Create()
var calculator = new VersionCalculator(commits.Values.ToArray(), currentCommitHash);
return calculator;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,32 @@ namespace OctoVersion.Tests;
/// </summary>
public class WhenCalculatingVersionFromShallowClone
{
static SimpleCommit MakeCommit(string hash, DateTimeOffset timestamp, string message = "normal commit")
=> new(hash, message, timestamp, false, false);
static SimpleCommit MakeCommit(string hash, DateTimeOffset timestamp, string message = "normal commit")
{
return new SimpleCommit(hash,
message,
timestamp,
false,
false);
}

static SimpleCommit MakeMajorBumpCommit(string hash, DateTimeOffset timestamp)
=> new(hash, "+semver: major", timestamp, true, false);
static SimpleCommit MakeMajorBumpCommit(string hash, DateTimeOffset timestamp)
{
return new SimpleCommit(hash,
"+semver: major",
timestamp,
true,
false);
}

static SimpleCommit MakeMinorBumpCommit(string hash, DateTimeOffset timestamp)
=> new(hash, "+semver: minor", timestamp, false, true);
static SimpleCommit MakeMinorBumpCommit(string hash, DateTimeOffset timestamp)
{
return new SimpleCommit(hash,
"+semver: minor",
timestamp,
false,
true);
}

[Fact]
public void WhenShallowBoundaryHasVersionTag_VersionIsCalculatedRelativeToTag()
Expand All @@ -30,7 +48,13 @@ public void WhenShallowBoundaryHasVersionTag_VersionIsCalculatedRelativeToTag()
// A (parent: B) ← HEAD
// Expected: HEAD = 2.0.2

var baseTime = new DateTimeOffset(2024, 1, 1, 0, 0, 0, TimeSpan.Zero);
var baseTime = new DateTimeOffset(2024,
1,
1,
0,
0,
0,
TimeSpan.Zero);

var commitC = MakeCommit("ccc", baseTime);
var commitB = MakeCommit("bbb", baseTime.AddMinutes(1));
Expand All @@ -56,7 +80,13 @@ public void WhenShallowBoundaryHasNoTag_VersionCountsFromZero()
// A (parent: B) ← HEAD
// The shallow boundary commit itself counts as 0.0.1, so HEAD = 0.0.2

var baseTime = new DateTimeOffset(2024, 1, 1, 0, 0, 0, TimeSpan.Zero);
var baseTime = new DateTimeOffset(2024,
1,
1,
0,
0,
0,
TimeSpan.Zero);

var commitB = MakeCommit("bbb", baseTime);
var commitA = MakeCommit("aaa", baseTime.AddMinutes(1));
Expand All @@ -78,7 +108,14 @@ public void WhenShallowBoundaryIsTheCurrentCommit_VersionIsCalculatedFromZero()
// A (no parents — shallow boundary) ← HEAD
// Expected: 0.0.1

var commitA = MakeCommit("aaa", new DateTimeOffset(2024, 1, 1, 0, 0, 0, TimeSpan.Zero));
var commitA = MakeCommit("aaa",
new DateTimeOffset(2024,
1,
1,
0,
0,
0,
TimeSpan.Zero));

var calculator = new VersionCalculator([commitA], commitA.Hash);
var version = calculator.GetVersion();
Expand All @@ -98,7 +135,13 @@ public void WhenMergeCommitHasOneParentCutByShallowClone_VersionUsesRemainingPar
// B (parent: C)
// A (parent: B — the other merge parent was outside shallow history) ← HEAD

var baseTime = new DateTimeOffset(2024, 1, 1, 0, 0, 0, TimeSpan.Zero);
var baseTime = new DateTimeOffset(2024,
1,
1,
0,
0,
0,
TimeSpan.Zero);

var commitC = MakeCommit("ccc", baseTime);
var commitB = MakeCommit("bbb", baseTime.AddMinutes(1));
Expand Down Expand Up @@ -130,7 +173,13 @@ public void WhenVersionTagExistsWithinShallowHistory_TagTakesPrecedenceOverCount
// A (parent: B) ← HEAD
// Expected: HEAD = 1.5.2

var baseTime = new DateTimeOffset(2024, 1, 1, 0, 0, 0, TimeSpan.Zero);
var baseTime = new DateTimeOffset(2024,
1,
1,
0,
0,
0,
TimeSpan.Zero);

var commitD = MakeCommit("ddd", baseTime);
var commitC = MakeCommit("ccc", baseTime.AddMinutes(1));
Expand Down Expand Up @@ -161,7 +210,13 @@ public void WhenMajorBumpCommitIsAboveShallowBoundary_MajorVersionIsIncremented(
// A (parent: B) ← HEAD
// Expected: B = 2.0.0, HEAD = 2.0.1

var baseTime = new DateTimeOffset(2024, 1, 1, 0, 0, 0, TimeSpan.Zero);
var baseTime = new DateTimeOffset(2024,
1,
1,
0,
0,
0,
TimeSpan.Zero);

var commitC = MakeCommit("ccc", baseTime);
var commitB = MakeMajorBumpCommit("bbb", baseTime.AddMinutes(1));
Expand Down Expand Up @@ -190,7 +245,13 @@ public void WhenMinorBumpCommitIsAboveShallowBoundary_MinorVersionIsIncremented(
// A (parent: B) ← HEAD
// Expected: B = 1.1.0, HEAD = 1.1.1

var baseTime = new DateTimeOffset(2024, 1, 1, 0, 0, 0, TimeSpan.Zero);
var baseTime = new DateTimeOffset(2024,
1,
1,
0,
0,
0,
TimeSpan.Zero);

var commitC = MakeCommit("ccc", baseTime);
var commitB = MakeMinorBumpCommit("bbb", baseTime.AddMinutes(1));
Expand All @@ -207,4 +268,4 @@ public void WhenMinorBumpCommitIsAboveShallowBoundary_MinorVersionIsIncremented(
version.Minor.ShouldBe(1);
version.Patch.ShouldBe(1);
}
}
}
Loading