Skip to content

Commit 964943b

Browse files
committed
Introduce Identity type
1 parent 930f63c commit 964943b

File tree

4 files changed

+62
-1
lines changed

4 files changed

+62
-1
lines changed

LibGit2Sharp.Tests/TestHelpers/Constants.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ public static class Constants
66
{
77
public const string TemporaryReposPath = "TestRepos";
88
public const string UnknownSha = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef";
9-
public static readonly Signature Signature = new Signature("A. U. Thor", "thor@valhalla.asgard.com", new DateTimeOffset(2011, 06, 16, 10, 58, 27, TimeSpan.FromHours(2)));
9+
public static readonly Identity Identity = new Identity("A. U. Thor", "thor@valhalla.asgard.com");
10+
public static readonly Signature Signature = new Signature(Identity, new DateTimeOffset(2011, 06, 16, 10, 58, 27, TimeSpan.FromHours(2)));
1011

1112
// Populate these to turn on live credential tests: set the
1213
// PrivateRepoUrl to the URL of a repository that requires

LibGit2Sharp/Identity.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using LibGit2Sharp.Core;
2+
3+
namespace LibGit2Sharp
4+
{
5+
/// <summary>
6+
/// Represents the identity used when writing reflog entries.
7+
/// </summary>
8+
public sealed class Identity
9+
{
10+
private readonly string _name;
11+
private readonly string _email;
12+
13+
/// <summary>
14+
/// Initializes a new instance of the <see cref="Identity"/> class.
15+
/// </summary>
16+
/// <param name="name">The name.</param>
17+
/// <param name="email">The email.</param>
18+
public Identity(string name, string email)
19+
{
20+
Ensure.ArgumentNotNullOrEmptyString(name, "name");
21+
Ensure.ArgumentNotNullOrEmptyString(email, "email");
22+
Ensure.ArgumentDoesNotContainZeroByte(name, "name");
23+
Ensure.ArgumentDoesNotContainZeroByte(name, "email");
24+
25+
_name = name;
26+
_email = email;
27+
}
28+
29+
/// <summary>
30+
/// Gets the email.
31+
/// </summary>
32+
public string Email
33+
{
34+
get { return _email; }
35+
}
36+
37+
/// <summary>
38+
/// Gets the name.
39+
/// </summary>
40+
public string Name
41+
{
42+
get { return _name; }
43+
}
44+
}
45+
}

LibGit2Sharp/LibGit2Sharp.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
<Compile Include="EntryExistsException.cs" />
8181
<Compile Include="FetchOptionsBase.cs" />
8282
<Compile Include="IBelongToARepository.cs" />
83+
<Compile Include="Identity.cs" />
8384
<Compile Include="IndexNameEntryCollection.cs" />
8485
<Compile Include="ContentChangeStats.cs" />
8586
<Compile Include="BuiltInFeatures.cs" />

LibGit2Sharp/Signature.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,20 @@ public Signature(string name, string email, DateTimeOffset when)
4444
this.when = when;
4545
}
4646

47+
/// <summary>
48+
/// Initializes a new instance of the <see cref="Signature"/> class.
49+
/// </summary>
50+
/// <param name="identity">The identity.</param>
51+
/// <param name="when">The when.</param>
52+
public Signature(Identity identity, DateTimeOffset when)
53+
{
54+
Ensure.ArgumentNotNull(identity, "identity");
55+
56+
this.name = identity.Name;
57+
this.email = identity.Email;
58+
this.when = when;
59+
}
60+
4761
internal SignatureSafeHandle BuildHandle()
4862
{
4963
return Proxy.git_signature_new(name, email, when);

0 commit comments

Comments
 (0)