@@ -31,7 +31,7 @@ import (
31
31
"strings"
32
32
"time"
33
33
34
- git2go "github.com/libgit2/git2go/v31 "
34
+ git2go "github.com/libgit2/git2go/v33 "
35
35
"golang.org/x/crypto/ssh"
36
36
"golang.org/x/crypto/ssh/knownhosts"
37
37
@@ -61,16 +61,16 @@ func RemoteCallbacks(ctx context.Context, opts *git.AuthOptions) git2go.RemoteCa
61
61
// libgit2 it should stop the transfer when the given context is closed (due to
62
62
// e.g. a timeout).
63
63
func transferProgressCallback (ctx context.Context ) git2go.TransferProgressCallback {
64
- return func (p git2go.TransferProgress ) git2go. ErrorCode {
64
+ return func (p git2go.TransferProgress ) error {
65
65
// Early return if all the objects have been received.
66
66
if p .ReceivedObjects == p .TotalObjects {
67
- return git2go . ErrorCodeOK
67
+ return nil
68
68
}
69
69
select {
70
70
case <- ctx .Done ():
71
- return git2go . ErrorCodeUser
71
+ return fmt . Errorf ( "transport close (potentially due to a timeout)" )
72
72
default :
73
- return git2go . ErrorCodeOK
73
+ return nil
74
74
}
75
75
}
76
76
}
@@ -79,12 +79,12 @@ func transferProgressCallback(ctx context.Context) git2go.TransferProgressCallba
79
79
// libgit2 it should cancel the network operation when the given context is
80
80
// closed.
81
81
func transportMessageCallback (ctx context.Context ) git2go.TransportMessageCallback {
82
- return func (_ string ) git2go. ErrorCode {
82
+ return func (_ string ) error {
83
83
select {
84
84
case <- ctx .Done ():
85
- return git2go . ErrorCodeUser
85
+ return fmt . Errorf ( "transport closed" )
86
86
default :
87
- return git2go . ErrorCodeOK
87
+ return nil
88
88
}
89
89
}
90
90
}
@@ -93,16 +93,16 @@ func transportMessageCallback(ctx context.Context) git2go.TransportMessageCallba
93
93
// signals libgit2 it should stop the push transfer when the given context is
94
94
// closed (due to e.g. a timeout).
95
95
func pushTransferProgressCallback (ctx context.Context ) git2go.PushTransferProgressCallback {
96
- return func (current , total uint32 , _ uint ) git2go. ErrorCode {
96
+ return func (current , total uint32 , _ uint ) error {
97
97
// Early return if current equals total.
98
98
if current == total {
99
- return git2go . ErrorCodeOK
99
+ return nil
100
100
}
101
101
select {
102
102
case <- ctx .Done ():
103
- return git2go . ErrorCodeUser
103
+ return fmt . Errorf ( "transport close (potentially due to a timeout)" )
104
104
default :
105
- return git2go . ErrorCodeOK
105
+ return nil
106
106
}
107
107
}
108
108
}
@@ -155,10 +155,10 @@ func certificateCallback(opts *git.AuthOptions) git2go.CertificateCheckCallback
155
155
// x509Callback returns a CertificateCheckCallback that verifies the
156
156
// certificate against the given caBundle for git.HTTPS Transports.
157
157
func 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 {
159
159
roots := x509 .NewCertPool ()
160
160
if ok := roots .AppendCertsFromPEM (caBundle ); ! ok {
161
- return git2go . ErrorCodeCertificate
161
+ return fmt . Errorf ( "PEM CA bundle could not be appended to x509 certificate pool" )
162
162
}
163
163
164
164
opts := x509.VerifyOptions {
@@ -167,20 +167,20 @@ func x509Callback(caBundle []byte) git2go.CertificateCheckCallback {
167
167
CurrentTime : now (),
168
168
}
169
169
if _ , err := cert .X509 .Verify (opts ); err != nil {
170
- return git2go . ErrorCodeCertificate
170
+ return fmt . Errorf ( "verification failed: %w" , err )
171
171
}
172
- return git2go . ErrorCodeOK
172
+ return nil
173
173
}
174
174
}
175
175
176
176
// knownHostCallback returns a CertificateCheckCallback that verifies
177
177
// the key of Git server against the given host and known_hosts for
178
178
// git.SSH Transports.
179
179
func 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 {
181
181
kh , err := parseKnownHosts (string (knownHosts ))
182
182
if err != nil {
183
- return git2go . ErrorCodeCertificate
183
+ return fmt . Errorf ( "failed to parse known_hosts: %w" , err )
184
184
}
185
185
186
186
// First, attempt to split the configured host and port to validate
@@ -200,7 +200,7 @@ func knownHostsCallback(host string, knownHosts []byte) git2go.CertificateCheckC
200
200
}
201
201
202
202
if hostnameWithoutPort != hostWithoutPort {
203
- return git2go . ErrorCodeUser
203
+ return fmt . Errorf ( "host mismatch: %q %q" , hostWithoutPort , hostnameWithoutPort )
204
204
}
205
205
206
206
// We are now certain that the configured host and the hostname
@@ -210,10 +210,10 @@ func knownHostsCallback(host string, knownHosts []byte) git2go.CertificateCheckC
210
210
h := knownhosts .Normalize (host )
211
211
for _ , k := range kh {
212
212
if k .matches (h , cert .Hostkey ) {
213
- return git2go . ErrorCodeOK
213
+ return nil
214
214
}
215
215
}
216
- return git2go . ErrorCodeCertificate
216
+ return fmt . Errorf ( "hostkey could not be verified" )
217
217
}
218
218
}
219
219
0 commit comments