relax the SHA1 regex to cover SHA1, SHA256 and any other length of SHA

Signed-off-by: Benoit Gagnon <benoit.gagnon@ubisoft.com>
This commit is contained in:
Benoit Gagnon 2019-10-24 11:06:36 -04:00
parent 2bf42f11cd
commit 1915ef519a

View file

@ -153,7 +153,7 @@ func remoteResolveRef(ctx context.Context, remote string, ref string) (string, e
if err != nil {
return "", err
}
commitShaPattern, _ := regexp.Compile("^([0-9a-f]{40})\\b")
commitShaPattern := regexp.MustCompile("^([0-9a-f]{40,})\\b")
commitSha := commitShaPattern.FindString(b.String())
return commitSha, nil
}
@ -176,9 +176,9 @@ func (p *GitPackage) Install(ctx context.Context, name, dir, version string) (st
// but possible event that a ref is exactly 40 hex characters
commitSha, err := remoteResolveRef(ctx, p.Source.Remote, version)
// If the ref resolution failed and "version" looks like a SHA1, assume it is one
// and proceed.
commitShaPattern := regexp.MustCompile("^([0-9a-f]{40})$")
// If the ref resolution failed and "version" looks like a SHA,
// assume it is one and proceed.
commitShaPattern := regexp.MustCompile("^([0-9a-f]{40,})$")
if commitSha == "" && commitShaPattern.MatchString(version) {
commitSha = version
}