Skip to content

Commit

Permalink
*: upgrade to go-billy.v3, merge
Browse files Browse the repository at this point in the history
  • Loading branch information
mcuadros committed Jun 18, 2017
1 parent bf3a920 commit abb9ec0
Show file tree
Hide file tree
Showing 31 changed files with 148 additions and 134 deletions.
3 changes: 1 addition & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ environment:
GOPATH: c:\gopath

install:
- set PATH=%GOPATH%\bin;c:\go\bin;%PATH%
- set PATH=%GOPATH%\bin;c:\go\bin;"C:\Program Files\Git\mingw64\bin";%PATH%
- go version
- go get -v -t ./...

- git config --global user.email "[email protected]"
- git config --global user.name "Travis CI

Expand Down
8 changes: 4 additions & 4 deletions common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (

"github.com/src-d/go-git-fixtures"
. "gopkg.in/check.v1"
"gopkg.in/src-d/go-billy.v2/memfs"
"gopkg.in/src-d/go-billy.v2/osfs"
"gopkg.in/src-d/go-billy.v3/memfs"
"gopkg.in/src-d/go-billy.v3/osfs"
)

func Test(t *testing.T) { TestingT(t) }
Expand Down Expand Up @@ -42,7 +42,7 @@ func (s *BaseSuite) buildBasicRepository(c *C) {
}

func (s *BaseSuite) NewRepository(f *fixtures.Fixture) *Repository {
fs := osfs.New(f.DotGit().Base())
fs := osfs.New(f.DotGit().Root())
st, err := filesystem.NewStorage(fs)
if err != nil {
panic(err)
Expand Down Expand Up @@ -94,7 +94,7 @@ func (s *BaseSuite) GetBasicLocalRepositoryURL() string {
}

func (s *BaseSuite) GetLocalRepositoryURL(f *fixtures.Fixture) string {
return f.DotGit().Base()
return f.DotGit().Root()
}

type SuiteCommon struct{}
Expand Down
2 changes: 1 addition & 1 deletion example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/storage/memory"

"gopkg.in/src-d/go-billy.v2/memfs"
"gopkg.in/src-d/go-billy.v3/memfs"
)

func ExampleClone() {
Expand Down
2 changes: 1 addition & 1 deletion plumbing/format/packfile/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package packfile_test
import (
"io"

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

"github.com/src-d/go-git-fixtures"
"gopkg.in/src-d/go-git.v4/plumbing"
Expand Down
4 changes: 2 additions & 2 deletions plumbing/transport/file/receive_pack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ func (s *ReceivePackSuite) SetUpSuite(c *C) {

func (s *ReceivePackSuite) SetUpTest(c *C) {
fixture := fixtures.Basic().One()
path := fixture.DotGit().Base()
path := fixture.DotGit().Root()
s.Endpoint = prepareRepo(c, path)

fixture = fixtures.ByTag("empty").One()
path = fixture.DotGit().Base()
path = fixture.DotGit().Root()
s.EmptyEndpoint = prepareRepo(c, path)

s.NonExistentEndpoint = prepareRepo(c, "/non-existent")
Expand Down
4 changes: 2 additions & 2 deletions plumbing/transport/file/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ func (s *ServerSuite) SetUpSuite(c *C) {
s.RemoteName = "test"

fixture := fixtures.Basic().One()
s.SrcPath = fixture.DotGit().Base()
s.SrcPath = fixture.DotGit().Root()

fixture = fixtures.ByTag("empty").One()
s.DstPath = fixture.DotGit().Base()
s.DstPath = fixture.DotGit().Root()

cmd := exec.Command("git", "remote", "add", s.RemoteName, s.DstPath)
cmd.Dir = s.SrcPath
Expand Down
7 changes: 4 additions & 3 deletions plumbing/transport/file/upload_pack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ func (s *UploadPackSuite) SetUpSuite(c *C) {
s.UploadPackSuite.Client = DefaultClient

fixture := fixtures.Basic().One()
path := fixture.DotGit().Base()
path := fixture.DotGit().Root()
ep, err := transport.NewEndpoint(path)
c.Assert(err, IsNil)
s.Endpoint = ep

fixture = fixtures.ByTag("empty").One()
path = fixture.DotGit().Base()
path = fixture.DotGit().Root()
ep, err = transport.NewEndpoint(path)
c.Assert(err, IsNil)
s.EmptyEndpoint = ep
Expand Down Expand Up @@ -74,6 +74,7 @@ func (s *UploadPackSuite) TestNonExistentCommand(c *C) {
cmd := "/non-existent-git"
client := NewClient(cmd, cmd)
session, err := client.NewUploadPackSession(s.Endpoint, s.EmptyAuth)
c.Assert(err, ErrorMatches, ".*no such file or directory.*")
// Error message is OS-dependant, so do a broad check
c.Assert(err, ErrorMatches, ".*file.*")
c.Assert(session, IsNil)
}
4 changes: 2 additions & 2 deletions plumbing/transport/git/receive_pack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (s *ReceivePackSuite) SetUpTest(c *C) {
err = os.MkdirAll(interpolatedBase, 0755)
c.Assert(err, IsNil)

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

dotgit = fixtures.ByTag("empty").One().DotGit().Base()
dotgit = fixtures.ByTag("empty").One().DotGit().Root()
prepareRepo(c, dotgit)
err = os.Rename(dotgit, filepath.Join(interpolatedBase, "empty.git"))
c.Assert(err, IsNil)
Expand Down
10 changes: 7 additions & 3 deletions plumbing/transport/server/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"gopkg.in/src-d/go-git.v4/plumbing/transport"
"gopkg.in/src-d/go-git.v4/storage/filesystem"

"gopkg.in/src-d/go-billy.v2"
"gopkg.in/src-d/go-billy.v2/osfs"
"gopkg.in/src-d/go-billy.v3"
"gopkg.in/src-d/go-billy.v3/osfs"
)

// DefaultLoader is a filesystem loader ignoring host and resolving paths to /.
Expand Down Expand Up @@ -34,7 +34,11 @@ func NewFilesystemLoader(base billy.Filesystem) Loader {
// storer for it. Returns transport.ErrRepositoryNotFound if a repository does
// not exist in the given path.
func (l *fsLoader) Load(ep transport.Endpoint) (storer.Storer, error) {
fs := l.base.Dir(ep.Path())
fs, err := l.base.Chroot(ep.Path())
if err != nil {
return nil, err
}

if _, err := fs.Stat("config"); err != nil {
return nil, transport.ErrRepositoryNotFound
}
Expand Down
22 changes: 8 additions & 14 deletions plumbing/transport/server/server_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package server_test

import (
"fmt"
"testing"

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

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

const inprocScheme = "inproc"

type BaseSuite struct {
fixtures.Suite
loader server.MapLoader
Expand All @@ -29,15 +26,15 @@ func (s *BaseSuite) SetUpSuite(c *C) {
s.Suite.SetUpSuite(c)
s.loader = server.MapLoader{}
s.client = server.NewServer(s.loader)
s.clientBackup = client.Protocols[inprocScheme]
client.Protocols[inprocScheme] = s.client
s.clientBackup = client.Protocols["file"]
client.Protocols["file"] = s.client
}

func (s *BaseSuite) TearDownSuite(c *C) {
if s.clientBackup == nil {
delete(client.Protocols, inprocScheme)
delete(client.Protocols, "file")
} else {
client.Protocols[inprocScheme] = s.clientBackup
client.Protocols["file"] = s.clientBackup
}
}

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

f := fixtures.Basic().One()
fs := f.DotGit()
path := fs.Base()
url := fmt.Sprintf("%s://%s", inprocScheme, path)
ep, err := transport.NewEndpoint(url)
path := fs.Root()
ep, err := transport.NewEndpoint(path)
c.Assert(err, IsNil)
*basic = ep
sto, err := filesystem.NewStorage(fs)
c.Assert(err, IsNil)
s.loader[ep.String()] = sto

path = "/empty.git"
url = fmt.Sprintf("%s://%s", inprocScheme, path)
ep, err = transport.NewEndpoint(url)
ep, err = transport.NewEndpoint(path)
c.Assert(err, IsNil)
*empty = ep
s.loader[ep.String()] = memory.NewStorage()

path = "/non-existent.git"
url = fmt.Sprintf("%s://%s", inprocScheme, path)
ep, err = transport.NewEndpoint(url)
ep, err = transport.NewEndpoint(path)
c.Assert(err, IsNil)
*nonExistent = ep
}
2 changes: 1 addition & 1 deletion references_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ func (s *ReferencesSuite) TestObjectNotFoundError(c *C) {
h1 := plumbing.NewHash("af2d6a6954d532f8ffb47615169c8fdf9d383a1a")
hParent := plumbing.NewHash("1669dce138d9b841a518c64b10914d88f5e488ea")

url := fixtures.ByURL("https://github.com/git-fixtures/basic.git").One().DotGit().Base()
url := fixtures.ByURL("https://github.com/git-fixtures/basic.git").One().DotGit().Root()
storer := memory.NewStorage()
r, err := Clone(storer, nil, &CloneOptions{
URL: url,
Expand Down
14 changes: 7 additions & 7 deletions remote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"gopkg.in/src-d/go-git.v4/storage/memory"

. "gopkg.in/check.v1"
"gopkg.in/src-d/go-billy.v2/osfs"
"gopkg.in/src-d/go-billy.v3/osfs"
)

type RemoteSuite struct {
Expand Down Expand Up @@ -214,7 +214,7 @@ func (s *RemoteSuite) TestPushToEmptyRepository(c *C) {
c.Assert(err, IsNil)

dstFs := fixtures.ByTag("empty").One().DotGit()
url := dstFs.Base()
url := dstFs.Root()

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

dstFs := fixtures.ByTag("empty").One().DotGit()
url := dstFs.Base()
url := dstFs.Root()

r := newRemote(sto, &config.RemoteConfig{
Name: DefaultRemoteName,
Expand Down Expand Up @@ -297,7 +297,7 @@ func (s *RemoteSuite) TestPushNoErrAlreadyUpToDate(c *C) {
f := fixtures.Basic().One()
sto, err := filesystem.NewStorage(f.DotGit())
c.Assert(err, IsNil)
url := f.DotGit().Base()
url := f.DotGit().Root()
r := newRemote(sto, &config.RemoteConfig{
Name: DefaultRemoteName,
URL: url,
Expand All @@ -319,7 +319,7 @@ func (s *RemoteSuite) TestPushRejectNonFastForward(c *C) {
dstSto, err := filesystem.NewStorage(dstFs)
c.Assert(err, IsNil)

url := dstFs.Base()
url := dstFs.Root()
r := newRemote(sto, &config.RemoteConfig{
Name: DefaultRemoteName,
URL: url,
Expand Down Expand Up @@ -348,7 +348,7 @@ func (s *RemoteSuite) TestPushForce(c *C) {
dstSto, err := filesystem.NewStorage(dstFs)
c.Assert(err, IsNil)

url := dstFs.Base()
url := dstFs.Root()
r := newRemote(sto, &config.RemoteConfig{
Name: DefaultRemoteName,
URL: url,
Expand Down Expand Up @@ -377,7 +377,7 @@ func (s *RemoteSuite) TestPushNewReference(c *C) {
dstSto, err := filesystem.NewStorage(dstFs)
c.Assert(err, IsNil)

url := dstFs.Base()
url := dstFs.Root()
r := newRemote(sto, &config.RemoteConfig{
Name: DefaultRemoteName,
URL: url,
Expand Down
32 changes: 14 additions & 18 deletions repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (
"gopkg.in/src-d/go-git.v4/storage/filesystem"
"gopkg.in/src-d/go-git.v4/utils/ioutil"

"gopkg.in/src-d/go-billy.v2"
"gopkg.in/src-d/go-billy.v2/osfs"
"gopkg.in/src-d/go-billy.v3"
"gopkg.in/src-d/go-billy.v3/osfs"
)

var (
Expand Down Expand Up @@ -92,11 +92,6 @@ func setWorktreeAndStoragePaths(r *Repository, worktree billy.Filesystem) error
return nil
}

_, isOS := fs.Filesystem().(*osfs.OS)
if !isOS {
return nil
}

if err := createDotGitFile(worktree, fs.Filesystem()); err != nil {
return err
}
Expand All @@ -105,9 +100,9 @@ func setWorktreeAndStoragePaths(r *Repository, worktree billy.Filesystem) error
}

func createDotGitFile(worktree, storage billy.Filesystem) error {
path, err := filepath.Rel(worktree.Base(), storage.Base())
path, err := filepath.Rel(worktree.Root(), storage.Root())
if err != nil {
path = storage.Base()
path = storage.Root()
}

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

func setConfigWorktree(r *Repository, worktree, storage billy.Filesystem) error {
path, err := filepath.Rel(storage.Base(), worktree.Base())
path, err := filepath.Rel(storage.Root(), worktree.Root())
if err != nil {
path = worktree.Base()
path = worktree.Root()
}

if path == ".." {
Expand Down Expand Up @@ -194,7 +189,7 @@ func PlainInit(path string, isBare bool) (*Repository, error) {
dot = osfs.New(path)
} else {
wt = osfs.New(path)
dot = wt.Dir(".git")
dot, _ = wt.Chroot(".git")
}

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

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

if fi.IsDir() {
return fs.Dir(".git"), fs, nil
dot, err = fs.Chroot(".git")
return dot, fs, err
}

dot, err = dotGitFileToFilesystem(fs)
dot, err = dotGitFileToOSFilesystem(path, fs)
if err != nil {
return nil, nil, err
}

return dot, fs, nil
}

func dotGitFileToFilesystem(fs billy.Filesystem) (billy.Filesystem, error) {
func dotGitFileToOSFilesystem(path string, fs billy.Filesystem) (billy.Filesystem, error) {
var err error

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

return fs.Dir(gitdir), err
return osfs.New(fs.Join(path, gitdir)), nil
}

// PlainClone a repository into the path with the given options, isBare defines
Expand Down
Loading

0 comments on commit abb9ec0

Please sign in to comment.