diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2016-12-02 00:44:06 +0100 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2016-12-02 00:44:06 +0100 |
commit | 6996381ae43936e7365395e90c8f93372e49be9f (patch) | |
tree | ed0d9441157a62230b0b9ca57ef600fd2ba99f76 | |
parent | c15bf1dff332873644290db0e186b8f5ad9b8fb2 (diff) | |
download | go-git-6996381ae43936e7365395e90c8f93372e49be9f.tar.gz |
BaseSuite improvements, usage of file:// proto
-rw-r--r-- | blame_test.go | 42 | ||||
-rw-r--r-- | commit_test.go | 4 | ||||
-rw-r--r-- | common_test.go | 190 | ||||
-rw-r--r-- | file_test.go | 17 | ||||
-rw-r--r-- | fixtures/fixtures.go | 18 | ||||
-rw-r--r-- | plumbing/format/index/decoder_test.go | 30 | ||||
-rw-r--r-- | plumbing/format/index/encoder_test.go | 8 | ||||
-rw-r--r-- | references_test.go | 26 | ||||
-rw-r--r-- | remote.go | 6 | ||||
-rw-r--r-- | remote_test.go | 68 | ||||
-rw-r--r-- | repository_test.go | 87 | ||||
-rw-r--r-- | tag_test.go | 48 | ||||
-rw-r--r-- | tree_diff_test.go | 376 |
13 files changed, 379 insertions, 541 deletions
diff --git a/blame_test.go b/blame_test.go index 53f2271..f4203b8 100644 --- a/blame_test.go +++ b/blame_test.go @@ -20,12 +20,24 @@ type blameTest struct { blames []string // the commits blamed for each line } -func (s *BlameSuite) mockBlame(t blameTest, c *C) (blame *Blame) { - r, ok := s.Repositories[t.repo] - c.Assert(ok, Equals, true) +// run a blame on all the suite's tests +func (s *BlameSuite) TestBlame(c *C) { + for _, t := range blameTests { + r := s.NewRepositoryFromPackfile(fixtures.ByURL(t.repo).One()) + + exp := s.mockBlame(c, t, r) + commit, err := r.Commit(plumbing.NewHash(t.rev)) + c.Assert(err, IsNil) + + obt, err := commit.Blame(t.path) + c.Assert(err, IsNil) + c.Assert(obt, DeepEquals, exp) + } +} +func (s *BlameSuite) mockBlame(c *C, t blameTest, r *Repository) (blame *Blame) { commit, err := r.Commit(plumbing.NewHash(t.rev)) - c.Assert(err, IsNil, Commentf("%v: repo=%s, rev=%s", err, r, t.rev)) + c.Assert(err, IsNil, Commentf("%v: repo=%s, rev=%s", err, t.repo, t.rev)) f, err := commit.File(t.path) c.Assert(err, IsNil) @@ -52,28 +64,6 @@ func (s *BlameSuite) mockBlame(t blameTest, c *C) (blame *Blame) { } } -func (s *BlameSuite) SetUpSuite(c *C) { - s.BaseSuite.SetUpSuite(c) - s.buildRepositories(c, fixtures.ByTag("packfile")) -} - -// run a blame on all the suite's tests -func (s *BlameSuite) TestBlame(c *C) { - for _, t := range blameTests { - exp := s.mockBlame(t, c) - - r, ok := s.Repositories[t.repo] - c.Assert(ok, Equals, true) - - commit, err := r.Commit(plumbing.NewHash(t.rev)) - c.Assert(err, IsNil) - - obt, err := commit.Blame(t.path) - c.Assert(err, IsNil) - c.Assert(obt, DeepEquals, exp) - } -} - // utility function to avoid writing so many repeated commits func repeat(s string, n int) []string { if n < 0 { diff --git a/commit_test.go b/commit_test.go index 40e8973..ed240e8 100644 --- a/commit_test.go +++ b/commit_test.go @@ -132,9 +132,9 @@ func (s *SuiteCommit) TestString(c *C) { func (s *SuiteCommit) TestStringMultiLine(c *C) { hash := plumbing.NewHash("e7d896db87294e33ca3202e536d4d9bb16023db3") - s.buildRepositories(c, fixtures.ByURL("https://github.com/src-d/go-git.git")) + r := s.NewRepositoryFromPackfile(fixtures.ByURL("https://github.com/src-d/go-git.git").One()) - commit, err := s.Repositories["https://github.com/src-d/go-git.git"].Commit(hash) + commit, err := r.Commit(hash) c.Assert(err, IsNil) c.Assert(commit.String(), Equals, ""+ diff --git a/common_test.go b/common_test.go index 3aa3693..2dabf6b 100644 --- a/common_test.go +++ b/common_test.go @@ -2,18 +2,11 @@ package git import ( "fmt" - "io" - "os" "testing" "gopkg.in/src-d/go-git.v4/fixtures" - "gopkg.in/src-d/go-git.v4/plumbing" "gopkg.in/src-d/go-git.v4/plumbing/format/packfile" - "gopkg.in/src-d/go-git.v4/plumbing/protocol/packp" - "gopkg.in/src-d/go-git.v4/plumbing/protocol/packp/capability" - "gopkg.in/src-d/go-git.v4/plumbing/transport" "gopkg.in/src-d/go-git.v4/plumbing/transport/client" - "gopkg.in/src-d/go-git.v4/storage/filesystem" . "gopkg.in/check.v1" ) @@ -22,159 +15,71 @@ func Test(t *testing.T) { TestingT(t) } type BaseSuite struct { fixtures.Suite + Repository *Repository - Repository *Repository - Repositories map[string]*Repository + cache map[string]*Repository } func (s *BaseSuite) SetUpSuite(c *C) { s.Suite.SetUpSuite(c) s.installMockProtocol(c) - s.buildRepository(c) + s.buildBasicRepository(c) - s.Repositories = make(map[string]*Repository, 0) - s.buildRepositories(c, fixtures.Basic().ByTag("packfile")) + s.cache = make(map[string]*Repository, 0) } -func (s *BaseSuite) installMockProtocol(c *C) { - client.InstallProtocol("https", &MockClient{}) -} - -func (s *BaseSuite) buildRepository(c *C) { +func (s *BaseSuite) buildBasicRepository(c *C) { f := fixtures.Basic().One() - - var err error - s.Repository, err = NewFilesystemRepository(f.DotGit().Base()) - c.Assert(err, IsNil) + s.Repository = s.NewRepository(f) } -func (s *BaseSuite) buildRepositories(c *C, f fixtures.Fixtures) { - for _, fixture := range f { - r := NewMemoryRepository() - - f := fixture.Packfile() - defer f.Close() - - n := packfile.NewScanner(f) - d, err := packfile.NewDecoder(n, r.s) - c.Assert(err, IsNil) - _, err = d.Decode() - c.Assert(err, IsNil) - - s.Repositories[fixture.URL] = r +func (s *BaseSuite) NewRepository(f *fixtures.Fixture) *Repository { + r, err := NewFilesystemRepository(f.DotGit().Base()) + if err != nil { + panic(err) } -} - -const RepositoryFixture = "https://github.com/git-fixtures/basic.git" - -type MockClient struct{} - -type MockFetchPackSession struct { - endpoint transport.Endpoint - auth transport.AuthMethod -} - -func (c *MockClient) NewFetchPackSession(ep transport.Endpoint) ( - transport.FetchPackSession, error) { - return &MockFetchPackSession{ - endpoint: ep, - auth: nil, - }, nil -} - -func (c *MockClient) NewSendPackSession(ep transport.Endpoint) ( - transport.SendPackSession, error) { - - return nil, fmt.Errorf("not supported") -} - -func (c *MockFetchPackSession) SetAuth(auth transport.AuthMethod) error { - c.auth = auth - return nil + return r } -func (c *MockFetchPackSession) AdvertisedReferences() (*packp.AdvRefs, error) { - - h := fixtures.ByURL(c.endpoint.String()).One().Head - - cap := capability.NewList() - cap.Set(capability.Agent, "go-git/tests") - - ref := plumbing.ReferenceName("refs/heads/master") - branch := plumbing.ReferenceName("refs/heads/branch") - tag := plumbing.ReferenceName("refs/tags/v1.0.0") - - a := packp.NewAdvRefs() - a.Capabilities = cap - a.Head = &h - a.AddReference(plumbing.NewSymbolicReference(plumbing.HEAD, ref)) - a.AddReference(plumbing.NewHashReference(ref, h)) - a.AddReference(plumbing.NewHashReference(tag, h)) - a.AddReference(plumbing.NewHashReference(branch, plumbing.NewHash("e8d3ffab552895c19b9fcf7aa264d277cde33881"))) +func (s *BaseSuite) NewRepositoryFromPackfile(f *fixtures.Fixture) *Repository { + h := f.PackfileHash.String() + if r, ok := s.cache[h]; ok { + return r + } - return a, nil -} + r := NewMemoryRepository() -func (c *MockFetchPackSession) FetchPack( - r *packp.UploadPackRequest) (io.ReadCloser, error) { + p := f.Packfile() + defer p.Close() - if !r.Capabilities.Supports(capability.Agent) { - return nil, fmt.Errorf("" + - "invalid test rquest, missing Agent capability, the request" + - "should be created using NewUploadPackRequestFromCapabilities", - ) + n := packfile.NewScanner(p) + d, err := packfile.NewDecoder(n, r.s) + if err != nil { + panic(err) } - f := fixtures.ByURL(c.endpoint.String()) - - if len(r.Wants) == 1 { - return f.Exclude("single-branch").One().Packfile(), nil + _, err = d.Decode() + if err != nil { + panic(err) } - return f.One().Packfile(), nil -} - -func (c *MockFetchPackSession) Close() error { - return nil + s.cache[h] = r + return r } -type packedFixture struct { - url string - packfile string +func (s *BaseSuite) installMockProtocol(c *C) { + client.InstallProtocol("https", nil) } -var fixtureRepos = []packedFixture{ - {"https://github.com/tyba/git-fixture.git", "formats/packfile/fixtures/git-fixture.ofs-delta"}, - {"https://github.com/jamesob/desk.git", "formats/packfile/fixtures/jamesob-desk.pack"}, - {"https://github.com/spinnaker/spinnaker.git", "formats/packfile/fixtures/spinnaker-spinnaker.pack"}, +func (s *BaseSuite) GetBasicLocalRepositoryURL() string { + fixture := fixtures.Basic().One() + return s.GetLocalRepositoryURL(fixture) } -func unpackFixtures(c *C, fixtures ...[]packedFixture) map[string]*Repository { - repos := make(map[string]*Repository, 0) - for _, group := range fixtures { - for _, fixture := range group { - if _, existing := repos[fixture.url]; existing { - continue - } - - comment := Commentf("fixture packfile: %q", fixture.packfile) - - repos[fixture.url] = NewMemoryRepository() - - f, err := os.Open(fixture.packfile) - c.Assert(err, IsNil, comment) - - r := packfile.NewScanner(f) - d, err := packfile.NewDecoder(r, repos[fixture.url].s) - c.Assert(err, IsNil, comment) - _, err = d.Decode() - c.Assert(err, IsNil, comment) - c.Assert(f.Close(), IsNil, comment) - } - } - - return repos +func (s *BaseSuite) GetLocalRepositoryURL(f *fixtures.Fixture) string { + path := f.DotGit().Base() + return fmt.Sprintf("file://%s", path) } type SuiteCommon struct{} @@ -202,26 +107,3 @@ func (s *SuiteCommon) TestCountLines(c *C) { c.Assert(o, Equals, t.e, Commentf("subtest %d, input=%q", i, t.i)) } } - -func (s *BaseSuite) Clone(url string) *Repository { - r := NewMemoryRepository() - if err := r.Clone(&CloneOptions{URL: url}); err != nil { - panic(err) - } - - return r -} - -func (s *BaseSuite) NewRepository(f *fixtures.Fixture) *Repository { - storage, err := filesystem.NewStorage(f.DotGit()) - if err != nil { - panic(err) - } - - r, err := NewRepository(storage) - if err != nil { - panic(err) - } - - return r -} diff --git a/file_test.go b/file_test.go index ca815c2..a7067f3 100644 --- a/file_test.go +++ b/file_test.go @@ -26,7 +26,6 @@ var fileIterTests = []struct { commit string // the commit to search for the file files []fileIterExpectedEntry }{ - // https://api.github.com/repos/tyba/git-fixture/git/trees/6ecf0ef2c2dffb796033e5a02219af86ec6584e5 {"https://github.com/git-fixtures/basic.git", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", []fileIterExpectedEntry{ {".gitignore", "32858aad3c383ed1ff0a0f9bdf231d54a00c9e88"}, {"CHANGELOG", "d3ff53e0564a9f87d8e84b6e28e5060e517008aa"}, @@ -42,14 +41,14 @@ var fileIterTests = []struct { func (s *FileSuite) TestIter(c *C) { for i, t := range fileIterTests { - r := s.Repositories[t.repo] + r := s.NewRepository(fixtures.ByURL(t.repo).One()) commit, err := r.Commit(plumbing.NewHash(t.commit)) c.Assert(err, IsNil, Commentf("subtest %d: %v (%s)", i, err, t.commit)) tree, err := commit.Tree() c.Assert(err, IsNil) - iter := NewFileIter(r, tree) + iter := NewFileIter(s.Repository, tree) for k := 0; k < len(t.files); k++ { exp := t.files[k] file, err := iter.Next() @@ -100,7 +99,8 @@ hs_err_pid* func (s *FileSuite) TestContents(c *C) { for i, t := range contentsTests { - commit, err := s.Repositories[t.repo].Commit(plumbing.NewHash(t.commit)) + r := s.NewRepository(fixtures.ByURL(t.repo).One()) + commit, err := r.Commit(plumbing.NewHash(t.commit)) c.Assert(err, IsNil, Commentf("subtest %d: %v (%s)", i, err, t.commit)) file, err := commit.File(t.path) @@ -149,9 +149,7 @@ var linesTests = []struct { func (s *FileSuite) TestLines(c *C) { for i, t := range linesTests { - r, ok := s.Repositories[t.repo] - c.Assert(ok, Equals, true, Commentf("cannot find repository %s", t.repo)) - + r := s.NewRepository(fixtures.ByURL(t.repo).One()) commit, err := r.Commit(plumbing.NewHash(t.commit)) c.Assert(err, IsNil, Commentf("subtest %d: %v (%s)", i, err, t.commit)) @@ -181,10 +179,9 @@ var ignoreEmptyDirEntriesTests = []struct { // At least this test has a high chance of panicking if // we don't ignore empty dirs. func (s *FileSuite) TestIgnoreEmptyDirEntries(c *C) { - s.buildRepositories(c, fixtures.ByTag("empty-folder")) - for i, t := range ignoreEmptyDirEntriesTests { - commit, err := s.Repositories[t.repo].Commit(plumbing.NewHash(t.commit)) + r := s.NewRepository(fixtures.ByURL(t.repo).One()) + commit, err := r.Commit(plumbing.NewHash(t.commit)) c.Assert(err, IsNil, Commentf("subtest %d: %v (%s)", i, err, t.commit)) tree, err := commit.Tree() diff --git a/fixtures/fixtures.go b/fixtures/fixtures.go index 4e5e2bb..503f2ea 100644 --- a/fixtures/fixtures.go +++ b/fixtures/fixtures.go @@ -18,14 +18,14 @@ var RootFolder = "" const DataFolder = "data" -var folders []string +var folders = make(map[string]string, 0) var fixtures = Fixtures{{ Tags: []string{"packfile", "ofs-delta", ".git"}, URL: "https://github.com/git-fixtures/basic.git", Head: plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"), PackfileHash: plumbing.NewHash("a3fed42da1e8189a077c0e6846c040dcf73fc9dd"), - DotGitHash: plumbing.NewHash("0a00a25543e6d732dbf4e8e9fec55c8e65fc4e8d"), + DotGitHash: plumbing.NewHash("7a725350b88b05ca03541b59dd0649fda7f521f2"), ObjectsCount: 31, }, { Tags: []string{"packfile", "ref-delta", ".git"}, @@ -87,6 +87,7 @@ var fixtures = Fixtures{{ URL: "https://github.com/cpcs499/Final_Pres_P.git", Head: plumbing.NewHash("70bade703ce556c2c7391a8065c45c943e8b6bc3"), PackfileHash: plumbing.NewHash("29f304662fd64f102d94722cf5bd8802d9a9472c"), + DotGitHash: plumbing.NewHash("e1580a78f7d36791249df76df8a2a2613d629902"), }, { Tags: []string{"packfile", "diff-tree"}, URL: "https://github.com/github/gem-builder.git", @@ -179,15 +180,18 @@ func (f *Fixture) Idx() *os.File { } func (f *Fixture) DotGit() fs.Filesystem { + h := f.DotGitHash.String() + if path, ok := folders[h]; ok { + return osfs.New(path) + } + fn := filepath.Join(RootFolder, DataFolder, fmt.Sprintf("git-%s.tgz", f.DotGitHash)) path, err := tgz.Extract(fn) if err != nil { - fmt.Println(os.Getwd()) - fmt.Println(filepath.Clean(fn)) panic(err) } - folders = append(folders, path) + folders[h] = path return osfs.New(path) } @@ -246,8 +250,10 @@ func (s *Suite) SetUpSuite(c *check.C) { } func (s *Suite) TearDownSuite(c *check.C) { - for _, f := range folders { + for hash, f := range folders { err := os.RemoveAll(f) c.Assert(err, check.IsNil) + + delete(folders, hash) } } diff --git a/plumbing/format/index/decoder_test.go b/plumbing/format/index/decoder_test.go index 44ecb69..4614701 100644 --- a/plumbing/format/index/decoder_test.go +++ b/plumbing/format/index/decoder_test.go @@ -10,13 +10,13 @@ import ( func Test(t *testing.T) { TestingT(t) } -type IdxfileSuite struct { +type IndexSuite struct { fixtures.Suite } -var _ = Suite(&IdxfileSuite{}) +var _ = Suite(&IndexSuite{}) -func (s *IdxfileSuite) TestDecode(c *C) { +func (s *IndexSuite) TestDecode(c *C) { f, err := fixtures.Basic().One().DotGit().Open("index") c.Assert(err, IsNil) @@ -29,7 +29,7 @@ func (s *IdxfileSuite) TestDecode(c *C) { c.Assert(idx.Entries, HasLen, 9) } -func (s *IdxfileSuite) TestDecodeEntries(c *C) { +func (s *IndexSuite) TestDecodeEntries(c *C) { f, err := fixtures.Basic().One().DotGit().Open("index") c.Assert(err, IsNil) @@ -41,12 +41,12 @@ func (s *IdxfileSuite) TestDecodeEntries(c *C) { c.Assert(idx.Entries, HasLen, 9) e := idx.Entries[0] - c.Assert(e.CreatedAt.Unix(), Equals, int64(1473350251)) - c.Assert(e.CreatedAt.Nanosecond(), Equals, 12059307) - c.Assert(e.ModifiedAt.Unix(), Equals, int64(1473350251)) - c.Assert(e.ModifiedAt.Nanosecond(), Equals, 12059307) - c.Assert(e.Dev, Equals, uint32(38)) - c.Assert(e.Inode, Equals, uint32(1715795)) + c.Assert(e.CreatedAt.Unix(), Equals, int64(1480626693)) + c.Assert(e.CreatedAt.Nanosecond(), Equals, 498593596) + c.Assert(e.ModifiedAt.Unix(), Equals, int64(1480626693)) + c.Assert(e.ModifiedAt.Nanosecond(), Equals, 498593596) + c.Assert(e.Dev, Equals, uint32(39)) + c.Assert(e.Inode, Equals, uint32(140626)) c.Assert(e.UID, Equals, uint32(1000)) c.Assert(e.GID, Equals, uint32(100)) c.Assert(e.Size, Equals, uint32(189)) @@ -58,7 +58,7 @@ func (s *IdxfileSuite) TestDecodeEntries(c *C) { c.Assert(e.Name, Equals, "CHANGELOG") } -func (s *IdxfileSuite) TestDecodeCacheTree(c *C) { +func (s *IndexSuite) TestDecodeCacheTree(c *C) { f, err := fixtures.Basic().One().DotGit().Open("index") c.Assert(err, IsNil) @@ -87,7 +87,7 @@ var expectedEntries = []TreeEntry{ {Path: "vendor", Entries: 1, Trees: 0, Hash: plumbing.NewHash("cf4aa3b38974fb7d81f367c0830f7d78d65ab86b")}, } -func (s *IdxfileSuite) TestDecodeMergeConflict(c *C) { +func (s *IndexSuite) TestDecodeMergeConflict(c *C) { f, err := fixtures.Basic().ByTag("merge-conflict").One().DotGit().Open("index") c.Assert(err, IsNil) @@ -126,7 +126,7 @@ func (s *IdxfileSuite) TestDecodeMergeConflict(c *C) { } -func (s *IdxfileSuite) TestDecodeExtendedV3(c *C) { +func (s *IndexSuite) TestDecodeExtendedV3(c *C) { f, err := fixtures.Basic().ByTag("intent-to-add").One().DotGit().Open("index") c.Assert(err, IsNil) @@ -143,7 +143,7 @@ func (s *IdxfileSuite) TestDecodeExtendedV3(c *C) { c.Assert(idx.Entries[6].SkipWorktree, Equals, false) } -func (s *IdxfileSuite) TestDecodeResolveUndo(c *C) { +func (s *IndexSuite) TestDecodeResolveUndo(c *C) { f, err := fixtures.Basic().ByTag("resolve-undo").One().DotGit().Open("index") c.Assert(err, IsNil) @@ -168,7 +168,7 @@ func (s *IdxfileSuite) TestDecodeResolveUndo(c *C) { c.Assert(ru.Entries[1].Stages[TheirMode], Not(Equals), plumbing.ZeroHash) } -func (s *IdxfileSuite) TestDecodeV4(c *C) { +func (s *IndexSuite) TestDecodeV4(c *C) { f, err := fixtures.Basic().ByTag("index-v4").One().DotGit().Open("index") c.Assert(err, IsNil) diff --git a/plumbing/format/index/encoder_test.go b/plumbing/format/index/encoder_test.go index 6770985..28cbd1f 100644 --- a/plumbing/format/index/encoder_test.go +++ b/plumbing/format/index/encoder_test.go @@ -9,7 +9,7 @@ import ( "gopkg.in/src-d/go-git.v4/plumbing" ) -func (s *IdxfileSuite) TestEncode(c *C) { +func (s *IndexSuite) TestEncode(c *C) { idx := &Index{ Version: 2, Entries: []Entry{{ @@ -44,7 +44,7 @@ func (s *IdxfileSuite) TestEncode(c *C) { c.Assert(idx, DeepEquals, output) } -func (s *IdxfileSuite) TestEncodeUnsuportedVersion(c *C) { +func (s *IndexSuite) TestEncodeUnsuportedVersion(c *C) { idx := &Index{Version: 3} buf := bytes.NewBuffer(nil) @@ -53,7 +53,7 @@ func (s *IdxfileSuite) TestEncodeUnsuportedVersion(c *C) { c.Assert(err, Equals, ErrUnsupportedVersion) } -func (s *IdxfileSuite) TestEncodeWithIntentToAddUnsuportedVersion(c *C) { +func (s *IndexSuite) TestEncodeWithIntentToAddUnsuportedVersion(c *C) { idx := &Index{ Version: 2, Entries: []Entry{{IntentToAdd: true}}, @@ -65,7 +65,7 @@ func (s *IdxfileSuite) TestEncodeWithIntentToAddUnsuportedVersion(c *C) { c.Assert(err, Equals, ErrUnsupportedVersion) } -func (s *IdxfileSuite) TestEncodeWithSkipWorktreeUnsuportedVersion(c *C) { +func (s *IndexSuite) TestEncodeWithSkipWorktreeUnsuportedVersion(c *C) { idx := &Index{ Version: 2, Entries: []Entry{{SkipWorktree: true}}, diff --git a/references_test.go b/references_test.go index f5a2fdc..2147f49 100644 --- a/references_test.go +++ b/references_test.go @@ -286,17 +286,11 @@ var referencesTests = [...]struct { */ } -func (s *ReferencesSuite) SetUpSuite(c *C) { - s.BaseSuite.SetUpSuite(c) - s.buildRepositories(c, fixtures.All().ByTag("packfile")) -} - func (s *ReferencesSuite) TestRevList(c *C) { for _, t := range referencesTests { - repo, ok := s.Repositories[t.repo] - c.Assert(ok, Equals, true) + r := s.NewRepositoryFromPackfile(fixtures.ByURL(t.repo).One()) - commit, err := repo.Commit(plumbing.NewHash(t.commit)) + commit, err := r.Commit(plumbing.NewHash(t.commit)) c.Assert(err, IsNil) revs, err := commit.References(t.path) @@ -305,7 +299,7 @@ func (s *ReferencesSuite) TestRevList(c *C) { for i := range revs { if revs[i].Hash.String() != t.revs[i] { - commit, err := repo.Commit(plumbing.NewHash(t.revs[i])) + commit, err := s.Repository.Commit(plumbing.NewHash(t.revs[i])) c.Assert(err, IsNil) equiv, err := equivalent(t.path, revs[i], commit) c.Assert(err, IsNil) @@ -358,14 +352,16 @@ func (s *ReferencesSuite) TestEquivalent(c *C) { } // returns the commits from a slice of hashes -func (s *ReferencesSuite) commits(cc *C, repo string, hs ...string) []*Commit { - r, ok := s.Repositories[repo] - cc.Assert(ok, Equals, true) +func (s *ReferencesSuite) commits(c *C, repo string, hs ...string) []*Commit { + r := s.NewRepositoryFromPackfile(fixtures.ByURL(repo).One()) + result := make([]*Commit, 0, len(hs)) for _, h := range hs { - c, err := r.Commit(plumbing.NewHash(h)) - cc.Assert(err, IsNil) - result = append(result, c) + commit, err := r.Commit(plumbing.NewHash(h)) + c.Assert(err, IsNil) + + result = append(result, commit) } + return result } @@ -172,7 +172,11 @@ func (r *Remote) buildRequest( s storer.ReferenceStorer, o *FetchOptions, refs []*plumbing.Reference, ) (*packp.UploadPackRequest, error) { req := packp.NewUploadPackRequestFromCapabilities(r.advRefs.Capabilities) - req.Depth = packp.DepthCommits(o.Depth) + + if o.Depth != 0 { + req.Depth = packp.DepthCommits(o.Depth) + req.Capabilities.Set(capability.Shallow) + } for _, ref := range refs { req.Wants = append(req.Wants, ref.Hash()) diff --git a/remote_test.go b/remote_test.go index 365e118..7c714e9 100644 --- a/remote_test.go +++ b/remote_test.go @@ -11,6 +11,7 @@ import ( "gopkg.in/src-d/go-git.v4/config" "gopkg.in/src-d/go-git.v4/plumbing" + "gopkg.in/src-d/go-git.v4/plumbing/protocol/packp/capability" "gopkg.in/src-d/go-git.v4/plumbing/storer" "gopkg.in/src-d/go-git.v4/plumbing/transport/client" githttp "gopkg.in/src-d/go-git.v4/plumbing/transport/http" @@ -19,11 +20,8 @@ import ( osfs "gopkg.in/src-d/go-git.v4/utils/fs/os" . "gopkg.in/check.v1" - "gopkg.in/src-d/go-git.v4/plumbing/protocol/packp/capability" ) -const FixRefSpec = config.RefSpec("+refs/heads/*:refs/remotes/origin/*") - type RemoteSuite struct { BaseSuite } @@ -31,7 +29,8 @@ type RemoteSuite struct { var _ = Suite(&RemoteSuite{}) func (s *RemoteSuite) TestConnect(c *C) { - r := newRemote(nil, &config.RemoteConfig{Name: "foo", URL: RepositoryFixture}) + url := s.GetBasicLocalRepositoryURL() + r := newRemote(nil, &config.RemoteConfig{Name: "foo", URL: url}) err := r.Connect() c.Assert(err, IsNil) @@ -52,9 +51,8 @@ func (s *RemoteSuite) TestnewRemoteInvalidSchemaEndpoint(c *C) { } func (s *RemoteSuite) TestInfo(c *C) { - r := newRemote(nil, &config.RemoteConfig{Name: "foo", URL: RepositoryFixture}) - r.client = &MockClient{} - + url := s.GetBasicLocalRepositoryURL() + r := newRemote(nil, &config.RemoteConfig{Name: "foo", URL: url}) c.Assert(r.AdvertisedReferences(), IsNil) c.Assert(r.Connect(), IsNil) c.Assert(r.AdvertisedReferences(), NotNil) @@ -62,30 +60,28 @@ func (s *RemoteSuite) TestInfo(c *C) { } func (s *RemoteSuite) TestDefaultBranch(c *C) { - r := newRemote(nil, &config.RemoteConfig{Name: "foo", URL: RepositoryFixture}) - r.client = &MockClient{} - + url := s.GetBasicLocalRepositoryURL() + r := newRemote(nil, &config.RemoteConfig{Name: "foo", URL: url}) c.Assert(r.Connect(), IsNil) c.Assert(r.Head().Name(), Equals, plumbing.ReferenceName("refs/heads/master")) } func (s *RemoteSuite) TestCapabilities(c *C) { - r := newRemote(nil, &config.RemoteConfig{Name: "foo", URL: RepositoryFixture}) - r.client = &MockClient{} - + url := s.GetBasicLocalRepositoryURL() + r := newRemote(nil, &config.RemoteConfig{Name: "foo", URL: url}) c.Assert(r.Connect(), IsNil) c.Assert(r.Capabilities().Get(capability.Agent), HasLen, 1) } func (s *RemoteSuite) TestFetch(c *C) { + url := s.GetBasicLocalRepositoryURL() sto := memory.NewStorage() - r := newRemote(sto, &config.RemoteConfig{Name: "foo", URL: RepositoryFixture}) - r.client = &MockClient{} - + r := newRemote(sto, &config.RemoteConfig{Name: "foo", URL: url}) c.Assert(r.Connect(), IsNil) + refspec := config.RefSpec("+refs/heads/*:refs/remotes/origin/*") err := r.Fetch(&FetchOptions{ - RefSpecs: []config.RefSpec{FixRefSpec}, + RefSpecs: []config.RefSpec{refspec}, }) c.Assert(err, IsNil) @@ -94,7 +90,6 @@ func (s *RemoteSuite) TestFetch(c *C) { expectedRefs := []*plumbing.Reference{ plumbing.NewReferenceFromStrings("refs/remotes/origin/master", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5"), plumbing.NewReferenceFromStrings("refs/remotes/origin/branch", "e8d3ffab552895c19b9fcf7aa264d277cde33881"), - plumbing.NewReferenceFromStrings("refs/tags/v1.0.0", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5"), } for _, exp := range expectedRefs { @@ -114,6 +109,7 @@ func (m *mockPackfileWriter) PackfileWriter() (io.WriteCloser, error) { } func (s *RemoteSuite) TestFetchWithPackfileWriter(c *C) { + dir, err := ioutil.TempDir("", "fetch") c.Assert(err, IsNil) @@ -124,13 +120,13 @@ func (s *RemoteSuite) TestFetchWithPackfileWriter(c *C) { mock := &mockPackfileWriter{Storer: fss} - r := newRemote(mock, &config.RemoteConfig{Name: "foo", URL: RepositoryFixture}) - r.client = &MockClient{} - + url := s.GetBasicLocalRepositoryURL() + r := newRemote(mock, &config.RemoteConfig{Name: "foo", URL: url}) c.Assert(r.Connect(), IsNil) + refspec := config.RefSpec("+refs/heads/*:refs/remotes/origin/*") err = r.Fetch(&FetchOptions{ - RefSpecs: []config.RefSpec{FixRefSpec}, + RefSpecs: []config.RefSpec{refspec}, }) c.Assert(err, IsNil) @@ -149,14 +145,14 @@ func (s *RemoteSuite) TestFetchWithPackfileWriter(c *C) { } func (s *RemoteSuite) TestFetchNoErrAlreadyUpToDate(c *C) { + url := s.GetBasicLocalRepositoryURL() sto := memory.NewStorage() - r := newRemote(sto, &config.RemoteConfig{Name: "foo", URL: RepositoryFixture}) - r.client = &MockClient{} - + r := newRemote(sto, &config.RemoteConfig{Name: "foo", URL: url}) c.Assert(r.Connect(), IsNil) + refspec := config.RefSpec("+refs/heads/*:refs/remotes/origin/*") o := &FetchOptions{ - RefSpecs: []config.RefSpec{FixRefSpec}, + RefSpecs: []config.RefSpec{refspec}, } err := r.Fetch(o) @@ -166,8 +162,8 @@ func (s *RemoteSuite) TestFetchNoErrAlreadyUpToDate(c *C) { } func (s *RemoteSuite) TestHead(c *C) { - r := newRemote(nil, &config.RemoteConfig{Name: "foo", URL: RepositoryFixture}) - r.client = &MockClient{} + url := s.GetBasicLocalRepositoryURL() + r := newRemote(nil, &config.RemoteConfig{Name: "foo", URL: url}) err := r.Connect() c.Assert(err, IsNil) @@ -175,9 +171,8 @@ func (s *RemoteSuite) TestHead(c *C) { } func (s *RemoteSuite) TestRef(c *C) { - r := newRemote(nil, &config.RemoteConfig{Name: "foo", URL: RepositoryFixture}) - r.client = &MockClient{} - + url := s.GetBasicLocalRepositoryURL() + r := newRemote(nil, &config.RemoteConfig{Name: "foo", URL: url}) err := r.Connect() c.Assert(err, IsNil) @@ -191,9 +186,8 @@ func (s *RemoteSuite) TestRef(c *C) { } func (s *RemoteSuite) TestRefs(c *C) { - r := newRemote(nil, &config.RemoteConfig{Name: "foo", URL: RepositoryFixture}) - r.client = &MockClient{} - + url := s.GetBasicLocalRepositoryURL() + r := newRemote(nil, &config.RemoteConfig{Name: "foo", URL: url}) err := r.Connect() c.Assert(err, IsNil) @@ -203,7 +197,11 @@ func (s *RemoteSuite) TestRefs(c *C) { } func (s *RemoteSuite) TestString(c *C) { - r := newRemote(nil, &config.RemoteConfig{Name: "foo", URL: RepositoryFixture}) + r := newRemote(nil, &config.RemoteConfig{ + Name: "foo", + URL: "https://github.com/git-fixtures/basic.git", + }) + c.Assert(r.String(), Equals, ""+ "foo\thttps://github.com/git-fixtures/basic.git (fetch)\n"+ "foo\thttps://github.com/git-fixtures/basic.git (push)", diff --git a/repository_test.go b/repository_test.go index dbcc232..11fa5c5 100644 --- a/repository_test.go +++ b/repository_test.go @@ -2,6 +2,7 @@ package git import ( "gopkg.in/src-d/go-git.v4/config" + "gopkg.in/src-d/go-git.v4/fixtures" "gopkg.in/src-d/go-git.v4/plumbing" "gopkg.in/src-d/go-git.v4/storage/memory" @@ -68,7 +69,7 @@ func (s *RepositorySuite) TestClone(c *C) { c.Assert(head, IsNil) err = r.Clone(&CloneOptions{ - URL: RepositoryFixture, + URL: s.GetBasicLocalRepositoryURL(), }) c.Assert(err, IsNil) @@ -93,12 +94,6 @@ func (s *RepositorySuite) TestClone(c *C) { c.Assert(branch, NotNil) c.Assert(branch.Type(), Equals, plumbing.HashReference) c.Assert(branch.Hash().String(), Equals, "6ecf0ef2c2dffb796033e5a02219af86ec6584e5") - - branch, err = r.Ref("refs/remotes/origin/branch", false) - c.Assert(err, IsNil) - c.Assert(branch, NotNil) - c.Assert(branch.Type(), Equals, plumbing.HashReference) - c.Assert(branch.Hash().String(), Equals, "e8d3ffab552895c19b9fcf7aa264d277cde33881") } func (s *RepositorySuite) TestCloneNonEmpty(c *C) { @@ -108,7 +103,7 @@ func (s *RepositorySuite) TestCloneNonEmpty(c *C) { c.Assert(err, Equals, plumbing.ErrReferenceNotFound) c.Assert(head, IsNil) - o := &CloneOptions{URL: RepositoryFixture} + o := &CloneOptions{URL: s.GetBasicLocalRepositoryURL()} err = r.Clone(o) c.Assert(err, IsNil) @@ -124,7 +119,7 @@ func (s *RepositorySuite) TestCloneSingleBranchAndNonHEAD(c *C) { c.Assert(head, IsNil) err = r.Clone(&CloneOptions{ - URL: RepositoryFixture, + URL: s.GetBasicLocalRepositoryURL(), ReferenceName: plumbing.ReferenceName("refs/heads/branch"), SingleBranch: true, }) @@ -161,7 +156,7 @@ func (s *RepositorySuite) TestCloneSingleBranch(c *C) { c.Assert(head, IsNil) err = r.Clone(&CloneOptions{ - URL: RepositoryFixture, + URL: s.GetBasicLocalRepositoryURL(), SingleBranch: true, }) @@ -192,7 +187,7 @@ func (s *RepositorySuite) TestCloneSingleBranch(c *C) { func (s *RepositorySuite) TestCloneDetachedHEAD(c *C) { r := NewMemoryRepository() err := r.Clone(&CloneOptions{ - URL: RepositoryFixture, + URL: s.GetBasicLocalRepositoryURL(), ReferenceName: plumbing.ReferenceName("refs/tags/v1.0.0"), }) @@ -203,10 +198,10 @@ func (s *RepositorySuite) TestCloneDetachedHEAD(c *C) { c.Assert(head.Hash().String(), Equals, "6ecf0ef2c2dffb796033e5a02219af86ec6584e5") } -func (s *RepositorySuite) TestPull(c *C) { +func (s *RepositorySuite) TestPullSingleBranch(c *C) { r := NewMemoryRepository() err := r.Clone(&CloneOptions{ - URL: RepositoryFixture, + URL: s.GetBasicLocalRepositoryURL(), SingleBranch: true, }) @@ -219,21 +214,34 @@ func (s *RepositorySuite) TestPull(c *C) { c.Assert(err, IsNil) c.Assert(branch.Hash().String(), Equals, "6ecf0ef2c2dffb796033e5a02219af86ec6584e5") + branch, err = r.Ref("refs/remotes/foo/branch", false) + c.Assert(err, NotNil) + storage := r.s.(*memory.Storage) - c.Assert(storage.Objects, HasLen, 31) + c.Assert(storage.Objects, HasLen, 28) +} + +func (s *RepositorySuite) TestPull(c *C) { + r := NewMemoryRepository() r.CreateRemote(&config.RemoteConfig{ Name: "foo", - URL: "https://github.com/git-fixtures/tags.git", + URL: s.GetBasicLocalRepositoryURL(), }) - err = r.Pull(&PullOptions{RemoteName: "foo"}) + err := r.Pull(&PullOptions{RemoteName: "foo"}) c.Assert(err, IsNil) - c.Assert(storage.Objects, HasLen, 38) - branch, err = r.Ref("refs/heads/master", false) + storage := r.s.(*memory.Storage) + c.Assert(storage.Objects, HasLen, 31) + + branch, err := r.Ref("refs/heads/master", false) + c.Assert(err, IsNil) + c.Assert(branch.Hash().String(), Equals, "6ecf0ef2c2dffb796033e5a02219af86ec6584e5") + + branch, err = r.Ref("refs/remotes/foo/branch", false) c.Assert(err, IsNil) - c.Assert(branch.Hash().String(), Equals, "f7b877701fbf855b44c0a9e86f3fdce2c298b07f") + c.Assert(branch.Hash().String(), Equals, "e8d3ffab552895c19b9fcf7aa264d277cde33881") } func (s *RepositorySuite) TestIsEmpty(c *C) { @@ -243,7 +251,7 @@ func (s *RepositorySuite) TestIsEmpty(c *C) { c.Assert(err, IsNil) c.Assert(empty, Equals, true) - err = r.Clone(&CloneOptions{URL: RepositoryFixture}) + err = r.Clone(&CloneOptions{URL: s.GetBasicLocalRepositoryURL()}) c.Assert(err, IsNil) empty, err = r.IsEmpty() @@ -254,7 +262,7 @@ func (s *RepositorySuite) TestIsEmpty(c *C) { func (s *RepositorySuite) TestCommit(c *C) { r := NewMemoryRepository() err := r.Clone(&CloneOptions{ - URL: RepositoryFixture, + URL: s.GetBasicLocalRepositoryURL(), }) c.Assert(err, IsNil) @@ -277,7 +285,7 @@ func (s *RepositorySuite) TestCommit(c *C) { func (s *RepositorySuite) TestCommits(c *C) { r := NewMemoryRepository() - err := r.Clone(&CloneOptions{URL: RepositoryFixture}) + err := r.Clone(&CloneOptions{URL: s.GetBasicLocalRepositoryURL()}) c.Assert(err, IsNil) count := 0 @@ -299,11 +307,15 @@ func (s *RepositorySuite) TestCommits(c *C) { } func (s *RepositorySuite) TestTag(c *C) { + url := s.GetLocalRepositoryURL( + fixtures.ByURL("https://github.com/git-fixtures/tags.git").One(), + ) + r := NewMemoryRepository() - err := r.Clone(&CloneOptions{URL: "https://github.com/spinnaker/spinnaker.git"}) + err := r.Clone(&CloneOptions{URL: url}) c.Assert(err, IsNil) - hash := plumbing.NewHash("0a3fb06ff80156fb153bcdcc58b5e16c2d27625c") + hash := plumbing.NewHash("ad7897c0fb8e7d9a9ba41fa66072cf06095a6cfc") tag, err := r.Tag(hash) c.Assert(err, IsNil) @@ -313,8 +325,12 @@ func (s *RepositorySuite) TestTag(c *C) { } func (s *RepositorySuite) TestTags(c *C) { + url := s.GetLocalRepositoryURL( + fixtures.ByURL("https://github.com/git-fixtures/tags.git").One(), + ) + r := NewMemoryRepository() - err := r.Clone(&CloneOptions{URL: "https://github.com/git-fixtures/tags.git"}) + err := r.Clone(&CloneOptions{URL: url}) c.Assert(err, IsNil) count := 0 @@ -323,9 +339,9 @@ func (s *RepositorySuite) TestTags(c *C) { tags.ForEach(func(tag *Tag) error { count++ + c.Assert(tag.Hash.IsZero(), Equals, false) c.Assert(tag.Type(), Equals, plumbing.TagObject) - return nil }) @@ -339,7 +355,7 @@ func (s *RepositorySuite) TestTags(c *C) { func (s *RepositorySuite) TestCommitIterClosePanic(c *C) { r := NewMemoryRepository() - err := r.Clone(&CloneOptions{URL: RepositoryFixture}) + err := r.Clone(&CloneOptions{URL: s.GetBasicLocalRepositoryURL()}) c.Assert(err, IsNil) commits, err := r.Commits() @@ -349,7 +365,7 @@ func (s *RepositorySuite) TestCommitIterClosePanic(c *C) { func (s *RepositorySuite) TestRef(c *C) { r := NewMemoryRepository() - err := r.Clone(&CloneOptions{URL: RepositoryFixture}) + err := r.Clone(&CloneOptions{URL: s.GetBasicLocalRepositoryURL()}) c.Assert(err, IsNil) ref, err := r.Ref(plumbing.HEAD, false) @@ -363,7 +379,7 @@ func (s *RepositorySuite) TestRef(c *C) { func (s *RepositorySuite) TestRefs(c *C) { r := NewMemoryRepository() - err := r.Clone(&CloneOptions{URL: RepositoryFixture}) + err := r.Clone(&CloneOptions{URL: s.GetBasicLocalRepositoryURL()}) c.Assert(err, IsNil) c.Assert(err, IsNil) @@ -375,21 +391,20 @@ func (s *RepositorySuite) TestRefs(c *C) { func (s *RepositorySuite) TestObject(c *C) { r := NewMemoryRepository() - err := r.Clone(&CloneOptions{URL: "https://github.com/spinnaker/spinnaker.git"}) + err := r.Clone(&CloneOptions{URL: s.GetBasicLocalRepositoryURL()}) c.Assert(err, IsNil) - hash := plumbing.NewHash("0a3fb06ff80156fb153bcdcc58b5e16c2d27625c") - tag, err := r.Tag(hash) + hash := plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5") + o, err := r.Object(plumbing.CommitObject, hash) c.Assert(err, IsNil) - c.Assert(tag.Hash.IsZero(), Equals, false) - c.Assert(tag.Hash, Equals, hash) - c.Assert(tag.Type(), Equals, plumbing.TagObject) + c.Assert(o.ID().IsZero(), Equals, false) + c.Assert(o.Type(), Equals, plumbing.CommitObject) } func (s *RepositorySuite) TestObjectNotFound(c *C) { r := NewMemoryRepository() - err := r.Clone(&CloneOptions{URL: "https://github.com/git-fixtures/basic.git"}) + err := r.Clone(&CloneOptions{URL: s.GetBasicLocalRepositoryURL()}) c.Assert(err, IsNil) hash := plumbing.NewHash("0a3fb06ff80156fb153bcdcc58b5e16c2d27625c") diff --git a/tag_test.go b/tag_test.go index 652577b..89fe1f5 100644 --- a/tag_test.go +++ b/tag_test.go @@ -17,29 +17,23 @@ var _ = Suite(&TagSuite{}) func (s *TagSuite) SetUpSuite(c *C) { s.BaseSuite.SetUpSuite(c) - s.buildRepositories(c, fixtures.ByTag("tags")) + s.Repository = s.NewRepository(fixtures.ByURL("https://github.com/git-fixtures/tags.git").One()) } func (s *TagSuite) TestName(c *C) { - r := s.Repositories["https://github.com/git-fixtures/tags.git"] - - tag, err := r.Tag(plumbing.NewHash("b742a2a9fa0afcfa9a6fad080980fbc26b007c69")) + tag, err := s.Repository.Tag(plumbing.NewHash("b742a2a9fa0afcfa9a6fad080980fbc26b007c69")) c.Assert(err, IsNil) c.Assert(tag.Name, Equals, "annotated-tag") } func (s *TagSuite) TestTagger(c *C) { - r := s.Repositories["https://github.com/git-fixtures/tags.git"] - - tag, err := r.Tag(plumbing.NewHash("b742a2a9fa0afcfa9a6fad080980fbc26b007c69")) + tag, err := s.Repository.Tag(plumbing.NewHash("b742a2a9fa0afcfa9a6fad080980fbc26b007c69")) c.Assert(err, IsNil) c.Assert(tag.Tagger.String(), Equals, "Máximo Cuadros <mcuadros@gmail.com>") } func (s *TagSuite) TestAnnotated(c *C) { - r := s.Repositories["https://github.com/git-fixtures/tags.git"] - - tag, err := r.Tag(plumbing.NewHash("b742a2a9fa0afcfa9a6fad080980fbc26b007c69")) + tag, err := s.Repository.Tag(plumbing.NewHash("b742a2a9fa0afcfa9a6fad080980fbc26b007c69")) c.Assert(err, IsNil) c.Assert(tag.Message, Equals, "example annotated tag\n") @@ -50,9 +44,7 @@ func (s *TagSuite) TestAnnotated(c *C) { } func (s *TagSuite) TestCommit(c *C) { - r := s.Repositories["https://github.com/git-fixtures/tags.git"] - - tag, err := r.Tag(plumbing.NewHash("ad7897c0fb8e7d9a9ba41fa66072cf06095a6cfc")) + tag, err := s.Repository.Tag(plumbing.NewHash("ad7897c0fb8e7d9a9ba41fa66072cf06095a6cfc")) c.Assert(err, IsNil) c.Assert(tag.Message, Equals, "a tagged commit\n") @@ -63,9 +55,7 @@ func (s *TagSuite) TestCommit(c *C) { } func (s *TagSuite) TestBlob(c *C) { - r := s.Repositories["https://github.com/git-fixtures/tags.git"] - - tag, err := r.Tag(plumbing.NewHash("fe6cb94756faa81e5ed9240f9191b833db5f40ae")) + tag, err := s.Repository.Tag(plumbing.NewHash("fe6cb94756faa81e5ed9240f9191b833db5f40ae")) c.Assert(err, IsNil) c.Assert(tag.Message, Equals, "a tagged blob\n") @@ -76,9 +66,7 @@ func (s *TagSuite) TestBlob(c *C) { } func (s *TagSuite) TestTree(c *C) { - r := s.Repositories["https://github.com/git-fixtures/tags.git"] - - tag, err := r.Tag(plumbing.NewHash("152175bf7e5580299fa1f0ba41ef6474cc043b70")) + tag, err := s.Repository.Tag(plumbing.NewHash("152175bf7e5580299fa1f0ba41ef6474cc043b70")) c.Assert(err, IsNil) c.Assert(tag.Message, Equals, "a tagged tree\n") @@ -89,9 +77,7 @@ func (s *TagSuite) TestTree(c *C) { } func (s *TagSuite) TestTreeFromCommit(c *C) { - r := s.Repositories["https://github.com/git-fixtures/tags.git"] - - tag, err := r.Tag(plumbing.NewHash("ad7897c0fb8e7d9a9ba41fa66072cf06095a6cfc")) + tag, err := s.Repository.Tag(plumbing.NewHash("ad7897c0fb8e7d9a9ba41fa66072cf06095a6cfc")) c.Assert(err, IsNil) c.Assert(tag.Message, Equals, "a tagged commit\n") @@ -102,9 +88,7 @@ func (s *TagSuite) TestTreeFromCommit(c *C) { } func (s *TagSuite) TestObject(c *C) { - r := s.Repositories["https://github.com/git-fixtures/tags.git"] - - tag, err := r.Tag(plumbing.NewHash("ad7897c0fb8e7d9a9ba41fa66072cf06095a6cfc")) + tag, err := s.Repository.Tag(plumbing.NewHash("ad7897c0fb8e7d9a9ba41fa66072cf06095a6cfc")) c.Assert(err, IsNil) obj, err := tag.Object() @@ -114,12 +98,11 @@ func (s *TagSuite) TestObject(c *C) { } func (s *TagSuite) TestTagItter(c *C) { - r := s.Repositories["https://github.com/git-fixtures/tags.git"] - iter, err := r.s.IterObjects(plumbing.TagObject) + iter, err := s.Repository.s.IterObjects(plumbing.TagObject) c.Assert(err, IsNil) var count int - i := NewTagIter(r, iter) + i := NewTagIter(s.Repository, iter) err = i.ForEach(func(t *Tag) error { count++ return nil @@ -130,11 +113,10 @@ func (s *TagSuite) TestTagItter(c *C) { } func (s *TagSuite) TestTagIterError(c *C) { - r := s.Repositories["https://github.com/git-fixtures/tags.git"] - iter, err := r.s.IterObjects(plumbing.TagObject) + iter, err := s.Repository.s.IterObjects(plumbing.TagObject) c.Assert(err, IsNil) - i := NewTagIter(r, iter) + i := NewTagIter(s.Repository, iter) err = i.ForEach(func(t *Tag) error { return fmt.Errorf("a random error") }) @@ -173,9 +155,7 @@ func (s *TagSuite) TestTagEncodeDecodeIdempotent(c *C) { } func (s *TagSuite) TestString(c *C) { - r := s.Repositories["https://github.com/git-fixtures/tags.git"] - - tag, err := r.Tag(plumbing.NewHash("b742a2a9fa0afcfa9a6fad080980fbc26b007c69")) + tag, err := s.Repository.Tag(plumbing.NewHash("b742a2a9fa0afcfa9a6fad080980fbc26b007c69")) c.Assert(err, IsNil) c.Assert(tag.String(), Equals, ""+ "tag annotated-tag\n"+ diff --git a/tree_diff_test.go b/tree_diff_test.go index 81fee5d..e7e41c7 100644 --- a/tree_diff_test.go +++ b/tree_diff_test.go @@ -15,11 +15,6 @@ type DiffTreeSuite struct { var _ = Suite(&DiffTreeSuite{}) -func (s *DiffTreeSuite) SetUpSuite(c *C) { - s.BaseSuite.SetUpSuite(c) - s.buildRepositories(c, fixtures.ByTag("diff-tree")) -} - func (s *DiffTreeSuite) TestActionString(c *C) { expected := "Insert" action := Insert @@ -129,228 +124,203 @@ type expectChange struct { func (s *DiffTreeSuite) TestDiffTree(c *C) { for i, t := range []struct { - repo string // the repo name as in localRepos - commit1 string // the commit of the first tree - commit2 string // the commit of the second tree - expected []expectChange // the expected list of []changeExpect - }{ - { - "https://github.com/dezfowler/LiteMock.git", - "", - "", - []expectChange{}, - }, - { - "https://github.com/dezfowler/LiteMock.git", - "b7965eaa2c4f245d07191fe0bcfe86da032d672a", - "b7965eaa2c4f245d07191fe0bcfe86da032d672a", - []expectChange{}, - }, - { - "https://github.com/dezfowler/LiteMock.git", - "", - "b7965eaa2c4f245d07191fe0bcfe86da032d672a", - []expectChange{ - {Action: Insert, Name: "README"}, - }, - }, - { - "https://github.com/dezfowler/LiteMock.git", - "b7965eaa2c4f245d07191fe0bcfe86da032d672a", - "", - []expectChange{ - {Action: Delete, Name: "README"}, - }, - }, - { - "https://github.com/githubtraining/example-branches.git", - "", - "f0eb272cc8f77803478c6748103a1450aa1abd37", - []expectChange{ - {Action: Insert, Name: "README.md"}, - }, - }, - { - "https://github.com/githubtraining/example-branches.git", - "f0eb272cc8f77803478c6748103a1450aa1abd37", - "", - []expectChange{ - {Action: Delete, Name: "README.md"}, - }, + repository string // the repo name as in localRepos + commit1 string // the commit of the first tree + commit2 string // the commit of the second tree + expected []expectChange // the expected list of []changeExpect + }{{ + "https://github.com/dezfowler/LiteMock.git", + "", + "", + []expectChange{}, + }, { + "https://github.com/dezfowler/LiteMock.git", + "b7965eaa2c4f245d07191fe0bcfe86da032d672a", + "b7965eaa2c4f245d07191fe0bcfe86da032d672a", + []expectChange{}, + }, { + "https://github.com/dezfowler/LiteMock.git", + "", + "b7965eaa2c4f245d07191fe0bcfe86da032d672a", + []expectChange{ + {Action: Insert, Name: "README"}, }, - { - "https://github.com/githubtraining/example-branches.git", - "f0eb272cc8f77803478c6748103a1450aa1abd37", - "f0eb272cc8f77803478c6748103a1450aa1abd37", - []expectChange{}, + }, { + "https://github.com/dezfowler/LiteMock.git", + "b7965eaa2c4f245d07191fe0bcfe86da032d672a", + "", + []expectChange{ + {Action: Delete, Name: "README"}, }, - { - "https://github.com/github/gem-builder.git", - "", - "9608eed92b3839b06ebf72d5043da547de10ce85", - []expectChange{ - {Action: Insert, Name: "README"}, - {Action: Insert, Name: "gem_builder.rb"}, - {Action: Insert, Name: "gem_eval.rb"}, - }, + }, { + "https://github.com/githubtraining/example-branches.git", + "", + "f0eb272cc8f77803478c6748103a1450aa1abd37", + []expectChange{ + {Action: Insert, Name: "README.md"}, }, - { - "https://github.com/github/gem-builder.git", - "9608eed92b3839b06ebf72d5043da547de10ce85", - "", - []expectChange{ - {Action: Delete, Name: "README"}, - {Action: Delete, Name: "gem_builder.rb"}, - {Action: Delete, Name: "gem_eval.rb"}, - }, + }, { + "https://github.com/githubtraining/example-branches.git", + "f0eb272cc8f77803478c6748103a1450aa1abd37", + "", + []expectChange{ + {Action: Delete, Name: "README.md"}, }, - { - "https://github.com/github/gem-builder.git", - "9608eed92b3839b06ebf72d5043da547de10ce85", - "9608eed92b3839b06ebf72d5043da547de10ce85", - []expectChange{}, + }, { + "https://github.com/githubtraining/example-branches.git", + "f0eb272cc8f77803478c6748103a1450aa1abd37", + "f0eb272cc8f77803478c6748103a1450aa1abd37", + []expectChange{}, + }, { + "https://github.com/github/gem-builder.git", + "", + "9608eed92b3839b06ebf72d5043da547de10ce85", + []expectChange{ + {Action: Insert, Name: "README"}, + {Action: Insert, Name: "gem_builder.rb"}, + {Action: Insert, Name: "gem_eval.rb"}, }, - { - "https://github.com/toqueteos/ts3.git", - "", - "764e914b75d6d6df1fc5d832aa9840f590abf1bb", - []expectChange{ - {Action: Insert, Name: "README.markdown"}, - {Action: Insert, Name: "examples/bot.go"}, - {Action: Insert, Name: "examples/raw_shell.go"}, - {Action: Insert, Name: "helpers.go"}, - {Action: Insert, Name: "ts3.go"}, - }, + }, { + "https://github.com/github/gem-builder.git", + "9608eed92b3839b06ebf72d5043da547de10ce85", + "", + []expectChange{ + {Action: Delete, Name: "README"}, + {Action: Delete, Name: "gem_builder.rb"}, + {Action: Delete, Name: "gem_eval.rb"}, }, - { - "https://github.com/toqueteos/ts3.git", - "764e914b75d6d6df1fc5d832aa9840f590abf1bb", - "", - []expectChange{ - {Action: Delete, Name: "README.markdown"}, - {Action: Delete, Name: "examples/bot.go"}, - {Action: Delete, Name: "examples/raw_shell.go"}, - {Action: Delete, Name: "helpers.go"}, - {Action: Delete, Name: "ts3.go"}, - }, + }, { + "https://github.com/github/gem-builder.git", + "9608eed92b3839b06ebf72d5043da547de10ce85", + "9608eed92b3839b06ebf72d5043da547de10ce85", + []expectChange{}, + }, { + "https://github.com/toqueteos/ts3.git", + "", + "764e914b75d6d6df1fc5d832aa9840f590abf1bb", + []expectChange{ + {Action: Insert, Name: "README.markdown"}, + {Action: Insert, Name: "examples/bot.go"}, + {Action: Insert, Name: "examples/raw_shell.go"}, + {Action: Insert, Name: "helpers.go"}, + {Action: Insert, Name: "ts3.go"}, }, - { - "https://github.com/toqueteos/ts3.git", - "764e914b75d6d6df1fc5d832aa9840f590abf1bb", - "764e914b75d6d6df1fc5d832aa9840f590abf1bb", - []expectChange{}, + }, { + "https://github.com/toqueteos/ts3.git", + "764e914b75d6d6df1fc5d832aa9840f590abf1bb", + "", + []expectChange{ + {Action: Delete, Name: "README.markdown"}, + {Action: Delete, Name: "examples/bot.go"}, + {Action: Delete, Name: "examples/raw_shell.go"}, + {Action: Delete, Name: "helpers.go"}, + {Action: Delete, Name: "ts3.go"}, }, - { - "https://github.com/github/gem-builder.git", - "9608eed92b3839b06ebf72d5043da547de10ce85", - "6c41e05a17e19805879689414026eb4e279f7de0", - []expectChange{ - {Action: Modify, Name: "gem_eval.rb"}, - }, + }, { + "https://github.com/toqueteos/ts3.git", + "764e914b75d6d6df1fc5d832aa9840f590abf1bb", + "764e914b75d6d6df1fc5d832aa9840f590abf1bb", + []expectChange{}, + }, { + "https://github.com/github/gem-builder.git", + "9608eed92b3839b06ebf72d5043da547de10ce85", + "6c41e05a17e19805879689414026eb4e279f7de0", + []expectChange{ + {Action: Modify, Name: "gem_eval.rb"}, }, - { - "https://github.com/github/gem-builder.git", - "6c41e05a17e19805879689414026eb4e279f7de0", - "89be3aac2f178719c12953cc9eaa23441f8d9371", - []expectChange{ - {Action: Modify, Name: "gem_eval.rb"}, - {Action: Insert, Name: "gem_eval_test.rb"}, - {Action: Insert, Name: "security.rb"}, - {Action: Insert, Name: "security_test.rb"}, - }, + }, { + "https://github.com/github/gem-builder.git", + "6c41e05a17e19805879689414026eb4e279f7de0", + "89be3aac2f178719c12953cc9eaa23441f8d9371", + []expectChange{ + {Action: Modify, Name: "gem_eval.rb"}, + {Action: Insert, Name: "gem_eval_test.rb"}, + {Action: Insert, Name: "security.rb"}, + {Action: Insert, Name: "security_test.rb"}, }, - { - "https://github.com/github/gem-builder.git", - "89be3aac2f178719c12953cc9eaa23441f8d9371", - "597240b7da22d03ad555328f15abc480b820acc0", - []expectChange{ - {Action: Modify, Name: "gem_eval.rb"}, - }, + }, { + "https://github.com/github/gem-builder.git", + "89be3aac2f178719c12953cc9eaa23441f8d9371", + "597240b7da22d03ad555328f15abc480b820acc0", + []expectChange{ + {Action: Modify, Name: "gem_eval.rb"}, }, - { - "https://github.com/github/gem-builder.git", - "597240b7da22d03ad555328f15abc480b820acc0", - "0260380e375d2dd0e1a8fcab15f91ce56dbe778e", - []expectChange{ - {Action: Modify, Name: "gem_eval.rb"}, - {Action: Modify, Name: "gem_eval_test.rb"}, - {Action: Insert, Name: "lazy_dir.rb"}, - {Action: Insert, Name: "lazy_dir_test.rb"}, - {Action: Modify, Name: "security.rb"}, - {Action: Modify, Name: "security_test.rb"}, - }, + }, { + "https://github.com/github/gem-builder.git", + "597240b7da22d03ad555328f15abc480b820acc0", + "0260380e375d2dd0e1a8fcab15f91ce56dbe778e", + []expectChange{ + {Action: Modify, Name: "gem_eval.rb"}, + {Action: Modify, Name: "gem_eval_test.rb"}, + {Action: Insert, Name: "lazy_dir.rb"}, + {Action: Insert, Name: "lazy_dir_test.rb"}, + {Action: Modify, Name: "security.rb"}, + {Action: Modify, Name: "security_test.rb"}, }, - { - "https://github.com/github/gem-builder.git", - "0260380e375d2dd0e1a8fcab15f91ce56dbe778e", - "597240b7da22d03ad555328f15abc480b820acc0", - []expectChange{ - {Action: Modify, Name: "gem_eval.rb"}, - {Action: Modify, Name: "gem_eval_test.rb"}, - {Action: Delete, Name: "lazy_dir.rb"}, - {Action: Delete, Name: "lazy_dir_test.rb"}, - {Action: Modify, Name: "security.rb"}, - {Action: Modify, Name: "security_test.rb"}, - }, + }, { + "https://github.com/github/gem-builder.git", + "0260380e375d2dd0e1a8fcab15f91ce56dbe778e", + "597240b7da22d03ad555328f15abc480b820acc0", + []expectChange{ + {Action: Modify, Name: "gem_eval.rb"}, + {Action: Modify, Name: "gem_eval_test.rb"}, + {Action: Delete, Name: "lazy_dir.rb"}, + {Action: Delete, Name: "lazy_dir_test.rb"}, + {Action: Modify, Name: "security.rb"}, + {Action: Modify, Name: "security_test.rb"}, }, - { - "https://github.com/github/gem-builder.git", - "0260380e375d2dd0e1a8fcab15f91ce56dbe778e", - "ca9fd470bacb6262eb4ca23ee48bb2f43711c1ff", - []expectChange{ - {Action: Modify, Name: "gem_eval.rb"}, - {Action: Modify, Name: "security.rb"}, - {Action: Modify, Name: "security_test.rb"}, - }, + }, { + "https://github.com/github/gem-builder.git", + "0260380e375d2dd0e1a8fcab15f91ce56dbe778e", + "ca9fd470bacb6262eb4ca23ee48bb2f43711c1ff", + []expectChange{ + {Action: Modify, Name: "gem_eval.rb"}, + {Action: Modify, Name: "security.rb"}, + {Action: Modify, Name: "security_test.rb"}, }, - { - "https://github.com/github/gem-builder.git", - "fe3c86745f887c23a0d38c85cfd87ca957312f86", - "b7e3f636febf7a0cd3ab473b6d30081786d2c5b6", - []expectChange{ - {Action: Modify, Name: "gem_eval.rb"}, - {Action: Modify, Name: "gem_eval_test.rb"}, - {Action: Insert, Name: "git_mock"}, - {Action: Modify, Name: "lazy_dir.rb"}, - {Action: Modify, Name: "lazy_dir_test.rb"}, - {Action: Modify, Name: "security.rb"}, - }, + }, { + "https://github.com/github/gem-builder.git", + "fe3c86745f887c23a0d38c85cfd87ca957312f86", + "b7e3f636febf7a0cd3ab473b6d30081786d2c5b6", + []expectChange{ + {Action: Modify, Name: "gem_eval.rb"}, + {Action: Modify, Name: "gem_eval_test.rb"}, + {Action: Insert, Name: "git_mock"}, + {Action: Modify, Name: "lazy_dir.rb"}, + {Action: Modify, Name: "lazy_dir_test.rb"}, + {Action: Modify, Name: "security.rb"}, }, - { - "https://github.com/rumpkernel/rumprun-xen.git", - "1831e47b0c6db750714cd0e4be97b5af17fb1eb0", - "51d8515578ea0c88cc8fc1a057903675cf1fc16c", - []expectChange{ - {Action: Modify, Name: "Makefile"}, - {Action: Modify, Name: "netbsd_init.c"}, - {Action: Modify, Name: "rumphyper_stubs.c"}, - {Action: Delete, Name: "sysproxy.c"}, - }, + }, { + "https://github.com/rumpkernel/rumprun-xen.git", + "1831e47b0c6db750714cd0e4be97b5af17fb1eb0", + "51d8515578ea0c88cc8fc1a057903675cf1fc16c", + []expectChange{ + {Action: Modify, Name: "Makefile"}, + {Action: Modify, Name: "netbsd_init.c"}, + {Action: Modify, Name: "rumphyper_stubs.c"}, + {Action: Delete, Name: "sysproxy.c"}, }, - { - "https://github.com/rumpkernel/rumprun-xen.git", - "1831e47b0c6db750714cd0e4be97b5af17fb1eb0", - "e13e678f7ee9badd01b120889e0ec5fdc8ae3802", - []expectChange{ - {Action: Modify, Name: "app-tools/rumprun"}, - }, + }, { + "https://github.com/rumpkernel/rumprun-xen.git", + "1831e47b0c6db750714cd0e4be97b5af17fb1eb0", + "e13e678f7ee9badd01b120889e0ec5fdc8ae3802", + []expectChange{ + {Action: Modify, Name: "app-tools/rumprun"}, }, - } { - repo, ok := s.Repositories[t.repo] - c.Assert(ok, Equals, true, - Commentf("subtest %d: repo %s not found", i, t.repo)) + }} { + r := s.NewRepositoryFromPackfile(fixtures.ByURL(t.repository).One()) - tree1, err := tree(repo, t.commit1) + tree1, err := tree(r, t.commit1) c.Assert(err, IsNil, - Commentf("subtest %d: unable to retrieve tree from commit %s and repo %s: %s", i, t.commit1, t.repo, err)) + Commentf("subtest %d: unable to retrieve tree from commit %s and repo %s: %s", i, t.commit1, t.repository, err)) var tree2 *Tree if t.commit1 == t.commit2 { tree2 = tree1 } else { - tree2, err = tree(repo, t.commit2) + tree2, err = tree(r, t.commit2) c.Assert(err, IsNil, - Commentf("subtest %d: unable to retrieve tree from commit %s and repo %s", i, t.commit2, t.repo, err)) + Commentf("subtest %d: unable to retrieve tree from commit %s and repo %s", i, t.commit2, t.repository, err)) } obtained, err := DiffTree(tree1, tree2) @@ -358,7 +328,7 @@ func (s *DiffTreeSuite) TestDiffTree(c *C) { Commentf("subtest %d: unable to calculate difftree: %s", i, err)) c.Assert(equalChanges(obtained, t.expected), Equals, true, Commentf("subtest:%d\nrepo=%s\ncommit1=%s\ncommit2=%s\nexpected=%s\nobtained=%s", - i, t.repo, t.commit1, t.commit2, t.expected, obtained)) + i, t.repository, t.commit1, t.commit2, t.expected, obtained)) assertChanges(obtained, c) } |