@@ -31,7 +31,7 @@ import (
3131 "strings"
3232 "time"
3333
34- git2go "github.com/libgit2/git2go/v31 "
34+ git2go "github.com/libgit2/git2go/v33 "
3535 "golang.org/x/crypto/ssh"
3636 "golang.org/x/crypto/ssh/knownhosts"
3737
@@ -61,16 +61,16 @@ func RemoteCallbacks(ctx context.Context, opts *git.AuthOptions) git2go.RemoteCa
6161// libgit2 it should stop the transfer when the given context is closed (due to
6262// e.g. a timeout).
6363func transferProgressCallback (ctx context.Context ) git2go.TransferProgressCallback {
64- return func (p git2go.TransferProgress ) git2go. ErrorCode {
64+ return func (p git2go.TransferProgress ) error {
6565 // Early return if all the objects have been received.
6666 if p .ReceivedObjects == p .TotalObjects {
67- return git2go . ErrorCodeOK
67+ return nil
6868 }
6969 select {
7070 case <- ctx .Done ():
71- return git2go . ErrorCodeUser
71+ return fmt . Errorf ( "transport close - potentially due to a timeout" )
7272 default :
73- return git2go . ErrorCodeOK
73+ return nil
7474 }
7575 }
7676}
@@ -79,12 +79,12 @@ func transferProgressCallback(ctx context.Context) git2go.TransferProgressCallba
7979// libgit2 it should cancel the network operation when the given context is
8080// closed.
8181func transportMessageCallback (ctx context.Context ) git2go.TransportMessageCallback {
82- return func (_ string ) git2go. ErrorCode {
82+ return func (_ string ) error {
8383 select {
8484 case <- ctx .Done ():
85- return git2go . ErrorCodeUser
85+ return fmt . Errorf ( "transport closed" )
8686 default :
87- return git2go . ErrorCodeOK
87+ return nil
8888 }
8989 }
9090}
@@ -93,16 +93,16 @@ func transportMessageCallback(ctx context.Context) git2go.TransportMessageCallba
9393// signals libgit2 it should stop the push transfer when the given context is
9494// closed (due to e.g. a timeout).
9595func pushTransferProgressCallback (ctx context.Context ) git2go.PushTransferProgressCallback {
96- return func (current , total uint32 , _ uint ) git2go. ErrorCode {
96+ return func (current , total uint32 , _ uint ) error {
9797 // Early return if current equals total.
9898 if current == total {
99- return git2go . ErrorCodeOK
99+ return nil
100100 }
101101 select {
102102 case <- ctx .Done ():
103- return git2go . ErrorCodeUser
103+ return fmt . Errorf ( "transport close - potentially due to a timeout" )
104104 default :
105- return git2go . ErrorCodeOK
105+ return nil
106106 }
107107 }
108108}
@@ -155,10 +155,10 @@ func certificateCallback(opts *git.AuthOptions) git2go.CertificateCheckCallback
155155// x509Callback returns a CertificateCheckCallback that verifies the
156156// certificate against the given caBundle for git.HTTPS Transports.
157157func x509Callback (caBundle []byte ) git2go.CertificateCheckCallback {
158- return func (cert * git2go.Certificate , valid bool , hostname string ) git2go. ErrorCode {
158+ return func (cert * git2go.Certificate , valid bool , hostname string ) error {
159159 roots := x509 .NewCertPool ()
160160 if ok := roots .AppendCertsFromPEM (caBundle ); ! ok {
161- return git2go . ErrorCodeCertificate
161+ return fmt . Errorf ( "x509 cert could not be appended" )
162162 }
163163
164164 opts := x509.VerifyOptions {
@@ -167,20 +167,20 @@ func x509Callback(caBundle []byte) git2go.CertificateCheckCallback {
167167 CurrentTime : now (),
168168 }
169169 if _ , err := cert .X509 .Verify (opts ); err != nil {
170- return git2go . ErrorCodeCertificate
170+ return fmt . Errorf ( "x509 cert could not be verified" )
171171 }
172- return git2go . ErrorCodeOK
172+ return nil
173173 }
174174}
175175
176176// knownHostCallback returns a CertificateCheckCallback that verifies
177177// the key of Git server against the given host and known_hosts for
178178// git.SSH Transports.
179179func knownHostsCallback (host string , knownHosts []byte ) git2go.CertificateCheckCallback {
180- return func (cert * git2go.Certificate , valid bool , hostname string ) git2go. ErrorCode {
180+ return func (cert * git2go.Certificate , valid bool , hostname string ) error {
181181 kh , err := parseKnownHosts (string (knownHosts ))
182182 if err != nil {
183- return git2go . ErrorCodeCertificate
183+ return fmt . Errorf ( "failed to parse known_hosts: %w" , err )
184184 }
185185
186186 // First, attempt to split the configured host and port to validate
@@ -200,7 +200,7 @@ func knownHostsCallback(host string, knownHosts []byte) git2go.CertificateCheckC
200200 }
201201
202202 if hostnameWithoutPort != hostWithoutPort {
203- return git2go . ErrorCodeUser
203+ return fmt . Errorf ( "host mismatch: %q %q \n " , hostWithoutPort , hostnameWithoutPort )
204204 }
205205
206206 // We are now certain that the configured host and the hostname
@@ -210,10 +210,10 @@ func knownHostsCallback(host string, knownHosts []byte) git2go.CertificateCheckC
210210 h := knownhosts .Normalize (host )
211211 for _ , k := range kh {
212212 if k .matches (h , cert .Hostkey ) {
213- return git2go . ErrorCodeOK
213+ return nil
214214 }
215215 }
216- return git2go . ErrorCodeCertificate
216+ return fmt . Errorf ( "hostkey could not be verified" )
217217 }
218218}
219219
0 commit comments