aboutsummaryrefslogtreecommitdiffstats
path: root/config/refspec.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 /config/refspec.go
parent79798d4a85b9389b28ef26b70944157d16fc205a (diff)
downloadgo-git-21f106e6647ce70d1d40df65cd85e2e86264d2f0.tar.gz
config: RefSpec.IsExactSHA1, validates if the refspec describes an exact SHA1 ref
Diffstat (limited to 'config/refspec.go')
-rw-r--r--config/refspec.go9
1 files changed, 7 insertions, 2 deletions
diff --git a/config/refspec.go b/config/refspec.go
index 87cf2a6..4bfaa37 100644
--- a/config/refspec.go
+++ b/config/refspec.go
@@ -25,7 +25,7 @@ var (
// reference even if it isn’t a fast-forward.
// eg.: "+refs/heads/*:refs/remotes/origin/*"
//
-// https://git-scm.com/book/es/v2/Git-Internals-The-Refspec
+// https://git-scm.com/book/en/v2/Git-Internals-The-Refspec
type RefSpec string
// Validate validates the RefSpec
@@ -59,6 +59,11 @@ func (s RefSpec) IsDelete() bool {
return s[0] == refSpecSeparator[0]
}
+// IsExactSHA1 returns true if the source is a SHA1 hash.
+func (s RefSpec) IsExactSHA1() bool {
+ return plumbing.IsHash(s.Src())
+}
+
// Src return the src side.
func (s RefSpec) Src() string {
spec := string(s)
@@ -69,8 +74,8 @@ func (s RefSpec) Src() string {
} else {
start = 0
}
- end := strings.Index(spec, refSpecSeparator)
+ end := strings.Index(spec, refSpecSeparator)
return spec[start:end]
}