aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/hash.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2020-05-11 00:28:21 +0200
committerGitHub <noreply@github.com>2020-05-11 00:28:21 +0200
commit568154cab87659b31c751678c7f7dc93fedf60af (patch)
tree233f993126f9346b06979202042bd5d95ba70bf2 /plumbing/hash.go
parente4166c560bfa0bcdadd3197ad00365b4f1c027fb (diff)
parent8ecd388ae101a0dd88b78dc47ebfef9fe51699df (diff)
downloadgo-git-568154cab87659b31c751678c7f7dc93fedf60af.tar.gz
Merge pull request #58 from go-git/exact-sha1
Remote.Fetch: support exact SHA1 refspecs
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
+}