Skip to content

Commit 989f953

Browse files
committed
Introduced Reference.IsValidName(string)
Deprecated ReferenceCollection.IsValidName(string) . Updated Test . Fixes #680 Fixed typo in [Obsolete] tag. Rebase into current vNext.
1 parent a889aa9 commit 989f953

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

LibGit2Sharp.Tests/ReferenceFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ public void CanTellIfAReferenceIsValid(string refname, bool expectedResult)
752752
{
753753
using (var repo = new Repository(BareTestRepoPath))
754754
{
755-
Assert.Equal(expectedResult, repo.Refs.IsValidName(refname));
755+
Assert.Equal(expectedResult, Reference.IsValidName(refname));
756756
}
757757
}
758758

LibGit2Sharp/Reference.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,24 @@ internal static T BuildFromPtr<T>(ReferenceSafeHandle handle, Repository repo) w
6464
return reference as T;
6565
}
6666

67+
/// <summary>
68+
/// Determines if the proposed reference name is well-formed.
69+
/// </summary>
70+
/// <para>
71+
/// - Top-level names must contain only capital letters and underscores,
72+
/// and must begin and end with a letter. (e.g. "HEAD", "ORIG_HEAD").
73+
///
74+
/// - Names prefixed with "refs/" can be almost anything. You must avoid
75+
/// the characters '~', '^', ':', '\\', '?', '[', and '*', and the
76+
/// sequences ".." and "@{" which have special meaning to revparse.
77+
/// </para>
78+
/// <param name="canonicalName">The name to be checked.</param>
79+
/// <returns>true is the name is valid; false otherwise.</returns>
80+
public static bool IsValidName(string canonicalName)
81+
{
82+
return Proxy.git_reference_is_valid_name(canonicalName);
83+
}
84+
6785
/// <summary>
6886
/// Gets the full name of this reference.
6987
/// </summary>

LibGit2Sharp/ReferenceCollection.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,10 @@ public virtual IEnumerable<Reference> FromGlob(string pattern)
340340
/// </para>
341341
/// <param name="canonicalName">The name to be checked.</param>
342342
/// <returns>true is the name is valid; false otherwise.</returns>
343+
[Obsolete("This method will be removed in the next release. Please use Reference.IsValidName(string) instead.")]
343344
public virtual bool IsValidName(string canonicalName)
344345
{
345-
return Proxy.git_reference_is_valid_name(canonicalName);
346+
return Reference.IsValidName(canonicalName);
346347
}
347348

348349
/// <summary>

0 commit comments

Comments
 (0)