forked from libgit2/libgit2sharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGitObjectExtensions.cs
More file actions
35 lines (30 loc) · 1.17 KB
/
Copy pathGitObjectExtensions.cs
File metadata and controls
35 lines (30 loc) · 1.17 KB
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
using System.Globalization;
namespace LibGit2Sharp.Core
{
internal static class GitObjectExtensions
{
public static Commit DereferenceToCommit(this GitObject gitObject, string identifier, bool throwsIfCanNotBeDereferencedToACommit)
{
if (gitObject == null && !throwsIfCanNotBeDereferencedToACommit)
{
return null;
}
if (gitObject is Commit)
{
return (Commit)gitObject;
}
if (gitObject is TagAnnotation)
{
var target = ((TagAnnotation)gitObject).Target;
return target.DereferenceToCommit(identifier, throwsIfCanNotBeDereferencedToACommit);
}
if (!throwsIfCanNotBeDereferencedToACommit && (gitObject is Blob || gitObject is Tree))
{
return null;
}
throw new LibGit2Exception(string.Format(CultureInfo.InvariantCulture,
"The Git object pointed at by '{0}' can not be dereferenced to a commit.",
identifier));
}
}
}