diff options
author | nulltoken <emeric.fermas@gmail.com> | 2013-01-09 16:00:25 +0400 |
---|---|---|
committer | nulltoken <emeric.fermas@gmail.com> | 2013-01-09 16:00:25 +0400 |
commit | 1a13d3b3ab5834c466243823ec8ad7da9c3c0c1e (patch) | |
tree | 8e975779c453023e9d480ac45c3b1adde7ff1e4d | |
parent | 48aae611fa0592e57d24d218e1761f23374699b1 (diff) |
Introduce Repository.Refs.Head
-rw-r--r-- | LibGit2Sharp.Tests/ReferenceFixture.cs | 14 | ||||
-rw-r--r-- | LibGit2Sharp.Tests/RepositoryFixture.cs | 2 | ||||
-rw-r--r-- | LibGit2Sharp/ReferenceCollection.cs | 12 | ||||
-rw-r--r-- | LibGit2Sharp/Repository.cs | 2 |
4 files changed, 21 insertions, 9 deletions
diff --git a/LibGit2Sharp.Tests/ReferenceFixture.cs b/LibGit2Sharp.Tests/ReferenceFixture.cs index 745367b5..6dfeff29 100644 --- a/LibGit2Sharp.Tests/ReferenceFixture.cs +++ b/LibGit2Sharp.Tests/ReferenceFixture.cs @@ -158,7 +158,7 @@ namespace LibGit2Sharp.Tests Assert.Equal(name, newRef.CanonicalName); Assert.NotNull(newRef.Target); Assert.Equal("a4a7dce85cf63874e984719f4fdd239f5145052f", newRef.ResolveToDirectReference().Target.Sha); - Assert.Equal(target, ((SymbolicReference)repo.Refs["HEAD"]).Target.CanonicalName); + Assert.Equal(target, ((SymbolicReference)repo.Refs.Head).Target.CanonicalName); } } @@ -294,7 +294,7 @@ namespace LibGit2Sharp.Tests { using (var repo = new Repository(BareTestRepoPath)) { - var head = (SymbolicReference)repo.Refs["HEAD"]; + var head = (SymbolicReference)repo.Refs.Head; Assert.NotNull(head); Assert.Equal("HEAD", head.CanonicalName); Assert.NotNull(head.Target); @@ -439,11 +439,11 @@ namespace LibGit2Sharp.Tests Reference direct = repo.Refs.UpdateTarget("HEAD", test.Tip.Sha); Assert.True((direct is DirectReference)); - Assert.Equal(repo.Refs["HEAD"], direct); + Assert.Equal(repo.Refs.Head, direct); Reference symref = repo.Refs.UpdateTarget("HEAD", test.CanonicalName); Assert.True((symref is SymbolicReference)); - Assert.Equal(repo.Refs["HEAD"], symref); + Assert.Equal(repo.Refs.Head, symref); } } @@ -453,18 +453,18 @@ namespace LibGit2Sharp.Tests TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(); using (var repo = new Repository(path.RepositoryPath)) { - Reference head = repo.Refs["HEAD"]; + Reference head = repo.Refs.Head; Reference test = repo.Refs["refs/heads/test"]; Reference direct = repo.Refs.UpdateTarget(head, new ObjectId(test.TargetIdentifier)); Assert.True((direct is DirectReference)); Assert.Equal(test.TargetIdentifier, direct.TargetIdentifier); - Assert.Equal(repo.Refs["HEAD"], direct); + Assert.Equal(repo.Refs.Head, direct); Reference symref = repo.Refs.UpdateTarget(head, test); Assert.True((symref is SymbolicReference)); Assert.Equal(test.CanonicalName, symref.TargetIdentifier); - Assert.Equal(repo.Refs["HEAD"], symref); + Assert.Equal(repo.Refs.Head, symref); } } diff --git a/LibGit2Sharp.Tests/RepositoryFixture.cs b/LibGit2Sharp.Tests/RepositoryFixture.cs index c97c6222..829fee49 100644 --- a/LibGit2Sharp.Tests/RepositoryFixture.cs +++ b/LibGit2Sharp.Tests/RepositoryFixture.cs @@ -154,7 +154,7 @@ namespace LibGit2Sharp.Tests Assert.False(repo.Info.IsHeadDetached); Assert.True(repo.Info.IsHeadOrphaned); - Reference headRef = repo.Refs["HEAD"]; + Reference headRef = repo.Refs.Head; Assert.NotNull(headRef); Assert.Equal("refs/heads/master", headRef.TargetIdentifier); Assert.Null(headRef.ResolveToDirectReference()); diff --git a/LibGit2Sharp/ReferenceCollection.cs b/LibGit2Sharp/ReferenceCollection.cs index eff5116a..672aec97 100644 --- a/LibGit2Sharp/ReferenceCollection.cs +++ b/LibGit2Sharp/ReferenceCollection.cs @@ -262,6 +262,18 @@ namespace LibGit2Sharp return Proxy.git_reference_is_valid_name(canonicalName); } + /// <summary> + /// Shortcut to return the HEAD reference. + /// </summary> + /// <returns> + /// A <see cref="DirectReference"/> if the HEAD is detached; + /// otherwise a <see cref="SymbolicReference"/>. + /// </returns> + public virtual Reference Head + { + get { return this["HEAD"]; } + } + private string DebuggerDisplay { get diff --git a/LibGit2Sharp/Repository.cs b/LibGit2Sharp/Repository.cs index 474ae4c2..40acadb5 100644 --- a/LibGit2Sharp/Repository.cs +++ b/LibGit2Sharp/Repository.cs @@ -151,7 +151,7 @@ namespace LibGit2Sharp { get { - Reference reference = Refs["HEAD"]; + Reference reference = Refs.Head; if (reference is SymbolicReference) { |