diff --git a/LibGit2Sharp/Branch.cs b/LibGit2Sharp/Branch.cs index 31fe33d89..dbb1dd9ec 100644 --- a/LibGit2Sharp/Branch.cs +++ b/LibGit2Sharp/Branch.cs @@ -106,7 +106,15 @@ public virtual BranchTrackingDetails TrackingDetails /// public virtual bool IsCurrentRepositoryHead { - get { return repo.Head == this; } + get + { + if (this is DetachedHead) + { + return repo.Head.reference.TargetIdentifier == this.reference.TargetIdentifier; + } + + return repo.Head.reference.TargetIdentifier == this.CanonicalName; + } } /// diff --git a/LibGit2Sharp/ReferenceWrapper.cs b/LibGit2Sharp/ReferenceWrapper.cs index 9b5f151d3..349be3008 100644 --- a/LibGit2Sharp/ReferenceWrapper.cs +++ b/LibGit2Sharp/ReferenceWrapper.cs @@ -16,10 +16,11 @@ public abstract class ReferenceWrapper : IEquatable protected readonly Repository repo; + protected readonly Reference reference; private readonly Lazy objectBuilder; private static readonly LambdaEqualityHelper> equalityHelper = - new LambdaEqualityHelper>(x => x.CanonicalName, x => x.TargetObject); + new LambdaEqualityHelper>(x => x.CanonicalName, x => x.reference.TargetIdentifier); private readonly string canonicalName; @@ -40,6 +41,7 @@ protected internal ReferenceWrapper(Repository repo, Reference reference, Func(() => RetrieveTargetObject(reference)); }