Skip to content

Commit 7ca1be9

Browse files
committed
Make VersionPoint expose the commit sha
1 parent 911ac17 commit 7ca1be9

6 files changed

+24
-15
lines changed

GitFlowVersion/VersionOnMasterFinder.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ public VersionPoint Execute(GitVersionContext context, DateTimeOffset olderThan)
1919
{
2020
Major = major,
2121
Minor = minor,
22-
Timestamp = commit.When()
22+
Timestamp = commit.When(),
23+
CommitSha = commit.Sha,
2324
};
2425
}
2526
}
@@ -34,7 +35,8 @@ public VersionPoint Execute(GitVersionContext context, DateTimeOffset olderThan)
3435
{
3536
Major = major,
3637
Minor = minor,
37-
Timestamp = commit.When()
38+
Timestamp = commit.When(),
39+
CommitSha = commit.Sha,
3840
};
3941
}
4042
}
@@ -44,9 +46,10 @@ public VersionPoint Execute(GitVersionContext context, DateTimeOffset olderThan)
4446
{
4547
Major = 0,
4648
Minor = 1,
47-
Timestamp = DateTimeOffset.MinValue
49+
Timestamp = DateTimeOffset.MinValue,
50+
CommitSha = null,
4851
};
4952
}
5053

5154
}
52-
}
55+
}

GitFlowVersion/VersionPoint.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ class VersionPoint
77
public int Major;
88
public int Minor;
99
public DateTimeOffset Timestamp;
10+
public string CommitSha;
1011
}
11-
}
12+
}

Tests/Mocks/MockCommit.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
[DebuggerDisplay("{DebuggerDisplay}")]
77
public class MockCommit:Commit
88
{
9-
public MockCommit()
9+
public MockCommit(ObjectId id = null)
1010
{
11-
idEx = new ObjectId(Guid.NewGuid().ToString().Replace("-", "")+ "00000000");
11+
idEx = id ?? new ObjectId(Guid.NewGuid().ToString().Replace("-", "")+ "00000000");
1212
MessageEx = "";
1313
ParentsEx = new List<Commit> { null };
1414
}
@@ -38,4 +38,4 @@ string DebuggerDisplay
3838
return MessageEx;
3939
}
4040
}
41-
}
41+
}

Tests/Mocks/MockMergeCommit.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
using LibGit2Sharp;
2+
13
public class MockMergeCommit : MockCommit
24
{
3-
public MockMergeCommit()
5+
public MockMergeCommit(ObjectId id = null) : base(id)
46
{
57
ParentsEx.Add(null);
68
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"Major": 0,
33
"Minor": 3,
4-
"Timestamp": "2000-10-09T23:59:58Z"
4+
"Timestamp": "2000-10-09T23:59:58Z",
5+
"CommitSha": "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
56
}

Tests/VersionOnMasterFinderTests.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,23 @@
22
using FluentDate;
33
using FluentDateTimeOffset;
44
using GitFlowVersion;
5+
using LibGit2Sharp;
56
using NUnit.Framework;
67
using ObjectApproval;
78

89
[TestFixture]
910
public class VersionOnMasterFinderTests
1011
{
11-
1212
[Test]
1313
public void Should_find_previous_commit_that_was_at_least_a_minor_bump()
1414
{
1515
var finder = new VersionOnMasterFinder();
1616

1717
var dateTime = new DateTimeOffset(2000, 10, 10,0,0,0,new TimeSpan(0));
1818
var signature = 2.Seconds().Before(dateTime).ToSignature();
19+
20+
const string sha = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef";
21+
1922
var version = finder.Execute(new GitVersionContext
2023
{
2124
Repository = new MockRepository
@@ -24,7 +27,7 @@ public void Should_find_previous_commit_that_was_at_least_a_minor_bump()
2427
{
2528
new MockBranch("master")
2629
{
27-
new MockMergeCommit
30+
new MockMergeCommit(new ObjectId(sha))
2831
{
2932
MessageEx = "Merge branch 'hotfix-0.3.0'",
3033
CommitterEx = signature
@@ -43,7 +46,6 @@ public void Should_find_previous_commit_that_was_at_least_a_minor_bump()
4346
}
4447
}
4548
}, 1.Seconds().Ago());
46-
ObjectApprover.VerifyWithJson(version, Scrubbers.GuidScrubber);
49+
ObjectApprover.VerifyWithJson(version);
4750
}
48-
49-
}
51+
}

0 commit comments

Comments
 (0)