aboutsummaryrefslogtreecommitdiffstats
path: root/modules/git/repo_branch_gogit.go
diff options
context:
space:
mode:
Diffstat (limited to 'modules/git/repo_branch_gogit.go')
-rw-r--r--modules/git/repo_branch_gogit.go21
1 files changed, 13 insertions, 8 deletions
diff --git a/modules/git/repo_branch_gogit.go b/modules/git/repo_branch_gogit.go
index d1ec14d811..dbc4a5fedc 100644
--- a/modules/git/repo_branch_gogit.go
+++ b/modules/git/repo_branch_gogit.go
@@ -14,28 +14,33 @@ import (
"github.com/go-git/go-git/v5/plumbing/storer"
)
-// IsObjectExist returns true if given reference exists in the repository.
+// IsObjectExist returns true if the given object exists in the repository.
+// FIXME: Inconsistent behavior with nogogit edition
+// Unlike the implementation of IsObjectExist in nogogit edition, it does not support short hashes here.
+// For example, IsObjectExist("153f451") will return false, but it will return true in nogogit edition.
+// To fix this, the solution could be adding support for short hashes in gogit edition if it's really needed.
func (repo *Repository) IsObjectExist(name string) bool {
if name == "" {
return false
}
- _, err := repo.gogitRepo.ResolveRevision(plumbing.Revision(name))
-
+ _, err := repo.gogitRepo.Object(plumbing.AnyObject, plumbing.NewHash(name))
return err == nil
}
// IsReferenceExist returns true if given reference exists in the repository.
+// FIXME: Inconsistent behavior with nogogit edition
+// Unlike the implementation of IsObjectExist in nogogit edition, it does not support blob hashes here.
+// For example, IsObjectExist([existing_blob_hash]) will return false, but it will return true in nogogit edition.
+// To fix this, the solution could be refusing to support blob hashes in nogogit edition since a blob hash is not a reference.
func (repo *Repository) IsReferenceExist(name string) bool {
if name == "" {
return false
}
- reference, err := repo.gogitRepo.Reference(plumbing.ReferenceName(name), true)
- if err != nil {
- return false
- }
- return reference.Type() != plumbing.InvalidReference
+ _, err := repo.gogitRepo.ResolveRevision(plumbing.Revision(name))
+
+ return err == nil
}
// IsBranchExist returns true if given branch exists in current repository.