-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathGitRef.cs
65 lines (54 loc) · 1.76 KB
/
GitRef.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//-----------------------------------------------------------------------
// <copyright file="GitRef.cs" company="(none)">
// Copyright © 2013 John Gietzen and the WebGit .NET Authors. All rights reserved.
// </copyright>
// <author>John Gietzen</author>
//-----------------------------------------------------------------------
namespace WebGitNet
{
using System;
using System.Collections.Generic;
public enum RefType
{
Branch,
Tag,
RemoteBranch,
Stash,
Notes,
}
public class GitRef
{
private Dictionary<RefType, string> prefixes = new Dictionary<RefType, string>
{
{ RefType.Branch, "refs/heads" },
{ RefType.Tag, "refs/tags" },
{ RefType.RemoteBranch, "refs/remotes" },
{ RefType.Notes, "refs/notes" },
};
public GitRef(string shaId, string refPath)
{
this.ShaId = shaId;
this.RefPath = refPath;
foreach (var prefix in prefixes)
{
if (refPath.StartsWith(prefix.Value))
{
this.Name = refPath.Substring(prefix.Value.Length + 1);
this.RefType = prefix.Key;
return;
}
}
if (refPath == "refs/stash")
{
this.Name = "stash";
this.RefType = RefType.Stash;
return;
}
throw new ArgumentException("The ref path specified is not recognized.", "refPath");
}
public string Name { get; private set; }
public string RefPath { get; private set; }
public RefType RefType { get; private set; }
public string ShaId { get; private set; }
}
}