Skip to content

Commit abb9ec0

Browse files
committed
*: upgrade to go-billy.v3, merge
1 parent bf3a920 commit abb9ec0

31 files changed

+148
-134
lines changed

appveyor.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ environment:
1111
GOPATH: c:\gopath
1212

1313
install:
14-
- set PATH=%GOPATH%\bin;c:\go\bin;%PATH%
14+
- set PATH=%GOPATH%\bin;c:\go\bin;"C:\Program Files\Git\mingw64\bin";%PATH%
1515
- go version
1616
- go get -v -t ./...
17-
1817
- git config --global user.email "[email protected]"
1918
- git config --global user.name "Travis CI
2019

common_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111

1212
"github.com/src-d/go-git-fixtures"
1313
. "gopkg.in/check.v1"
14-
"gopkg.in/src-d/go-billy.v2/memfs"
15-
"gopkg.in/src-d/go-billy.v2/osfs"
14+
"gopkg.in/src-d/go-billy.v3/memfs"
15+
"gopkg.in/src-d/go-billy.v3/osfs"
1616
)
1717

1818
func Test(t *testing.T) { TestingT(t) }
@@ -42,7 +42,7 @@ func (s *BaseSuite) buildBasicRepository(c *C) {
4242
}
4343

4444
func (s *BaseSuite) NewRepository(f *fixtures.Fixture) *Repository {
45-
fs := osfs.New(f.DotGit().Base())
45+
fs := osfs.New(f.DotGit().Root())
4646
st, err := filesystem.NewStorage(fs)
4747
if err != nil {
4848
panic(err)
@@ -94,7 +94,7 @@ func (s *BaseSuite) GetBasicLocalRepositoryURL() string {
9494
}
9595

9696
func (s *BaseSuite) GetLocalRepositoryURL(f *fixtures.Fixture) string {
97-
return f.DotGit().Base()
97+
return f.DotGit().Root()
9898
}
9999

100100
type SuiteCommon struct{}

example_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"gopkg.in/src-d/go-git.v4/plumbing"
1414
"gopkg.in/src-d/go-git.v4/storage/memory"
1515

16-
"gopkg.in/src-d/go-billy.v2/memfs"
16+
"gopkg.in/src-d/go-billy.v3/memfs"
1717
)
1818

1919
func ExampleClone() {

plumbing/format/packfile/decoder_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package packfile_test
33
import (
44
"io"
55

6-
"gopkg.in/src-d/go-billy.v2/memfs"
6+
"gopkg.in/src-d/go-billy.v3/memfs"
77

88
"github.com/src-d/go-git-fixtures"
99
"gopkg.in/src-d/go-git.v4/plumbing"

plumbing/transport/file/receive_pack_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ func (s *ReceivePackSuite) SetUpSuite(c *C) {
2323

2424
func (s *ReceivePackSuite) SetUpTest(c *C) {
2525
fixture := fixtures.Basic().One()
26-
path := fixture.DotGit().Base()
26+
path := fixture.DotGit().Root()
2727
s.Endpoint = prepareRepo(c, path)
2828

2929
fixture = fixtures.ByTag("empty").One()
30-
path = fixture.DotGit().Base()
30+
path = fixture.DotGit().Root()
3131
s.EmptyEndpoint = prepareRepo(c, path)
3232

3333
s.NonExistentEndpoint = prepareRepo(c, "/non-existent")

plumbing/transport/file/server_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ func (s *ServerSuite) SetUpSuite(c *C) {
2424
s.RemoteName = "test"
2525

2626
fixture := fixtures.Basic().One()
27-
s.SrcPath = fixture.DotGit().Base()
27+
s.SrcPath = fixture.DotGit().Root()
2828

2929
fixture = fixtures.ByTag("empty").One()
30-
s.DstPath = fixture.DotGit().Base()
30+
s.DstPath = fixture.DotGit().Root()
3131

3232
cmd := exec.Command("git", "remote", "add", s.RemoteName, s.DstPath)
3333
cmd.Dir = s.SrcPath

plumbing/transport/file/upload_pack_test.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ func (s *UploadPackSuite) SetUpSuite(c *C) {
2424
s.UploadPackSuite.Client = DefaultClient
2525

2626
fixture := fixtures.Basic().One()
27-
path := fixture.DotGit().Base()
27+
path := fixture.DotGit().Root()
2828
ep, err := transport.NewEndpoint(path)
2929
c.Assert(err, IsNil)
3030
s.Endpoint = ep
3131

3232
fixture = fixtures.ByTag("empty").One()
33-
path = fixture.DotGit().Base()
33+
path = fixture.DotGit().Root()
3434
ep, err = transport.NewEndpoint(path)
3535
c.Assert(err, IsNil)
3636
s.EmptyEndpoint = ep
@@ -74,6 +74,7 @@ func (s *UploadPackSuite) TestNonExistentCommand(c *C) {
7474
cmd := "/non-existent-git"
7575
client := NewClient(cmd, cmd)
7676
session, err := client.NewUploadPackSession(s.Endpoint, s.EmptyAuth)
77-
c.Assert(err, ErrorMatches, ".*no such file or directory.*")
77+
// Error message is OS-dependant, so do a broad check
78+
c.Assert(err, ErrorMatches, ".*file.*")
7879
c.Assert(session, IsNil)
7980
}

plumbing/transport/git/receive_pack_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (s *ReceivePackSuite) SetUpTest(c *C) {
4343
err = os.MkdirAll(interpolatedBase, 0755)
4444
c.Assert(err, IsNil)
4545

46-
dotgit := fixtures.Basic().One().DotGit().Base()
46+
dotgit := fixtures.Basic().One().DotGit().Root()
4747
prepareRepo(c, dotgit)
4848
err = os.Rename(dotgit, filepath.Join(interpolatedBase, "basic.git"))
4949
c.Assert(err, IsNil)
@@ -52,7 +52,7 @@ func (s *ReceivePackSuite) SetUpTest(c *C) {
5252
c.Assert(err, IsNil)
5353
s.ReceivePackSuite.Endpoint = ep
5454

55-
dotgit = fixtures.ByTag("empty").One().DotGit().Base()
55+
dotgit = fixtures.ByTag("empty").One().DotGit().Root()
5656
prepareRepo(c, dotgit)
5757
err = os.Rename(dotgit, filepath.Join(interpolatedBase, "empty.git"))
5858
c.Assert(err, IsNil)

plumbing/transport/server/loader.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"gopkg.in/src-d/go-git.v4/plumbing/transport"
66
"gopkg.in/src-d/go-git.v4/storage/filesystem"
77

8-
"gopkg.in/src-d/go-billy.v2"
9-
"gopkg.in/src-d/go-billy.v2/osfs"
8+
"gopkg.in/src-d/go-billy.v3"
9+
"gopkg.in/src-d/go-billy.v3/osfs"
1010
)
1111

1212
// DefaultLoader is a filesystem loader ignoring host and resolving paths to /.
@@ -34,7 +34,11 @@ func NewFilesystemLoader(base billy.Filesystem) Loader {
3434
// storer for it. Returns transport.ErrRepositoryNotFound if a repository does
3535
// not exist in the given path.
3636
func (l *fsLoader) Load(ep transport.Endpoint) (storer.Storer, error) {
37-
fs := l.base.Dir(ep.Path())
37+
fs, err := l.base.Chroot(ep.Path())
38+
if err != nil {
39+
return nil, err
40+
}
41+
3842
if _, err := fs.Stat("config"); err != nil {
3943
return nil, transport.ErrRepositoryNotFound
4044
}
+8-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package server_test
22

33
import (
4-
"fmt"
54
"testing"
65

76
"github.com/src-d/go-git-fixtures"
@@ -16,8 +15,6 @@ import (
1615

1716
func Test(t *testing.T) { TestingT(t) }
1817

19-
const inprocScheme = "inproc"
20-
2118
type BaseSuite struct {
2219
fixtures.Suite
2320
loader server.MapLoader
@@ -29,15 +26,15 @@ func (s *BaseSuite) SetUpSuite(c *C) {
2926
s.Suite.SetUpSuite(c)
3027
s.loader = server.MapLoader{}
3128
s.client = server.NewServer(s.loader)
32-
s.clientBackup = client.Protocols[inprocScheme]
33-
client.Protocols[inprocScheme] = s.client
29+
s.clientBackup = client.Protocols["file"]
30+
client.Protocols["file"] = s.client
3431
}
3532

3633
func (s *BaseSuite) TearDownSuite(c *C) {
3734
if s.clientBackup == nil {
38-
delete(client.Protocols, inprocScheme)
35+
delete(client.Protocols, "file")
3936
} else {
40-
client.Protocols[inprocScheme] = s.clientBackup
37+
client.Protocols["file"] = s.clientBackup
4138
}
4239
}
4340

@@ -46,25 +43,22 @@ func (s *BaseSuite) prepareRepositories(c *C, basic *transport.Endpoint,
4643

4744
f := fixtures.Basic().One()
4845
fs := f.DotGit()
49-
path := fs.Base()
50-
url := fmt.Sprintf("%s://%s", inprocScheme, path)
51-
ep, err := transport.NewEndpoint(url)
46+
path := fs.Root()
47+
ep, err := transport.NewEndpoint(path)
5248
c.Assert(err, IsNil)
5349
*basic = ep
5450
sto, err := filesystem.NewStorage(fs)
5551
c.Assert(err, IsNil)
5652
s.loader[ep.String()] = sto
5753

5854
path = "/empty.git"
59-
url = fmt.Sprintf("%s://%s", inprocScheme, path)
60-
ep, err = transport.NewEndpoint(url)
55+
ep, err = transport.NewEndpoint(path)
6156
c.Assert(err, IsNil)
6257
*empty = ep
6358
s.loader[ep.String()] = memory.NewStorage()
6459

6560
path = "/non-existent.git"
66-
url = fmt.Sprintf("%s://%s", inprocScheme, path)
67-
ep, err = transport.NewEndpoint(url)
61+
ep, err = transport.NewEndpoint(path)
6862
c.Assert(err, IsNil)
6963
*nonExistent = ep
7064
}

references_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ func (s *ReferencesSuite) TestObjectNotFoundError(c *C) {
292292
h1 := plumbing.NewHash("af2d6a6954d532f8ffb47615169c8fdf9d383a1a")
293293
hParent := plumbing.NewHash("1669dce138d9b841a518c64b10914d88f5e488ea")
294294

295-
url := fixtures.ByURL("https://github.com/git-fixtures/basic.git").One().DotGit().Base()
295+
url := fixtures.ByURL("https://github.com/git-fixtures/basic.git").One().DotGit().Root()
296296
storer := memory.NewStorage()
297297
r, err := Clone(storer, nil, &CloneOptions{
298298
URL: url,

remote_test.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"gopkg.in/src-d/go-git.v4/storage/memory"
1616

1717
. "gopkg.in/check.v1"
18-
"gopkg.in/src-d/go-billy.v2/osfs"
18+
"gopkg.in/src-d/go-billy.v3/osfs"
1919
)
2020

2121
type RemoteSuite struct {
@@ -214,7 +214,7 @@ func (s *RemoteSuite) TestPushToEmptyRepository(c *C) {
214214
c.Assert(err, IsNil)
215215

216216
dstFs := fixtures.ByTag("empty").One().DotGit()
217-
url := dstFs.Base()
217+
url := dstFs.Root()
218218

219219
r := newRemote(sto, &config.RemoteConfig{
220220
Name: DefaultRemoteName,
@@ -254,7 +254,7 @@ func (s *RemoteSuite) TestPushTags(c *C) {
254254
c.Assert(err, IsNil)
255255

256256
dstFs := fixtures.ByTag("empty").One().DotGit()
257-
url := dstFs.Base()
257+
url := dstFs.Root()
258258

259259
r := newRemote(sto, &config.RemoteConfig{
260260
Name: DefaultRemoteName,
@@ -297,7 +297,7 @@ func (s *RemoteSuite) TestPushNoErrAlreadyUpToDate(c *C) {
297297
f := fixtures.Basic().One()
298298
sto, err := filesystem.NewStorage(f.DotGit())
299299
c.Assert(err, IsNil)
300-
url := f.DotGit().Base()
300+
url := f.DotGit().Root()
301301
r := newRemote(sto, &config.RemoteConfig{
302302
Name: DefaultRemoteName,
303303
URL: url,
@@ -319,7 +319,7 @@ func (s *RemoteSuite) TestPushRejectNonFastForward(c *C) {
319319
dstSto, err := filesystem.NewStorage(dstFs)
320320
c.Assert(err, IsNil)
321321

322-
url := dstFs.Base()
322+
url := dstFs.Root()
323323
r := newRemote(sto, &config.RemoteConfig{
324324
Name: DefaultRemoteName,
325325
URL: url,
@@ -348,7 +348,7 @@ func (s *RemoteSuite) TestPushForce(c *C) {
348348
dstSto, err := filesystem.NewStorage(dstFs)
349349
c.Assert(err, IsNil)
350350

351-
url := dstFs.Base()
351+
url := dstFs.Root()
352352
r := newRemote(sto, &config.RemoteConfig{
353353
Name: DefaultRemoteName,
354354
URL: url,
@@ -377,7 +377,7 @@ func (s *RemoteSuite) TestPushNewReference(c *C) {
377377
dstSto, err := filesystem.NewStorage(dstFs)
378378
c.Assert(err, IsNil)
379379

380-
url := dstFs.Base()
380+
url := dstFs.Root()
381381
r := newRemote(sto, &config.RemoteConfig{
382382
Name: DefaultRemoteName,
383383
URL: url,

repository.go

+14-18
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import (
1717
"gopkg.in/src-d/go-git.v4/storage/filesystem"
1818
"gopkg.in/src-d/go-git.v4/utils/ioutil"
1919

20-
"gopkg.in/src-d/go-billy.v2"
21-
"gopkg.in/src-d/go-billy.v2/osfs"
20+
"gopkg.in/src-d/go-billy.v3"
21+
"gopkg.in/src-d/go-billy.v3/osfs"
2222
)
2323

2424
var (
@@ -92,11 +92,6 @@ func setWorktreeAndStoragePaths(r *Repository, worktree billy.Filesystem) error
9292
return nil
9393
}
9494

95-
_, isOS := fs.Filesystem().(*osfs.OS)
96-
if !isOS {
97-
return nil
98-
}
99-
10095
if err := createDotGitFile(worktree, fs.Filesystem()); err != nil {
10196
return err
10297
}
@@ -105,9 +100,9 @@ func setWorktreeAndStoragePaths(r *Repository, worktree billy.Filesystem) error
105100
}
106101

107102
func createDotGitFile(worktree, storage billy.Filesystem) error {
108-
path, err := filepath.Rel(worktree.Base(), storage.Base())
103+
path, err := filepath.Rel(worktree.Root(), storage.Root())
109104
if err != nil {
110-
path = storage.Base()
105+
path = storage.Root()
111106
}
112107

113108
if path == ".git" {
@@ -126,9 +121,9 @@ func createDotGitFile(worktree, storage billy.Filesystem) error {
126121
}
127122

128123
func setConfigWorktree(r *Repository, worktree, storage billy.Filesystem) error {
129-
path, err := filepath.Rel(storage.Base(), worktree.Base())
124+
path, err := filepath.Rel(storage.Root(), worktree.Root())
130125
if err != nil {
131-
path = worktree.Base()
126+
path = worktree.Root()
132127
}
133128

134129
if path == ".." {
@@ -194,7 +189,7 @@ func PlainInit(path string, isBare bool) (*Repository, error) {
194189
dot = osfs.New(path)
195190
} else {
196191
wt = osfs.New(path)
197-
dot = wt.Dir(".git")
192+
dot, _ = wt.Chroot(".git")
198193
}
199194

200195
s, err := filesystem.NewStorage(dot)
@@ -209,7 +204,7 @@ func PlainInit(path string, isBare bool) (*Repository, error) {
209204
// repository is bare or a normal one. If the path doesn't contain a valid
210205
// repository ErrRepositoryNotExists is returned
211206
func PlainOpen(path string) (*Repository, error) {
212-
dot, wt, err := dotGitToFilesystems(path)
207+
dot, wt, err := dotGitToOSFilesystems(path)
213208
if err != nil {
214209
return nil, err
215210
}
@@ -230,7 +225,7 @@ func PlainOpen(path string) (*Repository, error) {
230225
return Open(s, wt)
231226
}
232227

233-
func dotGitToFilesystems(path string) (dot, wt billy.Filesystem, err error) {
228+
func dotGitToOSFilesystems(path string) (dot, wt billy.Filesystem, err error) {
234229
fs := osfs.New(path)
235230
fi, err := fs.Stat(".git")
236231
if err != nil {
@@ -242,18 +237,19 @@ func dotGitToFilesystems(path string) (dot, wt billy.Filesystem, err error) {
242237
}
243238

244239
if fi.IsDir() {
245-
return fs.Dir(".git"), fs, nil
240+
dot, err = fs.Chroot(".git")
241+
return dot, fs, err
246242
}
247243

248-
dot, err = dotGitFileToFilesystem(fs)
244+
dot, err = dotGitFileToOSFilesystem(path, fs)
249245
if err != nil {
250246
return nil, nil, err
251247
}
252248

253249
return dot, fs, nil
254250
}
255251

256-
func dotGitFileToFilesystem(fs billy.Filesystem) (billy.Filesystem, error) {
252+
func dotGitFileToOSFilesystem(path string, fs billy.Filesystem) (billy.Filesystem, error) {
257253
var err error
258254

259255
f, err := fs.Open(".git")
@@ -279,7 +275,7 @@ func dotGitFileToFilesystem(fs billy.Filesystem) (billy.Filesystem, error) {
279275
return osfs.New(gitdir), nil
280276
}
281277

282-
return fs.Dir(gitdir), err
278+
return osfs.New(fs.Join(path, gitdir)), nil
283279
}
284280

285281
// PlainClone a repository into the path with the given options, isBare defines

0 commit comments

Comments
 (0)