aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/hash.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2020-05-10 11:02:21 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2020-05-10 11:02:21 +0200
commit21f106e6647ce70d1d40df65cd85e2e86264d2f0 (patch)
tree4e92440758cc6e3901d2467405225144cfe29fea /plumbing/hash.go
parent79798d4a85b9389b28ef26b70944157d16fc205a (diff)
downloadgo-git-21f106e6647ce70d1d40df65cd85e2e86264d2f0.tar.gz
config: RefSpec.IsExactSHA1, validates if the refspec describes an exact SHA1 ref
Diffstat (limited to 'plumbing/hash.go')
-rw-r--r--plumbing/hash.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/plumbing/hash.go b/plumbing/hash.go
index 637a425..afc602a 100644
--- a/plumbing/hash.go
+++ b/plumbing/hash.go
@@ -71,3 +71,13 @@ type HashSlice []Hash
func (p HashSlice) Len() int { return len(p) }
func (p HashSlice) Less(i, j int) bool { return bytes.Compare(p[i][:], p[j][:]) < 0 }
func (p HashSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
+
+// IsHash returns true if the given string is a valid hash.
+func IsHash(s string) bool {
+ if len(s) != 40 {
+ return false
+ }
+
+ _, err := hex.DecodeString(s)
+ return err == nil
+}