diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2016-08-14 00:44:18 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2016-08-14 00:44:18 +0200 |
commit | f826cf9d42cc34e2ae5aaf6ede892ecab9d2f198 (patch) | |
tree | 7555e7596887f239ce26828e98142e4df25c388f | |
parent | 79087748f60f9aba219624a0fe9f4d33a0b51236 (diff) | |
download | go-git-f826cf9d42cc34e2ae5aaf6ede892ecab9d2f198.tar.gz |
fix tests and examples
-rw-r--r-- | cshared/remote_cshared.go | 11 | ||||
-rw-r--r-- | cshared/repository_cshared.go | 10 | ||||
-rw-r--r-- | examples/basic/main.go | 7 | ||||
-rw-r--r-- | examples/fs_implementation/main.go | 22 | ||||
-rw-r--r-- | examples/fs_implementation/main_test.go | 12 | ||||
-rw-r--r-- | examples/latest/latest.go | 14 | ||||
-rw-r--r-- | repository.go | 12 | ||||
-rw-r--r-- | utils/difftree/difftree_test.go | 6 | ||||
-rw-r--r-- | utils/fs/os_test.go | 2 |
9 files changed, 57 insertions, 39 deletions
diff --git a/cshared/remote_cshared.go b/cshared/remote_cshared.go index abed3c9..ee52e41 100644 --- a/cshared/remote_cshared.go +++ b/cshared/remote_cshared.go @@ -1,12 +1,9 @@ // +build ignore package main -import ( - "C" +import "C" - "gopkg.in/src-d/go-git.v4" - "gopkg.in/src-d/go-git.v4/clients/common" -) +/* //export c_Remote_get_Endpoint func c_Remote_get_Endpoint(r uint64) *C.char { @@ -189,4 +186,6 @@ func c_Remote_Refs(r uint64) uint64 { remote := obj.(*git.Remote) refs := remote.Refs() return uint64(RegisterObject(refs)) -}
\ No newline at end of file +} + +*/ diff --git a/cshared/repository_cshared.go b/cshared/repository_cshared.go index 8320f98..e11a6c0 100644 --- a/cshared/repository_cshared.go +++ b/cshared/repository_cshared.go @@ -1,13 +1,9 @@ // +build ignore package main -import ( - "C" +import "C" - "gopkg.in/src-d/go-git.v4" - "gopkg.in/src-d/go-git.v4/clients/common" - "gopkg.in/src-d/go-git.v4/core" -) +/* //export c_Repository func c_Repository() uint64 { @@ -232,3 +228,5 @@ func c_Repository_Object(r uint64, h []byte) (uint64, int, *C.char) { robj_handle := RegisterObject(robj) return uint64(robj_handle), ErrorCodeSuccess, nil } + +*/ diff --git a/examples/basic/main.go b/examples/basic/main.go index 6dc2ba1..fd7f82e 100644 --- a/examples/basic/main.go +++ b/examples/basic/main.go @@ -9,13 +9,14 @@ import ( ) func main() { - fmt.Printf("Retrieving %q ...\n", os.Args[1]) - r, err := git.NewRepository(os.Args[1], nil) + url := os.Args[1] + fmt.Printf("Retrieving %q ...\n", url) + r, err := git.NewMemoryRepository() if err != nil { panic(err) } - if err = r.PullDefault(); err != nil { + if err = r.Clone(&git.CloneOptions{URL: url}); err != nil { panic(err) } diff --git a/examples/fs_implementation/main.go b/examples/fs_implementation/main.go index 552a923..a9bfbe6 100644 --- a/examples/fs_implementation/main.go +++ b/examples/fs_implementation/main.go @@ -9,7 +9,7 @@ import ( "strings" "gopkg.in/src-d/go-git.v4" - gogitFS "gopkg.in/src-d/go-git.v4/utils/fs" + "gopkg.in/src-d/go-git.v4/utils/fs" ) func main() { @@ -18,9 +18,9 @@ func main() { os.Exit(1) } - fs := newFS(os.Args[1]) + fs := NewCustomFS(os.Args[1]) - repo, err := git.NewRepositoryFromFS(fs, ".git") + repo, err := git.NewFilesystemRepository(fs, ".git") if err != nil { fmt.Fprint(os.Stderr, err) os.Exit(1) @@ -57,19 +57,19 @@ func usage() { // // Example: when constructed with 'newFS("tmp")', a path like 'foo--bar' // will represent the local path "/tmp/foo/bar". -type fs struct { +type CustomFS struct { base string } const separator = "--" -func newFS(path string) *fs { - return &fs{ +func NewCustomFS(path string) *CustomFS { + return &CustomFS{ base: path, } } -func (fs *fs) Stat(path string) (info os.FileInfo, err error) { +func (fs *CustomFS) Stat(path string) (info os.FileInfo, err error) { f, err := os.Open(fs.ToReal(path)) if err != nil { return nil, err @@ -85,19 +85,19 @@ func (fs *fs) Stat(path string) (info os.FileInfo, err error) { return f.Stat() } -func (fs *fs) ToReal(path string) string { +func (fs *CustomFS) ToReal(path string) string { parts := strings.Split(path, separator) return filepath.Join(fs.base, filepath.Join(parts...)) } -func (fs *fs) Open(path string) (gogitFS.ReadSeekCloser, error) { +func (fs *CustomFS) Open(path string) (fs.ReadSeekCloser, error) { return os.Open(fs.ToReal(path)) } -func (fs *fs) ReadDir(path string) ([]os.FileInfo, error) { +func (fs *CustomFS) ReadDir(path string) ([]os.FileInfo, error) { return ioutil.ReadDir(fs.ToReal(path)) } -func (fs *fs) Join(elem ...string) string { +func (fs *CustomFS) Join(elem ...string) string { return strings.Join(elem, separator) } diff --git a/examples/fs_implementation/main_test.go b/examples/fs_implementation/main_test.go index 9683b1b..ed56cf1 100644 --- a/examples/fs_implementation/main_test.go +++ b/examples/fs_implementation/main_test.go @@ -20,7 +20,7 @@ func TestMain(m *testing.M) { func setUp() { var err error - repo, err = tgz.Extract("../../storage/filesystem/internal/gitdir/fixtures/spinnaker-gc.tgz") + repo, err = tgz.Extract("../../storage/filesystem/internal/dotgit/fixtures/spinnaker-gc.tgz") if err != nil { panic(err) } @@ -36,7 +36,7 @@ func tearDown() { } func TestJoin(t *testing.T) { - fs := newFS("") + fs := NewCustomFS("") for i, test := range [...]struct { input []string expected string @@ -64,7 +64,7 @@ func TestJoin(t *testing.T) { } func TestStat(t *testing.T) { - fs := newFS(filepath.Join(repo, ".git/")) + fs := NewCustomFS(filepath.Join(repo, ".git/")) for i, path := range [...]string{ "index", "info--refs", @@ -98,7 +98,7 @@ func TestStat(t *testing.T) { } func TestStatErrors(t *testing.T) { - fs := newFS(filepath.Join(repo, ".git/")) + fs := NewCustomFS(filepath.Join(repo, ".git/")) for i, test := range [...]struct { input string errRegExp string @@ -125,7 +125,7 @@ func TestStatErrors(t *testing.T) { } func TestOpen(t *testing.T) { - fs := newFS(filepath.Join(repo, ".git/")) + fs := NewCustomFS(filepath.Join(repo, ".git/")) for i, path := range [...]string{ "index", "info--refs", @@ -169,7 +169,7 @@ func TestOpen(t *testing.T) { } func TestReadDir(t *testing.T) { - fs := newFS(filepath.Join(repo, ".git/")) + fs := NewCustomFS(filepath.Join(repo, ".git/")) for i, path := range [...]string{ "info", ".", diff --git a/examples/latest/latest.go b/examples/latest/latest.go index 2ccddf1..684ebb7 100644 --- a/examples/latest/latest.go +++ b/examples/latest/latest.go @@ -8,17 +8,23 @@ import ( ) func main() { - fmt.Printf("Retrieving latest commit from: %q ...\n", os.Args[1]) - r, err := git.NewRepository(os.Args[1], nil) + url := os.Args[1] + + fmt.Printf("Retrieving latest commit from: %q ...\n", url) + r, err := git.NewMemoryRepository() if err != nil { panic(err) } - if err = r.Pull(git.DefaultRemoteName, "refs/heads/master"); err != nil { + if err = r.Clone(&git.CloneOptions{URL: url}); err != nil { + panic(err) + } + + head, err := r.Head() + if err != nil { panic(err) } - head := r.Remotes[git.DefaultRemoteName].Head() commit, err := r.Commit(head.Hash()) if err != nil { panic(err) diff --git a/repository.go b/repository.go index f286e03..6f2679c 100644 --- a/repository.go +++ b/repository.go @@ -5,7 +5,9 @@ import ( "gopkg.in/src-d/go-git.v4/clients/common" "gopkg.in/src-d/go-git.v4/core" + "gopkg.in/src-d/go-git.v4/storage/filesystem" "gopkg.in/src-d/go-git.v4/storage/memory" + "gopkg.in/src-d/go-git.v4/utils/fs" ) var ( @@ -32,6 +34,16 @@ func NewMemoryRepository() (*Repository, error) { return NewRepository(memory.NewStorage()) } +// NewFilesystemRepository creates a new repository, backed by a filesystem.Storage +func NewFilesystemRepository(fs fs.FS, path string) (*Repository, error) { + s, err := filesystem.NewStorage(fs, path) + if err != nil { + return nil, err + } + + return NewRepository(s) +} + // NewRepository creates a new repository with the given Storage func NewRepository(s core.Storage) (*Repository, error) { os, err := s.ObjectStorage() diff --git a/utils/difftree/difftree_test.go b/utils/difftree/difftree_test.go index 558d64d..b13c228 100644 --- a/utils/difftree/difftree_test.go +++ b/utils/difftree/difftree_test.go @@ -43,14 +43,16 @@ func (s *DiffTreeSuite) SetUpSuite(c *C) { s.repos = make(map[string]*git.Repository, 0) for _, fixRepo := range fixtureRepos { - s.repos[fixRepo.url] = git.NewPlainRepository() + s.repos[fixRepo.url], _ = git.NewMemoryRepository() f, err := os.Open(fixRepo.packfile) c.Assert(err, IsNil) r := packfile.NewSeekable(f) d := packfile.NewDecoder(r) - err = d.Decode(s.repos[fixRepo.url].Storage) + + os, _ := s.repos[fixRepo.url].Storage.ObjectStorage() + err = d.Decode(os) c.Assert(err, IsNil) c.Assert(f.Close(), IsNil) diff --git a/utils/fs/os_test.go b/utils/fs/os_test.go index a2a3066..b6c00c6 100644 --- a/utils/fs/os_test.go +++ b/utils/fs/os_test.go @@ -18,7 +18,7 @@ type FSImplSuite struct { var _ = Suite(&FSImplSuite{}) func (s *FSImplSuite) SetUpSuite(c *C) { - dir, err := tgz.Extract("../../storage/filesystem/internal/gitdir/fixtures/spinnaker-gc.tgz") + dir, err := tgz.Extract("../../storage/filesystem/internal/dotgit/fixtures/spinnaker-gc.tgz") c.Assert(err, IsNil) s.dir = dir } |