aboutsummaryrefslogtreecommitdiffstats
path: root/repository.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2018-04-17 14:31:19 +0200
committerGitHub <noreply@github.com>2018-04-17 14:31:19 +0200
commitb30763cb64afa91c016b23e905af0a378eb1b76d (patch)
treef959b230dd2b5bbd1ae497bcdc7bc5c68e80d7eb /repository.go
parent46a247f8c11e580d85ef6378848a15e17b8b5401 (diff)
parent0c7d7c6fc44a88b9ecd8aac9744272a71dd91f02 (diff)
downloadgo-git-b30763cb64afa91c016b23e905af0a378eb1b76d.tar.gz
Merge pull request #706 from antham/resolve-commit-sha1v4.3.1
Resolve full commit sha
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