Skip to content

Commit f44302e

Browse files
author
Paulo Gomes
committed
Bump libgit2 to 1.3.0 and git2go to V33.
Downstream breaking changes introduced since git2go@V31: - git2go.ErrorCode was deprecated in favour of the native error type. - FetchOptions no longer expects a pointer, but rather the actual value of git2go.FetchOptions. Signed-off-by: Paulo Gomes <[email protected]>
1 parent 1dae5e7 commit f44302e

File tree

6 files changed

+86
-60
lines changed

6 files changed

+86
-60
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ require (
2323
github.com/go-git/go-billy/v5 v5.3.1
2424
github.com/go-git/go-git/v5 v5.4.2
2525
github.com/go-logr/logr v1.2.2
26-
github.com/libgit2/git2go/v31 v31.7.6
26+
github.com/libgit2/git2go/v33 v33.0.6
2727
github.com/minio/minio-go/v7 v7.0.15
2828
github.com/onsi/ginkgo v1.16.5
2929
github.com/onsi/gomega v1.17.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -622,8 +622,8 @@ github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0/go.mod h1:vmVJ0l/dxyfGW6Fm
622622
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
623623
github.com/lib/pq v1.10.0 h1:Zx5DJFEYQXio93kgXnQ09fXNiUKsqv4OUEu2UtGcB1E=
624624
github.com/lib/pq v1.10.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
625-
github.com/libgit2/git2go/v31 v31.7.6 h1:jg/pNomrQULnafmfF6XTkozPX5ypyELoWErWkJuYPcI=
626-
github.com/libgit2/git2go/v31 v31.7.6/go.mod h1:c/rkJcBcUFx6wHaT++UwNpKvIsmPNqCeQ/vzO4DrEec=
625+
github.com/libgit2/git2go/v33 v33.0.6 h1:F//bA3/pgSTVq2hLNahhnof9NxyCzFF/c3MB6lb93Qo=
626+
github.com/libgit2/git2go/v33 v33.0.6/go.mod h1:KdpqkU+6+++4oHna/MIOgx4GCQ92IPCdpVRMRI80J+4=
627627
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de h1:9TO3cAIGXtEhnIaL+V+BEER86oLrvS+kWobKpbJuye0=
628628
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de/go.mod h1:zAbeS9B/r2mtpb6U+EI2rYA5OAXxsYw6wTamcNW+zcE=
629629
github.com/lithammer/dedent v1.1.0/go.mod h1:jrXYCQtgg0nJiN+StA2KgR7w6CiQNv9Fd/Z9BP0jIOc=

pkg/git/libgit2/checkout.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525

2626
"github.com/Masterminds/semver/v3"
2727
"github.com/go-logr/logr"
28-
git2go "github.com/libgit2/git2go/v31"
28+
git2go "github.com/libgit2/git2go/v33"
2929

3030
"github.com/fluxcd/pkg/gitutil"
3131
"github.com/fluxcd/pkg/version"
@@ -61,7 +61,7 @@ type CheckoutBranch struct {
6161

6262
func (c *CheckoutBranch) Checkout(ctx context.Context, path, url string, opts *git.AuthOptions) (*git.Commit, error) {
6363
repo, err := git2go.Clone(url, path, &git2go.CloneOptions{
64-
FetchOptions: &git2go.FetchOptions{
64+
FetchOptions: git2go.FetchOptions{
6565
DownloadTags: git2go.DownloadTagsNone,
6666
RemoteCallbacks: RemoteCallbacks(ctx, opts),
6767
ProxyOptions: git2go.ProxyOptions{Type: git2go.ProxyTypeAuto},
@@ -91,7 +91,7 @@ type CheckoutTag struct {
9191

9292
func (c *CheckoutTag) Checkout(ctx context.Context, path, url string, opts *git.AuthOptions) (*git.Commit, error) {
9393
repo, err := git2go.Clone(url, path, &git2go.CloneOptions{
94-
FetchOptions: &git2go.FetchOptions{
94+
FetchOptions: git2go.FetchOptions{
9595
DownloadTags: git2go.DownloadTagsAll,
9696
RemoteCallbacks: RemoteCallbacks(ctx, opts),
9797
ProxyOptions: git2go.ProxyOptions{Type: git2go.ProxyTypeAuto},
@@ -115,7 +115,7 @@ type CheckoutCommit struct {
115115

116116
func (c *CheckoutCommit) Checkout(ctx context.Context, path, url string, opts *git.AuthOptions) (*git.Commit, error) {
117117
repo, err := git2go.Clone(url, path, &git2go.CloneOptions{
118-
FetchOptions: &git2go.FetchOptions{
118+
FetchOptions: git2go.FetchOptions{
119119
DownloadTags: git2go.DownloadTagsNone,
120120
RemoteCallbacks: RemoteCallbacks(ctx, opts),
121121
ProxyOptions: git2go.ProxyOptions{Type: git2go.ProxyTypeAuto},
@@ -147,7 +147,7 @@ func (c *CheckoutSemVer) Checkout(ctx context.Context, path, url string, opts *g
147147
}
148148

149149
repo, err := git2go.Clone(url, path, &git2go.CloneOptions{
150-
FetchOptions: &git2go.FetchOptions{
150+
FetchOptions: git2go.FetchOptions{
151151
DownloadTags: git2go.DownloadTagsAll,
152152
RemoteCallbacks: RemoteCallbacks(ctx, opts),
153153
ProxyOptions: git2go.ProxyOptions{Type: git2go.ProxyTypeAuto},

pkg/git/libgit2/checkout_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"testing"
2626
"time"
2727

28-
git2go "github.com/libgit2/git2go/v31"
28+
git2go "github.com/libgit2/git2go/v33"
2929
. "github.com/onsi/gomega"
3030
)
3131

pkg/git/libgit2/transport.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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).
6363
func 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.
8181
func 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).
9595
func 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.
157157
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 {
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.
179179
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 {
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

Comments
 (0)