From 1997c572cb34a5556e9561c10e1495b38aed77c9 Mon Sep 17 00:00:00 2001 From: Paulo Gomes Date: Wed, 26 Feb 2025 23:59:22 +0000 Subject: [PATCH 1/6] Bump module to v6 Signed-off-by: Paulo Gomes --- fixtures.go | 6 +- fixtures_options.go | 4 +- go.mod | 6 +- go.sum | 31 +-- internal/embedfs/embed.go | 261 ------------------ internal/embedfs/embed_test.go | 390 --------------------------- internal/embedfs/testdata/empty.txt | 0 internal/embedfs/testdata/empty2.txt | 1 - internal/tgz/tgz.go | 4 +- internal/tgz/tgz_test.go | 4 +- 10 files changed, 19 insertions(+), 688 deletions(-) delete mode 100644 internal/embedfs/embed.go delete mode 100644 internal/embedfs/embed_test.go delete mode 100644 internal/embedfs/testdata/empty.txt delete mode 100644 internal/embedfs/testdata/empty2.txt diff --git a/fixtures.go b/fixtures.go index 360fc4f..0e645a3 100644 --- a/fixtures.go +++ b/fixtures.go @@ -9,13 +9,13 @@ import ( "strings" "testing" - "github.com/go-git/go-billy/v5" - "github.com/go-git/go-git-fixtures/v5/internal/embedfs" + "github.com/go-git/go-billy/v6" + "github.com/go-git/go-billy/v6/embedfs" "github.com/go-git/go-git-fixtures/v5/internal/tgz" ) //nolint:gochecknoglobals -var Filesystem = embedfs.New(&data, "data") +var Filesystem = embedfs.New(&data) //go:embed data var data embed.FS diff --git a/fixtures_options.go b/fixtures_options.go index 379e7fd..3a35465 100644 --- a/fixtures_options.go +++ b/fixtures_options.go @@ -1,8 +1,8 @@ package fixtures import ( - "github.com/go-git/go-billy/v5" - "github.com/go-git/go-billy/v5/osfs" + "github.com/go-git/go-billy/v6" + "github.com/go-git/go-billy/v6/osfs" "github.com/go-git/go-git-fixtures/v5/internal/tgz" ) diff --git a/go.mod b/go.mod index 4480709..2434627 100644 --- a/go.mod +++ b/go.mod @@ -4,14 +4,14 @@ module github.com/go-git/go-git-fixtures/v5 go 1.21 require ( - github.com/go-git/go-billy/v5 v5.6.2 + github.com/go-git/go-billy/v6 v6.0.0-20250226231054-855d56b95681 github.com/stretchr/testify v1.10.0 ) require ( - github.com/cyphar/filepath-securejoin v0.3.6 // indirect + github.com/cyphar/filepath-securejoin v0.4.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - golang.org/x/sys v0.29.0 // indirect + golang.org/x/sys v0.30.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 5c7006c..e49ed20 100644 --- a/go.sum +++ b/go.sum @@ -1,33 +1,16 @@ -github.com/cyphar/filepath-securejoin v0.3.6 h1:4d9N5ykBnSp5Xn2JkhocYDkOpURL/18CYMpo6xB9uWM= -github.com/cyphar/filepath-securejoin v0.3.6/go.mod h1:Sdj7gXlvMcPZsbhwhQ33GguGLDGQL7h7bg04C/+u9jI= +github.com/cyphar/filepath-securejoin v0.4.1 h1:JyxxyPEaktOD+GAnqIqTf9A8tHyAG22rowi7HkoSU1s= +github.com/cyphar/filepath-securejoin v0.4.1/go.mod h1:Sdj7gXlvMcPZsbhwhQ33GguGLDGQL7h7bg04C/+u9jI= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/go-git/go-billy/v5 v5.6.2 h1:6Q86EsPXMa7c3YZ3aLAQsMA0VlWmy43r6FHqa/UNbRM= -github.com/go-git/go-billy/v5 v5.6.2/go.mod h1:rcFC2rAsp/erv7CMz9GczHcuD0D32fWzH+MJAU+jaUU= -github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= -github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= -github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= -github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= -github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k= -github.com/onsi/gomega v1.34.1/go.mod h1:kU1QgUvBDLXBJq618Xvm2LUX6rSAfRaFRTcdOeDLwwY= +github.com/go-git/go-billy/v6 v6.0.0-20250226231054-855d56b95681 h1:dEJLKk2KlPXJHsKo9Yowx/Z3qaj66ylcugbnNl+LZsQ= +github.com/go-git/go-billy/v6 v6.0.0-20250226231054-855d56b95681/go.mod h1:HSPUM9l9AmLqMQiaJuOonBGMV+UQpncqo07ys+z3VBs= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= -github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8= -golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY= -golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0= -golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k= -golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU= -golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= -golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= +golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= +golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= -gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/embedfs/embed.go b/internal/embedfs/embed.go deleted file mode 100644 index c3af9c6..0000000 --- a/internal/embedfs/embed.go +++ /dev/null @@ -1,261 +0,0 @@ -// embedfs exposes an embed.FS as a read-only billy.Filesystem. -package embedfs - -import ( - "bytes" - "embed" - "fmt" - "io/fs" - "os" - "path/filepath" - "sort" - "strings" - "sync" - - "github.com/go-git/go-billy/v5" - "github.com/go-git/go-billy/v5/memfs" -) - -type Embed struct { - underlying *embed.FS - dir string -} - -func New(efs *embed.FS, dir string) *Embed { - fs := &Embed{ - underlying: efs, - dir: dir, - } - - if efs == nil { - fs.underlying = &embed.FS{} - } - - return fs -} - -func (fs *Embed) Root() string { - return "" -} - -func (fs *Embed) prefix(filename string) string { - if fs.dir != "" && !strings.HasPrefix(filename, fs.dir+"/") { - return fs.dir + "/" + filename - } - - return filename -} - -func (fs *Embed) Stat(filename string) (os.FileInfo, error) { - f, err := fs.underlying.Open(fs.prefix(filename)) - if err != nil { - return nil, err - } - defer f.Close() - - return f.Stat() -} - -func (fs *Embed) Open(filename string) (billy.File, error) { - return fs.OpenFile(filename, os.O_RDONLY, 0) -} - -func (fs *Embed) OpenFile(filename string, flag int, _ os.FileMode) (billy.File, error) { - if flag&(os.O_CREATE|os.O_WRONLY|os.O_APPEND|os.O_RDWR|os.O_EXCL|os.O_TRUNC) != 0 { - return nil, billy.ErrReadOnly - } - - filename = fs.prefix(filename) - f, err := fs.underlying.Open(filename) - if err != nil { - return nil, err - } - defer f.Close() - - fi, err := f.Stat() - if err != nil { - return nil, err - } - - if fi.IsDir() { - return nil, fmt.Errorf("cannot open directory: %s", filename) - } - - data, err := fs.underlying.ReadFile(filename) - if err != nil { - return nil, err - } - - // Only load the bytes to memory if the files is needed. - lazyFunc := func() *bytes.Reader { return bytes.NewReader(data) } - - return toFile(lazyFunc, fi), nil -} - -// Join return a path with all elements joined by forward slashes. -// -// This behaviour is OS-agnostic. -func (fs *Embed) Join(elem ...string) string { - for i, el := range elem { - if el != "" { - clean := filepath.Clean(strings.Join(elem[i:], "/")) - - return filepath.ToSlash(clean) - } - } - - return "" -} - -func (fs *Embed) ReadDir(path string) ([]os.FileInfo, error) { - e, err := fs.underlying.ReadDir(path) - if err != nil { - return nil, err - } - - entries := make([]os.FileInfo, 0, len(e)) - for _, f := range e { - fi, _ := f.Info() - entries = append(entries, fi) - } - - sort.Sort(memfs.ByName(entries)) - - return entries, nil -} - -// Chroot is not supported. -// -// Calls will always return billy.ErrNotSupported. -func (fs *Embed) Chroot(_ string) (billy.Filesystem, error) { - return nil, billy.ErrNotSupported -} - -// Lstat is not supported. -// -// Calls will always return billy.ErrNotSupported. -func (fs *Embed) Lstat(_ string) (os.FileInfo, error) { - return nil, billy.ErrNotSupported -} - -// Readlink is not supported. -// -// Calls will always return billy.ErrNotSupported. -func (fs *Embed) Readlink(_ string) (string, error) { - return "", billy.ErrNotSupported -} - -// TempFile is not supported. -// -// Calls will always return billy.ErrNotSupported. -func (fs *Embed) TempFile(_, _ string) (billy.File, error) { - return nil, billy.ErrNotSupported -} - -// Symlink is not supported. -// -// Calls will always return billy.ErrReadOnly. -func (fs *Embed) Symlink(_, _ string) error { - return billy.ErrReadOnly -} - -// Create is not supported. -// -// Calls will always return billy.ErrReadOnly. -func (fs *Embed) Create(_ string) (billy.File, error) { - return nil, billy.ErrReadOnly -} - -// Rename is not supported. -// -// Calls will always return billy.ErrReadOnly. -func (fs *Embed) Rename(_, _ string) error { - return billy.ErrReadOnly -} - -// Remove is not supported. -// -// Calls will always return billy.ErrReadOnly. -func (fs *Embed) Remove(_ string) error { - return billy.ErrReadOnly -} - -// MkdirAll is not supported. -// -// Calls will always return billy.ErrReadOnly. -func (fs *Embed) MkdirAll(_ string, _ os.FileMode) error { - return billy.ErrReadOnly -} - -func toFile(lazy func() *bytes.Reader, fi fs.FileInfo) billy.File { - return &file{ - lazy: lazy, - fi: fi, - } -} - -type file struct { - lazy func() *bytes.Reader - reader *bytes.Reader - fi fs.FileInfo - once sync.Once -} - -func (f *file) loadReader() { - f.reader = f.lazy() -} - -func (f *file) Name() string { - return f.fi.Name() -} - -func (f *file) Read(b []byte) (int, error) { - f.once.Do(f.loadReader) - - return f.reader.Read(b) -} - -func (f *file) ReadAt(b []byte, off int64) (int, error) { - f.once.Do(f.loadReader) - - return f.reader.ReadAt(b, off) -} - -func (f *file) Seek(offset int64, whence int) (int64, error) { - f.once.Do(f.loadReader) - - return f.reader.Seek(offset, whence) -} - -func (f *file) Stat() (os.FileInfo, error) { - return f.fi, nil -} - -// Close for embedfs file is a no-op. -func (f *file) Close() error { - return nil -} - -// Lock for embedfs file is a no-op. -func (f *file) Lock() error { - return nil -} - -// Unlock for embedfs file is a no-op. -func (f *file) Unlock() error { - return nil -} - -// Truncate is not supported. -// -// Calls will always return billy.ErrReadOnly. -func (f *file) Truncate(_ int64) error { - return billy.ErrReadOnly -} - -// Write is not supported. -// -// Calls will always return billy.ErrReadOnly. -func (f *file) Write(_ []byte) (int, error) { - return 0, billy.ErrReadOnly -} diff --git a/internal/embedfs/embed_test.go b/internal/embedfs/embed_test.go deleted file mode 100644 index 5881eed..0000000 --- a/internal/embedfs/embed_test.go +++ /dev/null @@ -1,390 +0,0 @@ -package embedfs_test - -import ( - "embed" - "fmt" - "io" - "os" - "testing" - - "github.com/go-git/go-billy/v5" - "github.com/go-git/go-git-fixtures/v5/internal/embedfs" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" -) - -//go:embed testdata/empty.txt -var singleFile embed.FS - -//go:embed testdata -var testdataDir embed.FS - -//nolint:gochecknoglobals -var empty embed.FS - -func TestOpen(t *testing.T) { - t.Parallel() - - tests := []struct { - name string - dir string - want []byte - wantErr bool - }{ - { - name: "testdata/empty.txt", - want: []byte(""), - }, - { - name: "testdata/empty2.txt", - want: []byte("test"), - }, - { - name: "empty.txt", - dir: "testdata", - want: []byte(""), - }, - { - name: "empty2.txt", - dir: "testdata", - want: []byte("test"), - }, - { - name: "non-existent", - wantErr: true, - }, - } - - for _, tc := range tests { - tc := tc - t.Run(tc.name, func(t *testing.T) { - t.Parallel() - - fs := embedfs.New(&testdataDir, tc.dir) - - var got []byte - f, err := fs.Open(tc.name) - if tc.wantErr { - require.Error(t, err) - } else { - require.NoError(t, err) - assert.NotNil(t, f) - - got, err = io.ReadAll(f) - require.NoError(t, err) - } - - assert.Equal(t, tc.want, got) - }) - } -} - -func TestOpenFileFlags(t *testing.T) { - t.Parallel() - - tests := []struct { - name string - file string - flag int - wantErr string - }{ - { - name: "O_CREATE", - file: "testdata/empty.txt", - flag: os.O_CREATE, - wantErr: "read-only filesystem", - }, - { - name: "O_WRONLY", - file: "testdata/empty.txt", - flag: os.O_WRONLY, - wantErr: "read-only filesystem", - }, - { - name: "O_TRUNC", - file: "testdata/empty.txt", - flag: os.O_TRUNC, - wantErr: "read-only filesystem", - }, - { - name: "O_RDWR", - file: "testdata/empty.txt", - flag: os.O_RDWR, - wantErr: "read-only filesystem", - }, - { - name: "O_EXCL", - file: "testdata/empty.txt", - flag: os.O_EXCL, - wantErr: "read-only filesystem", - }, - { - name: "O_RDONLY", - file: "testdata/empty.txt", - flag: os.O_RDONLY, - }, - { - name: "no flags", - file: "testdata/empty.txt", - }, - } - - for _, tc := range tests { - tc := tc - t.Run(tc.name, func(t *testing.T) { - t.Parallel() - - fs := embedfs.New(&testdataDir, "") - - _, err := fs.OpenFile(tc.file, tc.flag, 0o700) - if tc.wantErr != "" { - require.ErrorContains(t, err, tc.wantErr) - } else { - require.NoError(t, err) - } - }) - } -} - -func TestStat(t *testing.T) { - t.Parallel() - - tests := []struct { - name string - dir string - want string - isDir bool - wantErr bool - }{ - { - name: "testdata/empty.txt", - want: "empty.txt", - }, - { - name: "testdata/empty2.txt", - want: "empty2.txt", - }, - { - name: "empty.txt", - dir: "testdata", - want: "empty.txt", - }, - { - name: "empty2.txt", - dir: "testdata", - want: "empty2.txt", - }, - { - name: "non-existent", - wantErr: true, - }, - { - name: "testdata", - want: "testdata", - isDir: true, - }, - } - - for _, tc := range tests { - tc := tc - t.Run(tc.name, func(t *testing.T) { - t.Parallel() - - fs := embedfs.New(&testdataDir, tc.dir) - - fi, err := fs.Stat(tc.name) - if tc.wantErr { - require.Error(t, err) - } else { - require.NoError(t, err) - assert.NotNil(t, fi) - - assert.Equal(t, tc.want, fi.Name()) - assert.Equal(t, tc.isDir, fi.IsDir()) - } - }) - } -} - -func TestReadDir(t *testing.T) { - t.Parallel() - - tests := []struct { - name string - path string - fs *embed.FS - want []string - wantErr bool - }{ - { - name: "singleFile", - path: "testdata", - fs: &singleFile, - want: []string{"empty.txt"}, - }, - { - name: "empty", - path: "", - fs: &empty, - want: []string{}, - wantErr: true, - }, - { - name: "testdataDir w/ path", - path: "testdata", - fs: &testdataDir, - want: []string{"empty.txt", "empty2.txt"}, - }, - { - name: "testdataDir return no dir names", - path: "", - fs: &testdataDir, - want: []string{}, - wantErr: true, - }, - } - - for _, tc := range tests { - tc := tc - t.Run(tc.name, func(t *testing.T) { - t.Parallel() - - fs := embedfs.New(tc.fs, "") - - fis, err := fs.ReadDir(tc.path) - if tc.wantErr { - require.Error(t, err) - } else { - require.NoError(t, err) - } - - assert.Len(t, fis, len(tc.want)) - matched := 0 - - for _, n := range fis { - for _, w := range tc.want { - if n.Name() == w { - matched++ - } - } - } - - assert.Equal(t, len(tc.want), matched, "not all files matched") - }) - } -} - -func TestUnsupported(t *testing.T) { - t.Parallel() - - fs := embedfs.New(&testdataDir, "") - - _, err := fs.Create("test") - require.ErrorIs(t, err, billy.ErrReadOnly) - - err = fs.Remove("test") - require.ErrorIs(t, err, billy.ErrReadOnly) - - err = fs.Rename("test", "test") - require.ErrorIs(t, err, billy.ErrReadOnly) - - err = fs.MkdirAll("test", 0o700) - require.ErrorIs(t, err, billy.ErrReadOnly) -} - -func TestFileUnsupported(t *testing.T) { - t.Parallel() - - fs := embedfs.New(&testdataDir, "") - - f, err := fs.Open("testdata/empty.txt") - require.NoError(t, err) - assert.NotNil(t, f) - - _, err = f.Write([]byte("foo")) - require.ErrorIs(t, err, billy.ErrReadOnly) - - err = f.Truncate(0) - require.ErrorIs(t, err, billy.ErrReadOnly) -} - -//nolint:paralleltest -func TestFileSeek(t *testing.T) { - fs := embedfs.New(&testdataDir, "") - - f, err := fs.Open("testdata/empty2.txt") - require.NoError(t, err) - assert.NotNil(t, f) - - tests := []struct { - seekOff int64 - seekWhence int - want string - }{ - {seekOff: 3, seekWhence: io.SeekStart, want: ""}, - {seekOff: 3, seekWhence: io.SeekStart, want: "t"}, - {seekOff: 2, seekWhence: io.SeekStart, want: "st"}, - {seekOff: 1, seekWhence: io.SeekStart, want: "est"}, - {seekOff: 0, seekWhence: io.SeekStart, want: "test"}, - {seekOff: 0, seekWhence: io.SeekStart, want: "t"}, - {seekOff: 1, seekWhence: io.SeekCurrent, want: "s"}, - {seekOff: -2, seekWhence: io.SeekEnd, want: "st"}, - } - - for i, tc := range tests { - tc := tc - t.Run(fmt.Sprintf("#%d", i), func(t *testing.T) { - _, err = f.Seek(tc.seekOff, tc.seekWhence) - require.NoError(t, err) - - data := make([]byte, len(tc.want)) - n, err := f.Read(data) - require.NoError(t, err) - assert.Equal(t, len(tc.want), n) - assert.Equal(t, []byte(tc.want), data) - }) - } -} - -func TestJoin(t *testing.T) { - t.Parallel() - - tests := []struct { - name string - path []string - want string - }{ - { - name: "no leading slash", - path: []string{"data", "foo/bar"}, - want: "data/foo/bar", - }, - { - name: "w/ leading slash", - path: []string{"/data", "foo/bar"}, - want: "/data/foo/bar", - }, - { - name: "..", - path: []string{"/data", "../bar"}, - want: "/bar", - }, - { - name: ".", - path: []string{"/data", "./bar"}, - want: "/data/bar", - }, - } - - for _, tc := range tests { - tc := tc - t.Run(tc.name, func(t *testing.T) { - t.Parallel() - - fs := embedfs.New(&empty, "") - - got := fs.Join(tc.path...) - assert.Equal(t, tc.want, got) - }) - } -} diff --git a/internal/embedfs/testdata/empty.txt b/internal/embedfs/testdata/empty.txt deleted file mode 100644 index e69de29..0000000 diff --git a/internal/embedfs/testdata/empty2.txt b/internal/embedfs/testdata/empty2.txt deleted file mode 100644 index 30d74d2..0000000 --- a/internal/embedfs/testdata/empty2.txt +++ /dev/null @@ -1 +0,0 @@ -test \ No newline at end of file diff --git a/internal/tgz/tgz.go b/internal/tgz/tgz.go index 1dcc540..c6191fd 100644 --- a/internal/tgz/tgz.go +++ b/internal/tgz/tgz.go @@ -10,8 +10,8 @@ import ( "math" "os" - "github.com/go-git/go-billy/v5" - "github.com/go-git/go-billy/v5/memfs" + "github.com/go-git/go-billy/v6" + "github.com/go-git/go-billy/v6/memfs" ) //nolint:gochecknoglobals diff --git a/internal/tgz/tgz_test.go b/internal/tgz/tgz_test.go index c8839b9..315a4ed 100644 --- a/internal/tgz/tgz_test.go +++ b/internal/tgz/tgz_test.go @@ -6,8 +6,8 @@ import ( "path/filepath" "testing" - "github.com/go-git/go-billy/v5" - "github.com/go-git/go-billy/v5/osfs" + "github.com/go-git/go-billy/v6" + "github.com/go-git/go-billy/v6/osfs" "github.com/go-git/go-git-fixtures/v5/internal/tgz" "github.com/stretchr/testify/require" ) From 19c80fcdf4a2f66d5700cd0e2c075407eda5bcfc Mon Sep 17 00:00:00 2001 From: Paulo Gomes Date: Wed, 26 Feb 2025 23:59:47 +0000 Subject: [PATCH 2/6] build: Bump golangci-lint to v1.64.5 Signed-off-by: Paulo Gomes --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 9afecaa..4e431e9 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ GOCMD = go GOTEST = $(GOCMD) test -GOLANGCI_VERSION ?= v1.62.2 +GOLANGCI_VERSION ?= v1.64.5 TOOLS_BIN := $(shell mkdir -p build/tools && realpath build/tools) GOLANGCI = $(TOOLS_BIN)/golangci-lint-$(GOLANGCI_VERSION) From e3fee092d83d0185466b6093db33f78c2845fffb Mon Sep 17 00:00:00 2001 From: Paulo Gomes Date: Thu, 27 Feb 2025 00:00:49 +0000 Subject: [PATCH 3/6] build: Bump Go to 1.22 Signed-off-by: Paulo Gomes --- .github/workflows/test.yml | 2 +- go.mod | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 83b9437..39dc590 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,7 +11,7 @@ jobs: strategy: fail-fast: false matrix: - go-version: [1.21.x, 1.22.x, 1.23.x] + go-version: [1.22.x, 1.23.x, 1.24.x] platform: [ubuntu-latest, macos-latest, windows-latest] permissions: diff --git a/go.mod b/go.mod index 2434627..c3e2908 100644 --- a/go.mod +++ b/go.mod @@ -1,7 +1,7 @@ module github.com/go-git/go-git-fixtures/v5 // go-git supports the last 3 stable Go versions. -go 1.21 +go 1.22 require ( github.com/go-git/go-billy/v6 v6.0.0-20250226231054-855d56b95681 From 4f2e607038800d2c9d77191e90eed13bd389a4c1 Mon Sep 17 00:00:00 2001 From: Paulo Gomes Date: Thu, 27 Feb 2025 00:12:42 +0000 Subject: [PATCH 4/6] Enable more linters and fix errors Signed-off-by: Paulo Gomes --- .golangci.yaml | 6 ------ fixtures.go | 2 +- fixtures_test.go | 5 ----- internal/tgz/tgz.go | 12 +++++++++--- internal/tgz/tgz_test.go | 15 ++++++++------- 5 files changed, 18 insertions(+), 22 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index db3ccc8..0a6950d 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -6,12 +6,6 @@ linters: enable-all: true disable: - depguard - - err113 - - execinquery - - exhaustruct - - exportloopref - - funlen - - gomnd - ireturn - mnd - varnamelen diff --git a/fixtures.go b/fixtures.go index 0e645a3..a420c66 100644 --- a/fixtures.go +++ b/fixtures.go @@ -304,8 +304,8 @@ func (f *Fixture) Clone() *Fixture { PackfileHash: f.PackfileHash, WorktreeHash: f.WorktreeHash, ObjectsCount: f.ObjectsCount, + Tags: slices.Clone(f.Tags), } - nf.Tags = slices.Clone(f.Tags) return nf } diff --git a/fixtures_test.go b/fixtures_test.go index f670e48..ee5d0ad 100644 --- a/fixtures_test.go +++ b/fixtures_test.go @@ -96,8 +96,6 @@ func TestByTag(t *testing.T) { } for _, tc := range tests { - tc := tc - t.Run(tc.tag, func(t *testing.T) { t.Parallel() @@ -133,8 +131,6 @@ func TestByURL(t *testing.T) { } for _, tc := range tests { - tc := tc - t.Run(tc.URL, func(t *testing.T) { t.Parallel() @@ -148,7 +144,6 @@ func TestIdx(t *testing.T) { t.Parallel() for i, f := range fixtures.ByTag("packfile") { - f := f t.Run("#"+strconv.Itoa(i), func(t *testing.T) { t.Parallel() diff --git a/internal/tgz/tgz.go b/internal/tgz/tgz.go index c6191fd..b07182c 100644 --- a/internal/tgz/tgz.go +++ b/internal/tgz/tgz.go @@ -14,6 +14,12 @@ import ( "github.com/go-git/go-billy/v6/memfs" ) +var ( + ErrUnableToUntarType = errors.New("unable to untar type") + ErrCannotBeNegative = errors.New("mode cannot be negative") + ErrCannotBeGreaterThanMaxUInt32 = errors.New("mode cannot be greater than max uint32") +) + //nolint:gochecknoglobals var MemFactory = func() (billy.Filesystem, error) { return memfs.New(), nil @@ -54,10 +60,10 @@ func zipTarReader(r io.Reader) (*tar.Reader, error) { func filemode(mode int64) (fs.FileMode, error) { if mode < 0 { - return 0, errors.New("mode cannot be negative") + return 0, ErrCannotBeNegative } if mode > math.MaxUint32 { - return 0, errors.New("mode cannot be greater than max uint32") + return 0, ErrCannotBeGreaterThanMaxUInt32 } return os.FileMode(mode), nil @@ -91,7 +97,7 @@ func unTar(fs billy.Filesystem, src *tar.Reader) error { return err } default: - return fmt.Errorf("unable to untar type: %c in file %s", + return fmt.Errorf("%w: %c in file %s", ErrUnableToUntarType, header.Typeflag, header.Name) } } diff --git a/internal/tgz/tgz_test.go b/internal/tgz/tgz_test.go index 315a4ed..37bf806 100644 --- a/internal/tgz/tgz_test.go +++ b/internal/tgz/tgz_test.go @@ -23,19 +23,21 @@ func TestExtractError(t *testing.T) { { tgz: "not-found", notFound: true, + wantErr: "", }, { - tgz: "invalid-gzip.tgz", - wantErr: "gzip: invalid header", + tgz: "invalid-gzip.tgz", + notFound: false, + wantErr: "gzip: invalid header", }, { - tgz: "not-a-tar.tgz", - wantErr: "unexpected EOF", + tgz: "not-a-tar.tgz", + notFound: false, + wantErr: "unexpected EOF", }, } for _, tc := range tests { - tc := tc t.Run("tgz path = "+tc.tgz, func(t *testing.T) { t.Parallel() @@ -59,7 +61,7 @@ func TestExtractError(t *testing.T) { } } -func TestExtract(t *testing.T) { +func TestExtract(t *testing.T) { //nolint t.Parallel() tests := []struct { @@ -106,7 +108,6 @@ func TestExtract(t *testing.T) { } for _, ff := range factories { - ff := ff for _, tc := range tests { t.Run(fmt.Sprintf("[%s] tgz path = %s", ff.name, tc.tgz), func(t *testing.T) { t.Parallel() From f60b2a16d3411e8868d8777d2a9c2568c4be1857 Mon Sep 17 00:00:00 2001 From: Paulo Gomes Date: Thu, 27 Feb 2025 00:15:16 +0000 Subject: [PATCH 5/6] build: Bump and pin GH actions Signed-off-by: Paulo Gomes --- .github/workflows/codeql.yml | 6 +++--- .github/workflows/test.yml | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index f877b62..dfcb738 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -25,11 +25,11 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@dd746615b3b9d728a6a37ca2045b68ca76d4841a # v3.28.8 + uses: github/codeql-action/init@b56ba49b26e50535fa1e7f7db0f4f7b4bf65d80d # v3.28.10 with: languages: ${{ matrix.language }} # xref: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs @@ -40,6 +40,6 @@ jobs: run: go build ./... - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@dd746615b3b9d728a6a37ca2045b68ca76d4841a # v3.28.8 + uses: github/codeql-action/analyze@b56ba49b26e50535fa1e7f7db0f4f7b4bf65d80d # v3.28.10 with: category: "/language:${{matrix.language}}" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 39dc590..2142411 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,10 +20,10 @@ jobs: runs-on: ${{ matrix.platform }} steps: - name: Checkout code - uses: actions/checkout@v4 + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - name: Install Go - uses: actions/setup-go@v5 + uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0 with: go-version: ${{ matrix.go-version }} From 1fd774fb29cb3602af8ffb27c253b1cec47c28c1 Mon Sep 17 00:00:00 2001 From: Paulo Gomes Date: Thu, 27 Feb 2025 00:18:00 +0000 Subject: [PATCH 6/6] build: Add OpenSSF Scorecard Signed-off-by: Paulo Gomes --- .github/workflows/scorecard.yml | 62 +++++++++++++++++++++++++++++++++ README.md | 2 +- 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/scorecard.yml diff --git a/.github/workflows/scorecard.yml b/.github/workflows/scorecard.yml new file mode 100644 index 0000000..dbffb38 --- /dev/null +++ b/.github/workflows/scorecard.yml @@ -0,0 +1,62 @@ +name: Scorecard supply-chain security +on: + # For Branch-Protection check. Only the default branch is supported. See + # https://github.com/ossf/scorecard/blob/main/docs/checks.md#branch-protection + branch_protection_rule: + # To guarantee Maintained check is occasionally updated. See + # https://github.com/ossf/scorecard/blob/main/docs/checks.md#maintained + schedule: + - cron: '20 5 * * 0' + push: + branches: [ "main" ] + +# Declare default permissions as read only. +permissions: read-all + +jobs: + analysis: + name: Scorecard analysis + runs-on: ubuntu-latest + permissions: + # Needed to upload the results to code-scanning dashboard. + security-events: write + # Needed to publish results and get a badge (see publish_results below). + id-token: write + + steps: + - name: "Checkout code" + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + with: + persist-credentials: false + + - name: "Run analysis" + uses: ossf/scorecard-action@0864cf19026789058feabb7e87baa5f140aac736 # v2.3.1 + with: + results_file: results.sarif + results_format: sarif + # (Optional) "write" PAT token. Uncomment the `repo_token` line below if: + # - you want to enable the Branch-Protection check on a *public* repository + # To create the PAT, follow the steps in https://github.com/ossf/scorecard-action?tab=readme-ov-file#authentication-with-fine-grained-pat-optional. + # repo_token: ${{ secrets.SCORECARD_TOKEN }} + + # Public repositories: + # - Publish results to OpenSSF REST API for easy access by consumers + # - Allows the repository to include the Scorecard badge. + # - See https://github.com/ossf/scorecard-action#publishing-results. + publish_results: true + + # Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF + # format to the repository Actions tab. + - name: "Upload artifact" + uses: actions/upload-artifact@97a0fba1372883ab732affbe8f94b823f91727db # v3.pre.node20 + with: + name: SARIF file + path: results.sarif + retention-days: 5 + + # Upload the results to GitHub's code scanning dashboard (optional). + # Commenting out will disable upload of results to your repo's Code Scanning dashboard + - name: "Upload to code-scanning" + uses: github/codeql-action/upload-sarif@v3 + with: + sarif_file: results.sarif diff --git a/README.md b/README.md index f1a156f..768d135 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# go-git-fixtures +# go-git-fixtures [![GoDoc](https://godoc.org/gopkg.in/go-git/go-git-fixtures.v6?status.svg)](https://pkg.go.dev/github.com/go-git/go-git-fixtures/v6) [![Test](https://github.com/go-git/go-git-fixtures/workflows/Test/badge.svg)](https://github.com/go-git/go-git-fixtures/actions?query=workflow%3ATest) [![OpenSSF Scorecard](https://api.scorecard.dev/projects/github.com/go-git/go-git-fixtures/badge)](https://scorecard.dev/viewer/?uri=github.com/go-git/go-git-fixtures) git repository fixtures used by [go-git](https://github.com/go-git/go-git)