Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ReferenceExtensions.cs « LibGit2Sharp - github.com/mono/libgit2sharp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8b33e161849f92a7fc03a7d4960b78a73715b346 (plain)
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
66
67
68
69
70
71
72
73
74
75
using System;

namespace LibGit2Sharp
{
    /// <summary>
    /// Provides helpers to a <see cref="Reference"/>.
    /// </summary>
    public static class ReferenceExtensions
    {
        internal static bool LooksLikeLocalBranch(this string canonicalName)
        {
            return canonicalName.IsPrefixedBy(Reference.LocalBranchPrefix);
        }

        internal static bool LooksLikeRemoteTrackingBranch(this string canonicalName)
        {
            return canonicalName.IsPrefixedBy(Reference.RemoteTrackingBranchPrefix);
        }

        internal static bool LooksLikeTag(this string canonicalName)
        {
            return canonicalName.IsPrefixedBy(Reference.TagPrefix);
        }

        internal static bool LooksLikeNote(this string canonicalName)
        {
            return canonicalName.IsPrefixedBy(Reference.NotePrefix);
        }

        private static bool IsPrefixedBy(this string input, string prefix)
        {
            return input.StartsWith(prefix, StringComparison.Ordinal);
        }

        /// <summary>
        /// Determine if the current <see cref="Reference"/> is a local branch.
        /// </summary>
        /// <param name="reference">The <see cref="Reference"/> to test.</param>
        /// <returns>true if the current <see cref="Reference"/> is a local branch, false otherwise.</returns>
        public static bool IsLocalBranch(this Reference reference)
        {
            return reference.CanonicalName.LooksLikeLocalBranch();
        }

        /// <summary>
        /// Determine if the current <see cref="Reference"/> is a remote tracking branch.
        /// </summary>
        /// <param name="reference">The <see cref="Reference"/> to test.</param>
        /// <returns>true if the current <see cref="Reference"/> is a remote tracking branch, false otherwise.</returns>
        public static bool IsRemoteTrackingBranch(this Reference reference)
        {
            return reference.CanonicalName.LooksLikeRemoteTrackingBranch();
        }

        /// <summary>
        /// Determine if the current <see cref="Reference"/> is a tag.
        /// </summary>
        /// <param name="reference">The <see cref="Reference"/> to test.</param>
        /// <returns>true if the current <see cref="Reference"/> is a tag, false otherwise.</returns>
        public static bool IsTag(this Reference reference)
        {
            return reference.CanonicalName.LooksLikeTag();
        }

        /// <summary>
        /// Determine if the current <see cref="Reference"/> is a note.
        /// </summary>
        /// <param name="reference">The <see cref="Reference"/> to test.</param>
        /// <returns>true if the current <see cref="Reference"/> is a note, false otherwise.</returns>
        public static bool IsNote(this Reference reference)
        {
            return reference.CanonicalName.LooksLikeNote();
        }
    }
}