aboutsummaryrefslogtreecommitdiffstats
path: root/repository.go
diff options
context:
space:
mode:
authorantham <hamonanth@gmail.com>2018-01-03 00:50:20 +0100
committerantham <hamonanth@gmail.com>2018-04-16 21:47:31 +0200
commit0c7d7c6fc44a88b9ecd8aac9744272a71dd91f02 (patch)
treefe68c13b3b54a67b095f0f26a7b67ba1cf90dca3 /repository.go
parent0db54e829f81a28f71c22d54c03daba5ec144c8d (diff)
downloadgo-git-0c7d7c6fc44a88b9ecd8aac9744272a71dd91f02.tar.gz
Resolve full commit sha to plumbing hash
Signed-off-by: antham <hamonanth@gmail.com>
Diffstat (limited to 'repository.go')
-rw-r--r--repository.go25
1 files changed, 20 insertions, 5 deletions
diff --git a/repository.go b/repository.go
index 35780e2..928ad9d 100644
--- a/repository.go
+++ b/repository.go
@@ -1021,6 +1021,8 @@ func (r *Repository) ResolveRevision(rev plumbing.Revision) (*plumbing.Hash, err
case revision.Ref:
revisionRef := item.(revision.Ref)
var ref *plumbing.Reference
+ var hashCommit, refCommit *object.Commit
+ var rErr, hErr error
for _, rule := range append([]string{"%s"}, plumbing.RefRevParseRules...) {
ref, err = storer.ResolveReference(r.Storer, plumbing.ReferenceName(fmt.Sprintf(rule, revisionRef)))
@@ -1030,14 +1032,27 @@ func (r *Repository) ResolveRevision(rev plumbing.Revision) (*plumbing.Hash, err
}
}
- if ref == nil {
- return &plumbing.ZeroHash, plumbing.ErrReferenceNotFound
+ if ref != nil {
+ refCommit, rErr = r.CommitObject(ref.Hash())
+ } else {
+ rErr = plumbing.ErrReferenceNotFound
}
- commit, err = r.CommitObject(ref.Hash())
+ isHash := plumbing.NewHash(string(revisionRef)).String() == string(revisionRef)
- if err != nil {
- return &plumbing.ZeroHash, err
+ if isHash {
+ hashCommit, hErr = r.CommitObject(plumbing.NewHash(string(revisionRef)))
+ }
+
+ switch {
+ case rErr == nil && !isHash:
+ commit = refCommit
+ case rErr != nil && isHash && hErr == nil:
+ commit = hashCommit
+ case rErr == nil && isHash && hErr == nil:
+ return &plumbing.ZeroHash, fmt.Errorf(`refname "%s" is ambiguous`, revisionRef)
+ default:
+ return &plumbing.ZeroHash, plumbing.ErrReferenceNotFound
}
case revision.CaretPath:
depth := item.(revision.CaretPath).Depth