aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--appveyor.yml3
-rw-r--r--common_test.go8
-rw-r--r--example_test.go2
-rw-r--r--plumbing/format/idxfile/decoder_test.go3
-rw-r--r--plumbing/format/idxfile/encoder_test.go3
-rw-r--r--plumbing/format/packfile/decoder_test.go2
-rw-r--r--plumbing/object/commit_walker.go8
-rw-r--r--plumbing/object/commit_walker_test.go4
-rw-r--r--plumbing/revlist/revlist.go2
-rw-r--r--plumbing/storer/storer.go2
-rw-r--r--plumbing/transport/file/client.go17
-rw-r--r--plumbing/transport/file/receive_pack_test.go4
-rw-r--r--plumbing/transport/file/server_test.go4
-rw-r--r--plumbing/transport/file/upload_pack_test.go7
-rw-r--r--plumbing/transport/git/common.go10
-rw-r--r--plumbing/transport/git/receive_pack_test.go140
-rw-r--r--plumbing/transport/internal/common/common.go50
-rw-r--r--plumbing/transport/server/loader.go10
-rw-r--r--plumbing/transport/server/server_test.go22
-rw-r--r--plumbing/transport/test/receive_pack.go9
-rw-r--r--references_test.go2
-rw-r--r--remote.go4
-rw-r--r--remote_test.go14
-rw-r--r--repository.go38
-rw-r--r--repository_test.go27
-rw-r--r--storage/filesystem/config_test.go2
-rw-r--r--storage/filesystem/internal/dotgit/dotgit.go25
-rw-r--r--storage/filesystem/internal/dotgit/dotgit_test.go27
-rw-r--r--storage/filesystem/internal/dotgit/writers.go10
-rw-r--r--storage/filesystem/internal/dotgit/writers_test.go2
-rw-r--r--storage/filesystem/module.go7
-rw-r--r--storage/filesystem/object.go2
-rw-r--r--storage/filesystem/storage.go6
-rw-r--r--storage/filesystem/storage_test.go4
-rw-r--r--submodule.go12
-rw-r--r--submodule_test.go5
-rw-r--r--utils/merkletrie/filesystem/node.go6
-rw-r--r--utils/merkletrie/filesystem/node_test.go4
-rw-r--r--worktree.go5
-rw-r--r--worktree_commit.go2
-rw-r--r--worktree_commit_test.go12
-rw-r--r--worktree_test.go14
42 files changed, 353 insertions, 187 deletions
diff --git a/appveyor.yml b/appveyor.yml
index f36ebe7..160616b 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -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 "travis@example.com"
- git config --global user.name "Travis CI
diff --git a/common_test.go b/common_test.go
index e1a2a0f..3f5364c 100644
--- a/common_test.go
+++ b/common_test.go
@@ -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) }
@@ -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)
@@ -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{}
diff --git a/example_test.go b/example_test.go
index abcbec7..585b38a 100644
--- a/example_test.go
+++ b/example_test.go
@@ -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() {
diff --git a/plumbing/format/idxfile/decoder_test.go b/plumbing/format/idxfile/decoder_test.go
index 27aa59b..609f4e3 100644
--- a/plumbing/format/idxfile/decoder_test.go
+++ b/plumbing/format/idxfile/decoder_test.go
@@ -5,10 +5,11 @@ import (
"fmt"
"testing"
- . "gopkg.in/check.v1"
"github.com/src-d/go-git-fixtures"
"gopkg.in/src-d/go-git.v4/plumbing/format/packfile"
"gopkg.in/src-d/go-git.v4/storage/memory"
+
+ . "gopkg.in/check.v1"
)
func Test(t *testing.T) { TestingT(t) }
diff --git a/plumbing/format/idxfile/encoder_test.go b/plumbing/format/idxfile/encoder_test.go
index fab87b3..1fc4e9c 100644
--- a/plumbing/format/idxfile/encoder_test.go
+++ b/plumbing/format/idxfile/encoder_test.go
@@ -4,9 +4,10 @@ import (
"bytes"
"io/ioutil"
- . "gopkg.in/check.v1"
"github.com/src-d/go-git-fixtures"
"gopkg.in/src-d/go-git.v4/plumbing"
+
+ . "gopkg.in/check.v1"
)
func (s *IdxfileSuite) TestEncode(c *C) {
diff --git a/plumbing/format/packfile/decoder_test.go b/plumbing/format/packfile/decoder_test.go
index f081fd7..f1e2ed7 100644
--- a/plumbing/format/packfile/decoder_test.go
+++ b/plumbing/format/packfile/decoder_test.go
@@ -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"
diff --git a/plumbing/object/commit_walker.go b/plumbing/object/commit_walker.go
index 3316fab..8d2c6e8 100644
--- a/plumbing/object/commit_walker.go
+++ b/plumbing/object/commit_walker.go
@@ -13,13 +13,13 @@ type commitPreIterator struct {
start *Commit
}
-// NewCommitPreIterator returns a CommitIter that walks the commit history,
+// NewCommitPreorderIter returns a CommitIter that walks the commit history,
// starting at the given commit and visiting its parents in pre-order.
// The given callback will be called for each visited commit. Each commit will
// be visited only once. If the callback returns an error, walking will stop
// and will return the error. Other errors might be returned if the history
// cannot be traversed (e.g. missing objects).
-func NewCommitPreIterator(c *Commit) CommitIter {
+func NewCommitPreorderIter(c *Commit) CommitIter {
return &commitPreIterator{
seen: make(map[plumbing.Hash]bool),
stack: make([]CommitIter, 0),
@@ -94,12 +94,12 @@ type commitPostIterator struct {
seen map[plumbing.Hash]bool
}
-// NewCommitPostIterator returns a CommitIter that walks the commit
+// NewCommitPostorderIter returns a CommitIter that walks the commit
// history like WalkCommitHistory but in post-order. This means that after
// walking a merge commit, the merged commit will be walked before the base
// it was merged on. This can be useful if you wish to see the history in
// chronological order.
-func NewCommitPostIterator(c *Commit) CommitIter {
+func NewCommitPostorderIter(c *Commit) CommitIter {
return &commitPostIterator{
stack: []*Commit{c},
seen: make(map[plumbing.Hash]bool),
diff --git a/plumbing/object/commit_walker_test.go b/plumbing/object/commit_walker_test.go
index 7d04bce..2a03057 100644
--- a/plumbing/object/commit_walker_test.go
+++ b/plumbing/object/commit_walker_test.go
@@ -12,7 +12,7 @@ func (s *CommitWalkerSuite) TestCommitPreIterator(c *C) {
commit := s.commit(c, s.Fixture.Head)
var commits []*Commit
- wIter := NewCommitPreIterator(commit)
+ wIter := NewCommitPreorderIter(commit)
wIter.ForEach(func(c *Commit) error {
commits = append(commits, c)
return nil
@@ -39,7 +39,7 @@ func (s *CommitWalkerSuite) TestCommitPostIterator(c *C) {
commit := s.commit(c, s.Fixture.Head)
var commits []*Commit
- wIter := NewCommitPostIterator(commit)
+ wIter := NewCommitPostorderIter(commit)
wIter.ForEach(func(c *Commit) error {
commits = append(commits, c)
return nil
diff --git a/plumbing/revlist/revlist.go b/plumbing/revlist/revlist.go
index fbd1bd9..3e02184 100644
--- a/plumbing/revlist/revlist.go
+++ b/plumbing/revlist/revlist.go
@@ -82,7 +82,7 @@ func reachableObjects(
commit *object.Commit,
seen map[plumbing.Hash]bool,
cb func(h plumbing.Hash)) error {
- return object.NewCommitPreIterator(commit).
+ return object.NewCommitPreorderIter(commit).
ForEach(func(commit *object.Commit) error {
if seen[commit.Hash] {
return nil
diff --git a/plumbing/storer/storer.go b/plumbing/storer/storer.go
index 863070d..c7bc65a 100644
--- a/plumbing/storer/storer.go
+++ b/plumbing/storer/storer.go
@@ -8,7 +8,7 @@ type Storer interface {
// Initializer should be implemented by storers that require to perform any
// operation when creating a new repository (i.e. git init).
-type Initializer interface{
+type Initializer interface {
// Init performs initialization of the storer and returns the error, if
// any.
Init() error
diff --git a/plumbing/transport/file/client.go b/plumbing/transport/file/client.go
index d2a57d0..a199b01 100644
--- a/plumbing/transport/file/client.go
+++ b/plumbing/transport/file/client.go
@@ -3,6 +3,7 @@ package file
import (
"io"
+ "os"
"os/exec"
"gopkg.in/src-d/go-git.v4/plumbing/transport"
@@ -71,10 +72,16 @@ func (c *command) Close() error {
return nil
}
- return c.cmd.Process.Kill()
-}
-
-func (c *command) Wait() error {
defer func() { c.closed = true }()
- return c.cmd.Wait()
+ err := c.cmd.Wait()
+ if _, ok := err.(*os.PathError); ok {
+ return nil
+ }
+
+ // When a repository does not exist, the command exits with code 128.
+ if _, ok := err.(*exec.ExitError); ok {
+ return nil
+ }
+
+ return err
}
diff --git a/plumbing/transport/file/receive_pack_test.go b/plumbing/transport/file/receive_pack_test.go
index 5bbad44..ab21aea 100644
--- a/plumbing/transport/file/receive_pack_test.go
+++ b/plumbing/transport/file/receive_pack_test.go
@@ -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")
diff --git a/plumbing/transport/file/server_test.go b/plumbing/transport/file/server_test.go
index 176d6ee..ee72282 100644
--- a/plumbing/transport/file/server_test.go
+++ b/plumbing/transport/file/server_test.go
@@ -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
diff --git a/plumbing/transport/file/upload_pack_test.go b/plumbing/transport/file/upload_pack_test.go
index f013683..f894935 100644
--- a/plumbing/transport/file/upload_pack_test.go
+++ b/plumbing/transport/file/upload_pack_test.go
@@ -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
@@ -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)
}
diff --git a/plumbing/transport/git/common.go b/plumbing/transport/git/common.go
index 753f125..fcd02f8 100644
--- a/plumbing/transport/git/common.go
+++ b/plumbing/transport/git/common.go
@@ -90,12 +90,12 @@ func (c *command) StdoutPipe() (io.Reader, error) {
}
func endpointToCommand(cmd string, ep transport.Endpoint) string {
- return fmt.Sprintf("%s %s%chost=%s%c", cmd, ep.Path(), 0, ep.Host(), 0)
-}
+ host := ep.Host()
+ if ep.Port() != DefaultPort {
+ host = fmt.Sprintf("%s:%d", ep.Host(), ep.Port())
+ }
-// Wait no-op function, required by the interface
-func (c *command) Wait() error {
- return nil
+ return fmt.Sprintf("%s %s%chost=%s%c", cmd, ep.Path(), 0, host, 0)
}
// Close closes the TCP connection and connection.
diff --git a/plumbing/transport/git/receive_pack_test.go b/plumbing/transport/git/receive_pack_test.go
new file mode 100644
index 0000000..326ef1b
--- /dev/null
+++ b/plumbing/transport/git/receive_pack_test.go
@@ -0,0 +1,140 @@
+package git
+
+import (
+ "fmt"
+ "io"
+ "io/ioutil"
+ "net"
+ "os"
+ "os/exec"
+ "path/filepath"
+ "strings"
+ "time"
+
+ "github.com/src-d/go-git-fixtures"
+ "gopkg.in/src-d/go-git.v4/plumbing/transport"
+ "gopkg.in/src-d/go-git.v4/plumbing/transport/test"
+
+ . "gopkg.in/check.v1"
+)
+
+type ReceivePackSuite struct {
+ test.ReceivePackSuite
+ fixtures.Suite
+
+ base string
+ daemon *exec.Cmd
+}
+
+var _ = Suite(&ReceivePackSuite{})
+
+func (s *ReceivePackSuite) SetUpTest(c *C) {
+ s.ReceivePackSuite.Client = DefaultClient
+
+ port, err := freePort()
+ c.Assert(err, IsNil)
+
+ base, err := ioutil.TempDir(os.TempDir(), "go-git-daemon-test")
+ c.Assert(err, IsNil)
+ s.base = base
+
+ host := fmt.Sprintf("localhost_%d", port)
+ interpolatedBase := filepath.Join(base, host)
+ err = os.MkdirAll(interpolatedBase, 0755)
+ c.Assert(err, IsNil)
+
+ dotgit := fixtures.Basic().One().DotGit().Root()
+ prepareRepo(c, dotgit)
+ err = os.Rename(dotgit, filepath.Join(interpolatedBase, "basic.git"))
+ c.Assert(err, IsNil)
+
+ ep, err := transport.NewEndpoint(fmt.Sprintf("git://localhost:%d/basic.git", port))
+ c.Assert(err, IsNil)
+ s.ReceivePackSuite.Endpoint = ep
+
+ dotgit = fixtures.ByTag("empty").One().DotGit().Root()
+ prepareRepo(c, dotgit)
+ err = os.Rename(dotgit, filepath.Join(interpolatedBase, "empty.git"))
+ c.Assert(err, IsNil)
+
+ ep, err = transport.NewEndpoint(fmt.Sprintf("git://localhost:%d/empty.git", port))
+ c.Assert(err, IsNil)
+ s.ReceivePackSuite.EmptyEndpoint = ep
+
+ ep, err = transport.NewEndpoint(fmt.Sprintf("git://localhost:%d/non-existent.git", port))
+ c.Assert(err, IsNil)
+ s.ReceivePackSuite.NonExistentEndpoint = ep
+
+ s.daemon = exec.Command(
+ "git",
+ "daemon",
+ fmt.Sprintf("--base-path=%s", base),
+ "--export-all",
+ "--enable=receive-pack",
+ "--reuseaddr",
+ fmt.Sprintf("--port=%d", port),
+ // Use interpolated paths to validate that clients are specifying
+ // host and port properly.
+ // Note that some git versions (e.g. v2.11.0) had a bug that prevented
+ // the use of repository paths containing colons (:), so we use
+ // underscore (_) instead of colon in the interpolation.
+ // See https://github.com/git/git/commit/fe050334074c5132d01e1df2c1b9a82c9b8d394c
+ fmt.Sprintf("--interpolated-path=%s/%%H_%%P%%D", base),
+ // Unless max-connections is limited to 1, a git-receive-pack
+ // might not be seen by a subsequent operation.
+ "--max-connections=1",
+ // Whitelist required for interpolated paths.
+ fmt.Sprintf("%s/%s", interpolatedBase, "basic.git"),
+ fmt.Sprintf("%s/%s", interpolatedBase, "empty.git"),
+ )
+
+ // Environment must be inherited in order to acknowledge GIT_EXEC_PATH if set.
+ s.daemon.Env = os.Environ()
+
+ err = s.daemon.Start()
+ c.Assert(err, IsNil)
+
+ // Connections might be refused if we start sending request too early.
+ time.Sleep(time.Millisecond * 500)
+}
+
+func (s *ReceivePackSuite) TearDownTest(c *C) {
+ err := s.daemon.Process.Signal(os.Interrupt)
+ c.Assert(err, IsNil)
+ _ = s.daemon.Wait()
+ err = os.RemoveAll(s.base)
+ c.Assert(err, IsNil)
+}
+
+func freePort() (int, error) {
+ addr, err := net.ResolveTCPAddr("tcp", "localhost:0")
+ if err != nil {
+ return 0, err
+ }
+
+ l, err := net.ListenTCP("tcp", addr)
+ if err != nil {
+ return 0, err
+ }
+
+ return l.Addr().(*net.TCPAddr).Port, l.Close()
+}
+
+const bareConfig = `[core]
+repositoryformatversion = 0
+filemode = true
+bare = true`
+
+func prepareRepo(c *C, path string) {
+ // git-receive-pack refuses to update refs/heads/master on non-bare repo
+ // so we ensure bare repo config.
+ config := filepath.Join(path, "config")
+ if _, err := os.Stat(config); err == nil {
+ f, err := os.OpenFile(config, os.O_TRUNC|os.O_WRONLY, 0)
+ c.Assert(err, IsNil)
+ content := strings.NewReader(bareConfig)
+ _, err = io.Copy(f, content)
+ c.Assert(err, IsNil)
+ c.Assert(f.Close(), IsNil)
+ }
+}
diff --git a/plumbing/transport/internal/common/common.go b/plumbing/transport/internal/common/common.go
index f67ae29..c1e1518 100644
--- a/plumbing/transport/internal/common/common.go
+++ b/plumbing/transport/internal/common/common.go
@@ -59,14 +59,8 @@ type Command interface {
// Start starts the specified command. It does not wait for it to
// complete.
Start() error
- // Wait waits for the command to exit. It must have been started by
- // Start. The returned error is nil if the command runs, has no
- // problems copying stdin, stdout, and stderr, and exits with a zero
- // exit status.
- Wait() error
// Close closes the command and releases any resources used by it. It
- // can be called to forcibly finish the command without calling to Wait
- // or to release resources after calling Wait.
+ // will block until the command exits.
Close() error
}
@@ -178,6 +172,7 @@ func (s *session) handleAdvRefDecodeError(err error) error {
// If repository is not found, we get empty stdout and server writes an
// error to stderr.
if err == packp.ErrEmptyInput {
+ s.finished = true
if err := s.checkNotFoundError(); err != nil {
return err
}
@@ -246,9 +241,7 @@ func (s *session) UploadPack(req *packp.UploadPackRequest) (*packp.UploadPackRes
return nil, err
}
- wc := &waitCloser{s.Command}
- rc := ioutil.NewReadCloser(r, wc)
-
+ rc := ioutil.NewReadCloser(r, s.Command)
return DecodeUploadPackResponse(rc, req)
}
@@ -263,10 +256,14 @@ func (s *session) ReceivePack(req *packp.ReferenceUpdateRequest) (*packp.ReportS
return nil, err
}
+ if err := s.Stdin.Close(); err != nil {
+ return nil, err
+ }
+
if !req.Capabilities.Supports(capability.ReportStatus) {
// If we have neither report-status or sideband, we can only
// check return value error.
- return nil, s.Command.Wait()
+ return nil, s.Command.Close()
}
report := packp.NewReportStatus()
@@ -278,7 +275,7 @@ func (s *session) ReceivePack(req *packp.ReferenceUpdateRequest) (*packp.ReportS
return report, err
}
- return report, s.Command.Wait()
+ return report, s.Command.Close()
}
func (s *session) finish() error {
@@ -302,7 +299,7 @@ func (s *session) finish() error {
func (s *session) Close() error {
if err := s.finish(); err != nil {
_ = s.Command.Close()
- return nil
+ return err
}
return s.Command.Close()
@@ -329,10 +326,12 @@ func (s *session) checkNotFoundError() error {
}
var (
- githubRepoNotFoundErr = "ERROR: Repository not found."
- bitbucketRepoNotFoundErr = "conq: repository does not exist."
- localRepoNotFoundErr = "does not appear to be a git repository"
- gitProtocolNotFoundErr = "ERR \n Repository not found."
+ githubRepoNotFoundErr = "ERROR: Repository not found."
+ bitbucketRepoNotFoundErr = "conq: repository does not exist."
+ localRepoNotFoundErr = "does not appear to be a git repository"
+ gitProtocolNotFoundErr = "ERR \n Repository not found."
+ gitProtocolNoSuchErr = "ERR no such repository"
+ gitProtocolAccessDeniedErr = "ERR access denied"
)
func isRepoNotFoundError(s string) bool {
@@ -352,6 +351,14 @@ func isRepoNotFoundError(s string) bool {
return true
}
+ if strings.HasPrefix(s, gitProtocolNoSuchErr) {
+ return true
+ }
+
+ if strings.HasPrefix(s, gitProtocolAccessDeniedErr) {
+ return true
+ }
+
return false
}
@@ -403,12 +410,3 @@ func DecodeUploadPackResponse(r io.ReadCloser, req *packp.UploadPackRequest) (
return res, nil
}
-
-type waitCloser struct {
- Command Command
-}
-
-// Close waits until the command exits and returns error, if any.
-func (c *waitCloser) Close() error {
- return c.Command.Wait()
-}
diff --git a/plumbing/transport/server/loader.go b/plumbing/transport/server/loader.go
index 386c2f0..d4eccd4 100644
--- a/plumbing/transport/server/loader.go
+++ b/plumbing/transport/server/loader.go
@@ -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 /.
@@ -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
}
diff --git a/plumbing/transport/server/server_test.go b/plumbing/transport/server/server_test.go
index 6a64674..0f7201c 100644
--- a/plumbing/transport/server/server_test.go
+++ b/plumbing/transport/server/server_test.go
@@ -1,7 +1,6 @@
package server_test
import (
- "fmt"
"testing"
"github.com/src-d/go-git-fixtures"
@@ -16,8 +15,6 @@ import (
func Test(t *testing.T) { TestingT(t) }
-const inprocScheme = "inproc"
-
type BaseSuite struct {
fixtures.Suite
loader server.MapLoader
@@ -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
}
}
@@ -46,9 +43,8 @@ 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)
@@ -56,15 +52,13 @@ func (s *BaseSuite) prepareRepositories(c *C, basic *transport.Endpoint,
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
}
diff --git a/plumbing/transport/test/receive_pack.go b/plumbing/transport/test/receive_pack.go
index f4be8c8..bb1c58a 100644
--- a/plumbing/transport/test/receive_pack.go
+++ b/plumbing/transport/test/receive_pack.go
@@ -39,10 +39,10 @@ func (s *ReceivePackSuite) TestAdvertisedReferencesEmpty(c *C) {
func (s *ReceivePackSuite) TestAdvertisedReferencesNotExists(c *C) {
r, err := s.Client.NewReceivePackSession(s.NonExistentEndpoint, s.EmptyAuth)
c.Assert(err, IsNil)
- defer func() { c.Assert(r.Close(), IsNil) }()
ar, err := r.AdvertisedReferences()
c.Assert(err, Equals, transport.ErrRepositoryNotFound)
c.Assert(ar, IsNil)
+ c.Assert(r.Close(), IsNil)
r, err = s.Client.NewReceivePackSession(s.NonExistentEndpoint, s.EmptyAuth)
c.Assert(err, IsNil)
@@ -54,6 +54,7 @@ func (s *ReceivePackSuite) TestAdvertisedReferencesNotExists(c *C) {
writer, err := r.ReceivePack(req)
c.Assert(err, Equals, transport.ErrRepositoryNotFound)
c.Assert(writer, IsNil)
+ c.Assert(r.Close(), IsNil)
}
func (s *ReceivePackSuite) TestCallAdvertisedReferenceTwice(c *C) {
@@ -270,7 +271,6 @@ func (s *ReceivePackSuite) TestSendPackAddDeleteReference(c *C) {
func (s *ReceivePackSuite) testSendPackAddReference(c *C) {
r, err := s.Client.NewReceivePackSession(s.Endpoint, s.EmptyAuth)
c.Assert(err, IsNil)
- defer func() { c.Assert(r.Close(), IsNil) }()
fixture := fixtures.Basic().ByTag("packfile").One()
@@ -285,6 +285,8 @@ func (s *ReceivePackSuite) testSendPackAddReference(c *C) {
req.Capabilities.Set(capability.ReportStatus)
}
+ c.Assert(r.Close(), IsNil)
+
s.receivePack(c, s.Endpoint, req, nil, false)
s.checkRemoteReference(c, s.Endpoint, "refs/heads/newbranch", fixture.Head)
}
@@ -292,7 +294,6 @@ func (s *ReceivePackSuite) testSendPackAddReference(c *C) {
func (s *ReceivePackSuite) testSendPackDeleteReference(c *C) {
r, err := s.Client.NewReceivePackSession(s.Endpoint, s.EmptyAuth)
c.Assert(err, IsNil)
- defer func() { c.Assert(r.Close(), IsNil) }()
fixture := fixtures.Basic().ByTag("packfile").One()
@@ -307,6 +308,8 @@ func (s *ReceivePackSuite) testSendPackDeleteReference(c *C) {
req.Capabilities.Set(capability.ReportStatus)
}
+ c.Assert(r.Close(), IsNil)
+
s.receivePack(c, s.Endpoint, req, nil, false)
s.checkRemoteReference(c, s.Endpoint, "refs/heads/newbranch", plumbing.ZeroHash)
}
diff --git a/references_test.go b/references_test.go
index 050f169..3697949 100644
--- a/references_test.go
+++ b/references_test.go
@@ -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,
diff --git a/remote.go b/remote.go
index 592f7b6..deb8d7f 100644
--- a/remote.go
+++ b/remote.go
@@ -76,6 +76,8 @@ func (r *Remote) Push(o *PushOptions) (err error) {
return err
}
+ defer ioutil.CheckClose(s, &err)
+
ar, err := s.AdvertisedReferences()
if err != nil {
return err
@@ -420,7 +422,7 @@ func isFastForward(s storer.EncodedObjectStorer, old, new plumbing.Hash) (bool,
}
found := false
- iter := object.NewCommitPreIterator(c)
+ iter := object.NewCommitPreorderIter(c)
return found, iter.ForEach(func(c *object.Commit) error {
if c.Hash != old {
return nil
diff --git a/remote_test.go b/remote_test.go
index 8b2f71c..78339d4 100644
--- a/remote_test.go
+++ b/remote_test.go
@@ -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 {
@@ -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,
@@ -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,
@@ -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,
@@ -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,
@@ -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,
@@ -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,
diff --git a/repository.go b/repository.go
index 35aae52..a60f3ef 100644
--- a/repository.go
+++ b/repository.go
@@ -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 (
@@ -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
}
@@ -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" {
@@ -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 == ".." {
@@ -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)
@@ -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
}
@@ -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 {
@@ -242,10 +237,11 @@ 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
}
@@ -253,7 +249,7 @@ func dotGitToFilesystems(path string) (dot, wt billy.Filesystem, err error) {
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")
@@ -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
@@ -694,7 +690,7 @@ func (r *Repository) Log(o *LogOptions) (object.CommitIter, error) {
return nil, err
}
- return object.NewCommitPreIterator(commit), nil
+ return object.NewCommitPreorderIter(commit), nil
}
// Tags returns all the References from Tags. This method returns all the tag
@@ -927,7 +923,7 @@ func (r *Repository) ResolveRevision(rev plumbing.Revision) (*plumbing.Hash, err
commit = c
}
case revision.CaretReg:
- history := object.NewCommitPreIterator(commit)
+ history := object.NewCommitPreorderIter(commit)
re := item.(revision.CaretReg).Regexp
negate := item.(revision.CaretReg).Negate
@@ -957,7 +953,7 @@ func (r *Repository) ResolveRevision(rev plumbing.Revision) (*plumbing.Hash, err
commit = c
case revision.AtDate:
- history := object.NewCommitPreIterator(commit)
+ history := object.NewCommitPreorderIter(commit)
date := item.(revision.AtDate).Date
diff --git a/repository_test.go b/repository_test.go
index deb3f58..f622007 100644
--- a/repository_test.go
+++ b/repository_test.go
@@ -18,8 +18,8 @@ import (
"gopkg.in/src-d/go-git.v4/storage/memory"
. "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"
)
type RepositorySuite struct {
@@ -44,23 +44,25 @@ func (s *RepositorySuite) TestInitNonStandardDotGit(c *C) {
c.Assert(os.RemoveAll(dir), IsNil)
fs := osfs.New(dir)
- storage, err := filesystem.NewStorage(fs.Dir("storage"))
+ dot, _ := fs.Chroot("storage")
+ storage, err := filesystem.NewStorage(dot)
c.Assert(err, IsNil)
- r, err := Init(storage, fs.Dir("worktree"))
+ wt, _ := fs.Chroot("worktree")
+ r, err := Init(storage, wt)
c.Assert(err, IsNil)
c.Assert(r, NotNil)
- f, err := fs.Open("worktree/.git")
+ f, err := fs.Open(fs.Join("worktree", ".git"))
c.Assert(err, IsNil)
all, err := ioutil.ReadAll(f)
c.Assert(err, IsNil)
- c.Assert(string(all), Equals, "gitdir: ../storage\n")
+ c.Assert(string(all), Equals, fmt.Sprintf("gitdir: %s\n", filepath.Join("..", "storage")))
cfg, err := r.Config()
c.Assert(err, IsNil)
- c.Assert(cfg.Core.Worktree, Equals, "../worktree")
+ c.Assert(cfg.Core.Worktree, Equals, filepath.Join("..", "worktree"))
}
func (s *RepositorySuite) TestInitStandardDotGit(c *C) {
@@ -69,7 +71,8 @@ func (s *RepositorySuite) TestInitStandardDotGit(c *C) {
c.Assert(os.RemoveAll(dir), IsNil)
fs := osfs.New(dir)
- storage, err := filesystem.NewStorage(fs.Dir(".git"))
+ dot, _ := fs.Chroot(".git")
+ storage, err := filesystem.NewStorage(dot)
c.Assert(err, IsNil)
r, err := Init(storage, fs)
@@ -386,7 +389,7 @@ func (s *RepositorySuite) TestPlainCloneWithRecurseSubmodules(c *C) {
c.Assert(err, IsNil)
defer os.RemoveAll(dir)
- path := fixtures.ByTag("submodule").One().Worktree().Base()
+ path := fixtures.ByTag("submodule").One().Worktree().Root()
r, err := PlainClone(dir, false, &CloneOptions{
URL: path,
RecurseSubmodules: DefaultSubmoduleRecursionDepth,
@@ -669,7 +672,7 @@ func (s *RepositorySuite) TestPullProgress(c *C) {
}
func (s *RepositorySuite) TestPullProgressWithRecursion(c *C) {
- path := fixtures.ByTag("submodule").One().Worktree().Base()
+ path := fixtures.ByTag("submodule").One().Worktree().Root()
dir, err := ioutil.TempDir("", "plain-clone-submodule")
c.Assert(err, IsNil)
@@ -691,7 +694,7 @@ func (s *RepositorySuite) TestPullProgressWithRecursion(c *C) {
}
func (s *RepositorySuite) TestPullAdd(c *C) {
- path := fixtures.Basic().ByTag("worktree").One().Worktree().Base()
+ path := fixtures.Basic().ByTag("worktree").One().Worktree().Root()
r, err := Clone(memory.NewStorage(), nil, &CloneOptions{
URL: filepath.Join(path, ".git"),
@@ -729,7 +732,7 @@ func (s *RepositorySuite) TestPushToEmptyRepository(c *C) {
c.Assert(err, IsNil)
dstFs := fixtures.ByTag("empty").One().DotGit()
- url := dstFs.Base()
+ url := dstFs.Root()
r, err := Open(sto, srcFs)
c.Assert(err, IsNil)
diff --git a/storage/filesystem/config_test.go b/storage/filesystem/config_test.go
index b2879b3..1b812e6 100644
--- a/storage/filesystem/config_test.go
+++ b/storage/filesystem/config_test.go
@@ -8,7 +8,7 @@ import (
"gopkg.in/src-d/go-git.v4/storage/filesystem/internal/dotgit"
. "gopkg.in/check.v1"
- "gopkg.in/src-d/go-billy.v2/osfs"
+ "gopkg.in/src-d/go-billy.v3/osfs"
)
type ConfigSuite struct {
diff --git a/storage/filesystem/internal/dotgit/dotgit.go b/storage/filesystem/internal/dotgit/dotgit.go
index 1af64ab..c48f24c 100644
--- a/storage/filesystem/internal/dotgit/dotgit.go
+++ b/storage/filesystem/internal/dotgit/dotgit.go
@@ -12,7 +12,7 @@ import (
"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/utils/ioutil"
- "gopkg.in/src-d/go-billy.v2"
+ "gopkg.in/src-d/go-billy.v3"
)
const (
@@ -357,7 +357,7 @@ func (d *DotGit) rewritePackedRefsWithoutRef(name plumbing.ReferenceName) (err e
return err
}
- tmpPath := tmp.Filename()
+ tmpPath := tmp.Name()
defer ioutil.CheckClose(tmp, &err)
defer d.fs.Remove(tmpPath)
@@ -413,11 +413,11 @@ func (d *DotGit) processLine(line string) (*plumbing.Reference, error) {
}
func (d *DotGit) addRefsFromRefDir(refs *[]*plumbing.Reference) error {
- return d.walkReferencesTree(refs, refsPath)
+ return d.walkReferencesTree(refs, []string{refsPath})
}
-func (d *DotGit) walkReferencesTree(refs *[]*plumbing.Reference, relPath string) error {
- files, err := d.fs.ReadDir(relPath)
+func (d *DotGit) walkReferencesTree(refs *[]*plumbing.Reference, relPath []string) error {
+ files, err := d.fs.ReadDir(d.fs.Join(relPath...))
if err != nil {
if os.IsNotExist(err) {
return nil
@@ -427,7 +427,7 @@ func (d *DotGit) walkReferencesTree(refs *[]*plumbing.Reference, relPath string)
}
for _, f := range files {
- newRelPath := d.fs.Join(relPath, f.Name())
+ newRelPath := append(append([]string(nil), relPath...), f.Name())
if f.IsDir() {
if err = d.walkReferencesTree(refs, newRelPath); err != nil {
return err
@@ -436,7 +436,7 @@ func (d *DotGit) walkReferencesTree(refs *[]*plumbing.Reference, relPath string)
continue
}
- ref, err := d.readReferenceFile(".", newRelPath)
+ ref, err := d.readReferenceFile(".", strings.Join(newRelPath, "/"))
if err != nil {
return err
}
@@ -463,9 +463,8 @@ func (d *DotGit) addRefFromHEAD(refs *[]*plumbing.Reference) error {
return nil
}
-func (d *DotGit) readReferenceFile(refsPath, refFile string) (ref *plumbing.Reference, err error) {
- path := d.fs.Join(refsPath, refFile)
-
+func (d *DotGit) readReferenceFile(path, name string) (ref *plumbing.Reference, err error) {
+ path = d.fs.Join(path, d.fs.Join(strings.Split(name, "/")...))
f, err := d.fs.Open(path)
if err != nil {
return nil, err
@@ -478,12 +477,12 @@ func (d *DotGit) readReferenceFile(refsPath, refFile string) (ref *plumbing.Refe
}
line := strings.TrimSpace(string(b))
- return plumbing.NewReferenceFromStrings(refFile, line), nil
+ return plumbing.NewReferenceFromStrings(name, line), nil
}
// Module return a billy.Filesystem poiting to the module folder
-func (d *DotGit) Module(name string) billy.Filesystem {
- return d.fs.Dir(d.fs.Join(modulePath, name))
+func (d *DotGit) Module(name string) (billy.Filesystem, error) {
+ return d.fs.Chroot(d.fs.Join(modulePath, name))
}
func isHex(s string) bool {
diff --git a/storage/filesystem/internal/dotgit/dotgit_test.go b/storage/filesystem/internal/dotgit/dotgit_test.go
index f06f908..6151c8f 100644
--- a/storage/filesystem/internal/dotgit/dotgit_test.go
+++ b/storage/filesystem/internal/dotgit/dotgit_test.go
@@ -12,7 +12,7 @@ import (
"gopkg.in/src-d/go-git.v4/plumbing"
. "gopkg.in/check.v1"
- "gopkg.in/src-d/go-billy.v2/osfs"
+ "gopkg.in/src-d/go-billy.v3/osfs"
)
func Test(t *testing.T) { TestingT(t) }
@@ -157,7 +157,7 @@ func (s *SuiteDotGit) TestRemoveRefFromPackedRefs(c *C) {
err := dir.RemoveRef(name)
c.Assert(err, IsNil)
- b, err := ioutil.ReadFile(filepath.Join(fs.Base(), packedRefsPath))
+ b, err := ioutil.ReadFile(filepath.Join(fs.Root(), packedRefsPath))
c.Assert(err, IsNil)
c.Assert(string(b), Equals, ""+
@@ -170,7 +170,7 @@ func (s *SuiteDotGit) TestRemoveRefNonExistent(c *C) {
fs := fixtures.Basic().ByTag(".git").One().DotGit()
dir := New(fs)
- packedRefs := filepath.Join(fs.Base(), packedRefsPath)
+ packedRefs := filepath.Join(fs.Root(), packedRefsPath)
before, err := ioutil.ReadFile(packedRefs)
c.Assert(err, IsNil)
@@ -188,7 +188,7 @@ func (s *SuiteDotGit) TestRemoveRefInvalidPackedRefs(c *C) {
fs := fixtures.Basic().ByTag(".git").One().DotGit()
dir := New(fs)
- packedRefs := filepath.Join(fs.Base(), packedRefsPath)
+ packedRefs := filepath.Join(fs.Root(), packedRefsPath)
brokenContent := "BROKEN STUFF REALLY BROKEN"
err := ioutil.WriteFile(packedRefs, []byte(brokenContent), os.FileMode(0755))
@@ -198,7 +198,7 @@ func (s *SuiteDotGit) TestRemoveRefInvalidPackedRefs(c *C) {
err = dir.RemoveRef(name)
c.Assert(err, NotNil)
- after, err := ioutil.ReadFile(filepath.Join(fs.Base(), packedRefsPath))
+ after, err := ioutil.ReadFile(filepath.Join(fs.Root(), packedRefsPath))
c.Assert(err, IsNil)
c.Assert(brokenContent, Equals, string(after))
@@ -208,7 +208,7 @@ func (s *SuiteDotGit) TestRemoveRefInvalidPackedRefs2(c *C) {
fs := fixtures.Basic().ByTag(".git").One().DotGit()
dir := New(fs)
- packedRefs := filepath.Join(fs.Base(), packedRefsPath)
+ packedRefs := filepath.Join(fs.Root(), packedRefsPath)
brokenContent := strings.Repeat("a", bufio.MaxScanTokenSize*2)
err := ioutil.WriteFile(packedRefs, []byte(brokenContent), os.FileMode(0755))
@@ -218,7 +218,7 @@ func (s *SuiteDotGit) TestRemoveRefInvalidPackedRefs2(c *C) {
err = dir.RemoveRef(name)
c.Assert(err, NotNil)
- after, err := ioutil.ReadFile(filepath.Join(fs.Base(), packedRefsPath))
+ after, err := ioutil.ReadFile(filepath.Join(fs.Root(), packedRefsPath))
c.Assert(err, IsNil)
c.Assert(brokenContent, Equals, string(after))
@@ -243,7 +243,7 @@ func (s *SuiteDotGit) TestConfig(c *C) {
file, err := dir.Config()
c.Assert(err, IsNil)
- c.Assert(filepath.Base(file.Filename()), Equals, "config")
+ c.Assert(filepath.Base(file.Name()), Equals, "config")
}
func (s *SuiteDotGit) TestConfigWriteAndConfig(c *C) {
@@ -362,7 +362,7 @@ func (s *SuiteDotGit) TestObjectPack(c *C) {
pack, err := dir.ObjectPack(f.PackfileHash)
c.Assert(err, IsNil)
- c.Assert(filepath.Ext(pack.Filename()), Equals, ".pack")
+ c.Assert(filepath.Ext(pack.Name()), Equals, ".pack")
}
func (s *SuiteDotGit) TestObjectPackIdx(c *C) {
@@ -372,7 +372,7 @@ func (s *SuiteDotGit) TestObjectPackIdx(c *C) {
idx, err := dir.ObjectPackIdx(f.PackfileHash)
c.Assert(err, IsNil)
- c.Assert(filepath.Ext(idx.Filename()), Equals, ".idx")
+ c.Assert(filepath.Ext(idx.Name()), Equals, ".idx")
}
func (s *SuiteDotGit) TestObjectPackNotFound(c *C) {
@@ -445,7 +445,7 @@ func (s *SuiteDotGit) TestObject(c *C) {
file, err := dir.Object(hash)
c.Assert(err, IsNil)
c.Assert(strings.HasSuffix(
- file.Filename(), "objects/03/db8e1fbe133a480f2867aac478fd866686d69e"),
+ file.Name(), fs.Join("objects", "03", "db8e1fbe133a480f2867aac478fd866686d69e")),
Equals, true,
)
}
@@ -464,6 +464,7 @@ func (s *SuiteDotGit) TestSubmodules(c *C) {
fs := fixtures.ByTag("submodule").One().DotGit()
dir := New(fs)
- m := dir.Module("basic")
- c.Assert(strings.HasSuffix(m.Base(), ".git/module/basic"), Equals, true)
+ m, err := dir.Module("basic")
+ c.Assert(err, IsNil)
+ c.Assert(strings.HasSuffix(m.Root(), m.Join(".git", "module", "basic")), Equals, true)
}
diff --git a/storage/filesystem/internal/dotgit/writers.go b/storage/filesystem/internal/dotgit/writers.go
index 0d2747f..2407c58 100644
--- a/storage/filesystem/internal/dotgit/writers.go
+++ b/storage/filesystem/internal/dotgit/writers.go
@@ -10,7 +10,7 @@ import (
"gopkg.in/src-d/go-git.v4/plumbing/format/objfile"
"gopkg.in/src-d/go-git.v4/plumbing/format/packfile"
- "gopkg.in/src-d/go-billy.v2"
+ "gopkg.in/src-d/go-billy.v3"
)
// PackWriter is a io.Writer that generates the packfile index simultaneously,
@@ -36,7 +36,7 @@ func newPackWrite(fs billy.Filesystem) (*PackWriter, error) {
return nil, err
}
- fr, err := fs.Open(fw.Filename())
+ fr, err := fs.Open(fw.Name())
if err != nil {
return nil, err
}
@@ -130,7 +130,7 @@ func (w *PackWriter) Close() error {
}
func (w *PackWriter) clean() error {
- return w.fs.Remove(w.fw.Filename())
+ return w.fs.Remove(w.fw.Name())
}
func (w *PackWriter) save() error {
@@ -148,7 +148,7 @@ func (w *PackWriter) save() error {
return err
}
- return w.fs.Rename(w.fw.Filename(), fmt.Sprintf("%s.pack", base))
+ return w.fs.Rename(w.fw.Name(), fmt.Sprintf("%s.pack", base))
}
func (w *PackWriter) encodeIdx(writer io.Writer) error {
@@ -282,5 +282,5 @@ func (w *ObjectWriter) save() error {
hash := w.Hash().String()
file := w.fs.Join(objectsPath, hash[0:2], hash[2:40])
- return w.fs.Rename(w.f.Filename(), file)
+ return w.fs.Rename(w.f.Name(), file)
}
diff --git a/storage/filesystem/internal/dotgit/writers_test.go b/storage/filesystem/internal/dotgit/writers_test.go
index e7d7ef9..d2c7b6f 100644
--- a/storage/filesystem/internal/dotgit/writers_test.go
+++ b/storage/filesystem/internal/dotgit/writers_test.go
@@ -11,7 +11,7 @@ import (
"github.com/src-d/go-git-fixtures"
. "gopkg.in/check.v1"
- "gopkg.in/src-d/go-billy.v2/osfs"
+ "gopkg.in/src-d/go-billy.v3/osfs"
)
func (s *SuiteDotGit) TestNewObjectPack(c *C) {
diff --git a/storage/filesystem/module.go b/storage/filesystem/module.go
index 2e469d3..6f3de3f 100644
--- a/storage/filesystem/module.go
+++ b/storage/filesystem/module.go
@@ -10,5 +10,10 @@ type ModuleStorage struct {
}
func (s *ModuleStorage) Module(name string) (storage.Storer, error) {
- return NewStorage(s.dir.Module(name))
+ fs, err := s.dir.Module(name)
+ if err != nil {
+ return nil, err
+ }
+
+ return NewStorage(fs)
}
diff --git a/storage/filesystem/object.go b/storage/filesystem/object.go
index 782b99b..dc88108 100644
--- a/storage/filesystem/object.go
+++ b/storage/filesystem/object.go
@@ -12,7 +12,7 @@ import (
"gopkg.in/src-d/go-git.v4/storage/filesystem/internal/dotgit"
"gopkg.in/src-d/go-git.v4/storage/memory"
- "gopkg.in/src-d/go-billy.v2"
+ "gopkg.in/src-d/go-billy.v3"
)
type ObjectStorage struct {
diff --git a/storage/filesystem/storage.go b/storage/filesystem/storage.go
index af340d7..2c7c107 100644
--- a/storage/filesystem/storage.go
+++ b/storage/filesystem/storage.go
@@ -4,14 +4,14 @@ package filesystem
import (
"gopkg.in/src-d/go-git.v4/storage/filesystem/internal/dotgit"
- "gopkg.in/src-d/go-billy.v2"
+ "gopkg.in/src-d/go-billy.v3"
)
// Storage is an implementation of git.Storer that stores data on disk in the
// standard git format (this is, the .git directory). Zero values of this type
// are not safe to use, see the NewStorage function below.
type Storage struct {
- fs billy.Filesystem
+ fs billy.Filesystem
dir *dotgit.DotGit
ObjectStorage
@@ -31,7 +31,7 @@ func NewStorage(fs billy.Filesystem) (*Storage, error) {
}
return &Storage{
- fs: fs,
+ fs: fs,
dir: dir,
ObjectStorage: o,
diff --git a/storage/filesystem/storage_test.go b/storage/filesystem/storage_test.go
index 03d2e86..2ced9dd 100644
--- a/storage/filesystem/storage_test.go
+++ b/storage/filesystem/storage_test.go
@@ -7,8 +7,8 @@ import (
"gopkg.in/src-d/go-git.v4/storage/test"
. "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) }
diff --git a/submodule.go b/submodule.go
index fd23b9d..572e6f7 100644
--- a/submodule.go
+++ b/submodule.go
@@ -5,6 +5,7 @@ import (
"errors"
"fmt"
+ billy "gopkg.in/src-d/go-billy.v3"
"gopkg.in/src-d/go-git.v4/config"
"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/format/index"
@@ -107,8 +108,17 @@ func (s *Submodule) Repository() (*Repository, error) {
return nil, err
}
- worktree := s.w.fs.Dir(s.c.Path)
+ var exists bool
if err == nil {
+ exists = true
+ }
+
+ var worktree billy.Filesystem
+ if worktree, err = s.w.fs.Chroot(s.c.Path); err != nil {
+ return nil, err
+ }
+
+ if exists {
return Open(storer, worktree)
}
diff --git a/submodule_test.go b/submodule_test.go
index fdbe4a8..b398664 100644
--- a/submodule_test.go
+++ b/submodule_test.go
@@ -20,7 +20,7 @@ type SubmoduleSuite struct {
var _ = Suite(&SubmoduleSuite{})
func (s *SubmoduleSuite) SetUpTest(c *C) {
- path := fixtures.ByTag("submodule").One().Worktree().Base()
+ path := fixtures.ByTag("submodule").One().Worktree().Root()
dir, err := ioutil.TempDir("", "submodule")
c.Assert(err, IsNil)
@@ -127,7 +127,8 @@ func (s *SubmoduleSuite) TestUpdateWithRecursion(c *C) {
c.Assert(err, IsNil)
- _, err = s.Worktree.fs.Stat("itself/basic/LICENSE")
+ fs := s.Worktree.fs
+ _, err = fs.Stat(fs.Join("itself", "basic", "LICENSE"))
c.Assert(err, IsNil)
}
diff --git a/utils/merkletrie/filesystem/node.go b/utils/merkletrie/filesystem/node.go
index fc8f191..5461bd3 100644
--- a/utils/merkletrie/filesystem/node.go
+++ b/utils/merkletrie/filesystem/node.go
@@ -5,7 +5,7 @@ import (
"os"
"path/filepath"
- "gopkg.in/src-d/go-billy.v2"
+ "gopkg.in/src-d/go-billy.v3"
"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/filemode"
"gopkg.in/src-d/go-git.v4/utils/merkletrie/noder"
@@ -106,7 +106,7 @@ func (n *node) calculateChildren() error {
return nil
}
-func (n *node) newChildNode(file billy.FileInfo) (*node, error) {
+func (n *node) newChildNode(file os.FileInfo) (*node, error) {
path := filepath.Join(n.path, file.Name())
hash, err := n.calculateHash(path, file)
@@ -131,7 +131,7 @@ func (n *node) newChildNode(file billy.FileInfo) (*node, error) {
return node, nil
}
-func (n *node) calculateHash(path string, file billy.FileInfo) ([]byte, error) {
+func (n *node) calculateHash(path string, file os.FileInfo) ([]byte, error) {
if file.IsDir() {
return make([]byte, 24), nil
}
diff --git a/utils/merkletrie/filesystem/node_test.go b/utils/merkletrie/filesystem/node_test.go
index f783c15..a383716 100644
--- a/utils/merkletrie/filesystem/node_test.go
+++ b/utils/merkletrie/filesystem/node_test.go
@@ -7,8 +7,8 @@ import (
"testing"
. "gopkg.in/check.v1"
- "gopkg.in/src-d/go-billy.v2"
- "gopkg.in/src-d/go-billy.v2/memfs"
+ "gopkg.in/src-d/go-billy.v3"
+ "gopkg.in/src-d/go-billy.v3/memfs"
"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/utils/merkletrie"
"gopkg.in/src-d/go-git.v4/utils/merkletrie/noder"
diff --git a/worktree.go b/worktree.go
index ad6e0f7..aa30b83 100644
--- a/worktree.go
+++ b/worktree.go
@@ -8,6 +8,7 @@ import (
"os"
"path/filepath"
+ "gopkg.in/src-d/go-billy.v3/util"
"gopkg.in/src-d/go-git.v4/config"
"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/filemode"
@@ -15,7 +16,7 @@ import (
"gopkg.in/src-d/go-git.v4/plumbing/object"
"gopkg.in/src-d/go-git.v4/utils/merkletrie"
- "gopkg.in/src-d/go-billy.v2"
+ "gopkg.in/src-d/go-billy.v3"
)
var (
@@ -486,7 +487,7 @@ func (w *Worktree) readGitmodulesFile() (*config.Modules, error) {
}
func rmFileAndDirIfEmpty(fs billy.Filesystem, name string) error {
- if err := billy.RemoveAll(fs, name); err != nil {
+ if err := util.RemoveAll(fs, name); err != nil {
return err
}
diff --git a/worktree_commit.go b/worktree_commit.go
index bec75b2..5307b41 100644
--- a/worktree_commit.go
+++ b/worktree_commit.go
@@ -12,7 +12,7 @@ import (
"gopkg.in/src-d/go-git.v4/storage"
"gopkg.in/src-d/go-git.v4/utils/ioutil"
- "gopkg.in/src-d/go-billy.v2"
+ "gopkg.in/src-d/go-billy.v3"
)
// Commit stores the current contents of the index in a new commit along with
diff --git a/worktree_commit_test.go b/worktree_commit_test.go
index 7e1b93c..8f3b7b0 100644
--- a/worktree_commit_test.go
+++ b/worktree_commit_test.go
@@ -9,8 +9,8 @@ import (
"gopkg.in/src-d/go-git.v4/storage/memory"
. "gopkg.in/check.v1"
- "gopkg.in/src-d/go-billy.v2"
- "gopkg.in/src-d/go-billy.v2/memfs"
+ "gopkg.in/src-d/go-billy.v3/memfs"
+ "gopkg.in/src-d/go-billy.v3/util"
)
func (s *WorktreeSuite) TestCommitInvalidOptions(c *C) {
@@ -37,7 +37,7 @@ func (s *WorktreeSuite) TestCommitInitial(c *C) {
w, err := r.Worktree()
c.Assert(err, IsNil)
- billy.WriteFile(fs, "foo", []byte("foo"), 0644)
+ util.WriteFile(fs, "foo", []byte("foo"), 0644)
_, err = w.Add("foo")
c.Assert(err, IsNil)
@@ -61,7 +61,7 @@ func (s *WorktreeSuite) TestCommitParent(c *C) {
err := w.Checkout(&CheckoutOptions{})
c.Assert(err, IsNil)
- billy.WriteFile(fs, "foo", []byte("foo"), 0644)
+ util.WriteFile(fs, "foo", []byte("foo"), 0644)
_, err = w.Add("foo")
c.Assert(err, IsNil)
@@ -85,8 +85,8 @@ func (s *WorktreeSuite) TestCommitAll(c *C) {
err := w.Checkout(&CheckoutOptions{})
c.Assert(err, IsNil)
- billy.WriteFile(fs, "LICENSE", []byte("foo"), 0644)
- billy.WriteFile(fs, "foo", []byte("foo"), 0644)
+ util.WriteFile(fs, "LICENSE", []byte("foo"), 0644)
+ util.WriteFile(fs, "foo", []byte("foo"), 0644)
hash, err := w.Commit("foo\n", &CommitOptions{
All: true,
diff --git a/worktree_test.go b/worktree_test.go
index 56c1d9a..9efa231 100644
--- a/worktree_test.go
+++ b/worktree_test.go
@@ -13,9 +13,9 @@ import (
"github.com/src-d/go-git-fixtures"
. "gopkg.in/check.v1"
- "gopkg.in/src-d/go-billy.v2"
- "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"
+ "gopkg.in/src-d/go-billy.v3/util"
)
type WorktreeSuite struct {
@@ -521,7 +521,7 @@ func (s *WorktreeSuite) TestStatusDeleted(c *C) {
}
func (s *WorktreeSuite) TestSubmodule(c *C) {
- path := fixtures.ByTag("submodule").One().Worktree().Base()
+ path := fixtures.ByTag("submodule").One().Worktree().Root()
r, err := PlainOpen(path)
c.Assert(err, IsNil)
@@ -535,7 +535,7 @@ func (s *WorktreeSuite) TestSubmodule(c *C) {
}
func (s *WorktreeSuite) TestSubmodules(c *C) {
- path := fixtures.ByTag("submodule").One().Worktree().Base()
+ path := fixtures.ByTag("submodule").One().Worktree().Root()
r, err := PlainOpen(path)
c.Assert(err, IsNil)
@@ -562,7 +562,7 @@ func (s *WorktreeSuite) TestAddUntracked(c *C) {
c.Assert(err, IsNil)
c.Assert(idx.Entries, HasLen, 9)
- err = billy.WriteFile(w.fs, "foo", []byte("FOO"), 0755)
+ err = util.WriteFile(w.fs, "foo", []byte("FOO"), 0755)
c.Assert(err, IsNil)
hash, err := w.Add("foo")
@@ -601,7 +601,7 @@ func (s *WorktreeSuite) TestAddModified(c *C) {
c.Assert(err, IsNil)
c.Assert(idx.Entries, HasLen, 9)
- err = billy.WriteFile(w.fs, "LICENSE", []byte("FOO"), 0644)
+ err = util.WriteFile(w.fs, "LICENSE", []byte("FOO"), 0644)
c.Assert(err, IsNil)
hash, err := w.Add("LICENSE")