forked from libgit2/libgit2sharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DirectReference.cs
50 lines (44 loc) · 1.49 KB
/
DirectReference.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
namespace LibGit2Sharp
{
/// <summary>
/// A DirectReference points directly to a <see cref="GitObject"/>
/// </summary>
public class DirectReference : Reference
{
private readonly Lazy<GitObject> targetBuilder;
/// <summary>
/// Needed for mocking purposes.
/// </summary>
protected DirectReference()
{ }
internal DirectReference(string canonicalName, IRepository repo, ObjectId targetId)
: base(repo, canonicalName, targetId.Sha)
{
targetBuilder = new Lazy<GitObject>(() =>
{
if (repo == null)
{
throw new InvalidOperationException("Target requires a local repository");
}
return repo.Lookup(targetId);
});
}
/// <summary>
/// Gets the target of this <see cref="DirectReference"/>
/// </summary>
/// <exception cref="InvalidOperationException">Throws if Local Repository is not set.</exception>
public virtual GitObject Target
{
get { return targetBuilder.Value; }
}
/// <summary>
/// As a <see cref="DirectReference"/> is already peeled, invoking this will return the same <see cref="DirectReference"/>.
/// </summary>
/// <returns>This instance.</returns>
public override DirectReference ResolveToDirectReference()
{
return this;
}
}
}