Skip to content

Commit 192ee1a

Browse files
committed
fully based on go-billy
1 parent d6f713e commit 192ee1a

File tree

3 files changed

+19
-23
lines changed

3 files changed

+19
-23
lines changed

fixtures.go

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,21 @@ package fixtures
33
import (
44
"fmt"
55
"io"
6-
"io/ioutil"
76
"os"
87
"strings"
98

10-
"github.com/alcortesm/tgz"
119
"github.com/go-git/go-billy/v5"
1210
"github.com/go-git/go-billy/v5/osfs"
11+
"github.com/go-git/go-git-fixtures/v4/internal/tgz"
1312
"gopkg.in/check.v1"
1413
)
1514

1615
//go:generate esc -o data.go -pkg=fixtures data
1716

18-
var files = make(map[string]string)
17+
var (
18+
files = make(map[string]string)
19+
fs = osfs.New(os.TempDir())
20+
)
1921

2022
var fixtures = Fixtures{{
2123
Tags: []string{"packfile", "ofs-delta", ".git", "root-reference"},
@@ -203,17 +205,17 @@ func (f *Fixture) Is(tag string) bool {
203205
return false
204206
}
205207

206-
func (f *Fixture) file(path string) (*os.File, error) {
208+
func (f *Fixture) file(path string) (billy.File, error) {
207209
if fpath, ok := files[path]; ok {
208-
return os.Open(fpath)
210+
return fs.Open(fpath)
209211
}
210212

211213
bytes, err := FSByte(false, "/data/"+path)
212214
if err != nil {
213215
return nil, err
214216
}
215217

216-
file, err := ioutil.TempFile(os.TempDir(), "go-git-fixtures")
218+
file, err := fs.TempFile("", "go-git-fixtures")
217219
if err != nil {
218220
return nil, err
219221
}
@@ -222,32 +224,29 @@ func (f *Fixture) file(path string) (*os.File, error) {
222224
return nil, err
223225
}
224226

225-
if err := file.Sync(); err != nil {
226-
return nil, err
227-
}
228-
229-
if _, err := file.Seek(0, io.SeekStart); err != nil {
227+
if err := file.Close(); err != nil {
230228
return nil, err
231229
}
232230

233231
files[path] = file.Name()
234-
235-
return file, nil
232+
return fs.Open(file.Name())
236233
}
237234

238-
func (f *Fixture) Packfile() *os.File {
235+
func (f *Fixture) Packfile() billy.File {
239236
file, err := f.file(fmt.Sprintf("pack-%s.pack", f.PackfileHash))
240237
if err != nil {
241238
panic(err)
242239
}
240+
243241
return file
244242
}
245243

246-
func (f *Fixture) Idx() *os.File {
244+
func (f *Fixture) Idx() billy.File {
247245
file, err := f.file(fmt.Sprintf("pack-%s.idx", f.PackfileHash))
248246
if err != nil {
249247
panic(err)
250248
}
249+
251250
return file
252251
}
253252

@@ -264,12 +263,12 @@ func (f *Fixture) DotGit() billy.Filesystem {
264263
panic(err)
265264
}
266265

267-
path, err := tgz.Extract(file.Name())
266+
fs, err := tgz.Extract(fs, file.Name())
268267
if err != nil {
269268
panic(err)
270269
}
271270

272-
return osfs.New(path)
271+
return fs
273272
}
274273

275274
// EnsureIsBare overrides the config file with one where bare is true.
@@ -304,12 +303,12 @@ func (f *Fixture) Worktree() billy.Filesystem {
304303
panic(err)
305304
}
306305

307-
path, err := tgz.Extract(file.Name())
306+
fs, err := tgz.Extract(fs, file.Name())
308307
if err != nil {
309308
panic(err)
310309
}
311310

312-
return osfs.New(path)
311+
return fs
313312
}
314313

315314
type Fixtures []*Fixture
@@ -360,7 +359,7 @@ func (g Fixtures) Exclude(tag string) Fixtures {
360359
// Clean cleans all the temporal files created
361360
func Clean() error {
362361
for fname, f := range files {
363-
if err := os.Remove(f); err != nil {
362+
if err := fs.Remove(f); err != nil {
364363
return err
365364
}
366365
delete(files, fname)

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ module github.com/go-git/go-git-fixtures/v4
33
go 1.14
44

55
require (
6-
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7
76
github.com/go-git/go-billy/v5 v5.2.0
87
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c
98
)

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7 h1:uSoVVbwJiQipAclBbw+8quDsfcvFjOpI5iCf4p/cqCs=
2-
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs=
31
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
42
github.com/go-git/go-billy/v5 v5.2.0 h1:GcoouCP9J+5slw2uXAocL70z8ml4A8B/H8nEPt6CLPk=
53
github.com/go-git/go-billy/v5 v5.2.0/go.mod h1:pmpqyWchKfYfrkb/UVH4otLvyi/5gJlGI4Hb3ZqZ3W0=

0 commit comments

Comments
 (0)