Esempio n. 1
0
func (s *ReferencesSuite) TestRevList(c *C) {
	for _, t := range referencesTests {
		r := s.NewRepositoryFromPackfile(fixtures.ByURL(t.repo).One())

		commit, err := r.Commit(plumbing.NewHash(t.commit))
		c.Assert(err, IsNil)

		revs, err := References(commit, t.path)
		c.Assert(err, IsNil)
		c.Assert(len(revs), Equals, len(t.revs))

		for i := range revs {
			if revs[i].Hash.String() != 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)
				if equiv {
					fmt.Printf("cherry-pick detected: %s    %s\n", revs[i].Hash.String(), t.revs[i])
				} else {
					c.Fatalf("\nrepo=%s, commit=%s, path=%s, \n%s",
						t.repo, t.commit, t.path, compareSideBySide(t.revs, revs))
				}
			}
		}
	}
}
Esempio n. 2
0
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: url})
	c.Assert(err, IsNil)

	count := 0
	tags, err := r.Tags()
	c.Assert(err, IsNil)

	tags.ForEach(func(tag *object.Tag) error {
		count++

		c.Assert(tag.Hash.IsZero(), Equals, false)
		c.Assert(tag.Type(), Equals, plumbing.TagObject)
		return nil
	})

	refs, _ := r.References()
	refs.ForEach(func(ref *plumbing.Reference) error {
		return nil
	})

	c.Assert(count, Equals, 4)
}
Esempio n. 3
0
func (s *FileSuite) TestIter(c *C) {
	for i, t := range fileIterTests {
		f := fixtures.ByURL(t.repo).One()
		sto, err := filesystem.NewStorage(f.DotGit())
		c.Assert(err, IsNil)

		h := plumbing.NewHash(t.commit)
		commit, err := GetCommit(sto, h)
		c.Assert(err, IsNil, Commentf("subtest %d: %v (%s)", i, err, t.commit))

		tree, err := commit.Tree()
		c.Assert(err, IsNil)

		iter := NewFileIter(sto, tree)
		for k := 0; k < len(t.files); k++ {
			exp := t.files[k]
			file, err := iter.Next()
			c.Assert(err, IsNil, Commentf("subtest %d, iter %d, err=%v", i, k, err))
			c.Assert(file.Mode.String(), Equals, "-rw-r--r--")
			c.Assert(file.Hash.IsZero(), Equals, false)
			c.Assert(file.Hash, Equals, file.ID())
			c.Assert(file.Name, Equals, exp.Name, Commentf("subtest %d, iter %d, name=%s, expected=%s", i, k, file.Name, exp.Hash))
			c.Assert(file.Hash.String(), Equals, exp.Hash, Commentf("subtest %d, iter %d, hash=%v, expected=%s", i, k, file.Hash.String(), exp.Hash))
		}
		_, err = iter.Next()
		c.Assert(err, Equals, io.EOF)
	}
}
Esempio n. 4
0
func (s *TagSuite) SetUpSuite(c *C) {
	s.BaseObjectsSuite.SetUpSuite(c)
	storer, err := filesystem.NewStorage(
		fixtures.ByURL("https://github.com/git-fixtures/tags.git").One().DotGit())
	c.Assert(err, IsNil)
	s.Storer = storer
}
Esempio n. 5
0
// 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 := Blame(commit, t.path)
		c.Assert(err, IsNil)
		c.Assert(obt, DeepEquals, exp)
	}
}
Esempio n. 6
0
func (p *MockGitUploadPackService) Fetch(r *common.GitUploadPackRequest) (io.ReadCloser, error) {
	if !p.connected {
		return nil, errors.New("not connected")
	}

	f := fixtures.ByURL(p.endpoint.String())

	if len(r.Wants) == 1 {
		return f.Exclude("single-branch").One().Packfile(), nil
	}

	return f.One().Packfile(), nil
}
Esempio n. 7
0
// returns the commits from a slice of hashes
func (s *ReferencesSuite) commits(c *C, repo string, hs ...string) []*object.Commit {
	r := s.NewRepositoryFromPackfile(fixtures.ByURL(repo).One())

	result := make([]*object.Commit, 0, len(hs))
	for _, h := range hs {
		commit, err := r.Commit(plumbing.NewHash(h))
		c.Assert(err, IsNil)

		result = append(result, commit)
	}

	return result
}
Esempio n. 8
0
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: url})
	c.Assert(err, IsNil)

	hash := plumbing.NewHash("ad7897c0fb8e7d9a9ba41fa66072cf06095a6cfc")
	tag, err := r.Tag(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)
}
Esempio n. 9
0
func (s *FileSuite) TestLines(c *C) {
	for i, t := range linesTests {
		f := fixtures.ByURL(t.repo).One()
		sto, err := filesystem.NewStorage(f.DotGit())
		c.Assert(err, IsNil)

		h := plumbing.NewHash(t.commit)
		commit, err := GetCommit(sto, h)
		c.Assert(err, IsNil, Commentf("subtest %d: %v (%s)", i, err, t.commit))

		file, err := commit.File(t.path)
		c.Assert(err, IsNil)
		lines, err := file.Lines()
		c.Assert(err, IsNil)
		c.Assert(lines, DeepEquals, t.lines, Commentf(
			"subtest %d: commit=%s, path=%s", i, t.commit, t.path))
	}
}
Esempio n. 10
0
func (s *SuiteCommit) TestStringMultiLine(c *C) {
	hash := plumbing.NewHash("e7d896db87294e33ca3202e536d4d9bb16023db3")

	s.buildRepositories(c, fixtures.ByURL("https://github.com/src-d/go-git.git"))

	commit, err := s.Repositories["https://github.com/src-d/go-git.git"].Commit(hash)
	c.Assert(err, IsNil)

	c.Assert(commit.String(), Equals, ""+
		"commit e7d896db87294e33ca3202e536d4d9bb16023db3\n"+
		"Author: Alberto Cortés <*****@*****.**>\n"+
		"Date:   Wed Jan 27 11:13:49 2016 +0100\n"+
		"\n"+
		"    fix zlib invalid header error\n"+
		"\n"+
		"    The return value of reads to the packfile were being ignored, so zlib\n"+
		"    was getting invalid data on it read buffers.\n"+
		"\n",
	)
}
Esempio n. 11
0
// It is difficult to assert that we are ignoring an (empty) dir as even
// if we don't, no files will be found in it.
//
// At least this test has a high chance of panicking if
// we don't ignore empty dirs.
func (s *FileSuite) TestIgnoreEmptyDirEntries(c *C) {
	for i, t := range ignoreEmptyDirEntriesTests {
		f := fixtures.ByURL(t.repo).One()
		sto, err := filesystem.NewStorage(f.DotGit())
		c.Assert(err, IsNil)

		h := plumbing.NewHash(t.commit)
		commit, err := GetCommit(sto, h)
		c.Assert(err, IsNil, Commentf("subtest %d: %v (%s)", i, err, t.commit))

		tree, err := commit.Tree()
		c.Assert(err, IsNil)

		iter := tree.Files()
		defer iter.Close()
		for file, err := iter.Next(); err == nil; file, err = iter.Next() {
			_, _ = file.Contents()
			// this would probably panic if we are not ignoring empty dirs
		}
	}
}
Esempio n. 12
0
func (s *SuiteCommit) TestStringMultiLine(c *C) {
	hash := plumbing.NewHash("e7d896db87294e33ca3202e536d4d9bb16023db3")

	f := fixtures.ByURL("https://github.com/src-d/go-git.git").One()
	sto, err := filesystem.NewStorage(f.DotGit())

	o, err := sto.EncodedObject(plumbing.CommitObject, hash)
	c.Assert(err, IsNil)
	commit, err := DecodeCommit(sto, o)
	c.Assert(err, IsNil)

	c.Assert(commit.String(), Equals, ""+
		"commit e7d896db87294e33ca3202e536d4d9bb16023db3\n"+
		"Author: Alberto Cortés <*****@*****.**>\n"+
		"Date:   Wed Jan 27 11:13:49 2016 +0100\n"+
		"\n"+
		"    fix zlib invalid header error\n"+
		"\n"+
		"    The return value of reads to the packfile were being ignored, so zlib\n"+
		"    was getting invalid data on it read buffers.\n"+
		"\n",
	)
}
Esempio n. 13
0
func (p *MockGitUploadPackService) Info() (*common.GitUploadPackInfo, error) {
	if !p.connected {
		return nil, errors.New("not connected")
	}

	h := fixtures.ByURL(p.endpoint.String()).One().Head

	c := packp.NewCapabilities()
	c.Decode("6ecf0ef2c2dffb796033e5a02219af86ec6584e5 HEADmulti_ack thin-pack side-band side-band-64k ofs-delta shallow no-progress include-tag multi_ack_detailed no-done symref=HEAD:refs/heads/master agent=git/2:2.4.8~dbussink-fix-enterprise-tokens-compilation-1167-gc7006cf")

	ref := plumbing.ReferenceName("refs/heads/master")
	branch := plumbing.ReferenceName("refs/heads/branch")
	tag := plumbing.ReferenceName("refs/tags/v1.0.0")

	return &common.GitUploadPackInfo{
		Capabilities: c,
		Refs: map[plumbing.ReferenceName]*plumbing.Reference{
			plumbing.HEAD: plumbing.NewSymbolicReference(plumbing.HEAD, ref),
			ref:           plumbing.NewHashReference(ref, h),
			tag:           plumbing.NewHashReference(tag, h),
			branch:        plumbing.NewHashReference(branch, plumbing.NewHash("e8d3ffab552895c19b9fcf7aa264d277cde33881")),
		},
	}, nil
}
Esempio n. 14
0
func (s *DiffTreeSuite) TestDiffTree(c *C) {
	for i, t := range []struct {
		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/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"},
		},
	}, {
		"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/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/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",
		"",
		[]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/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",
		"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",
		"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",
		"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",
		"e13e678f7ee9badd01b120889e0ec5fdc8ae3802",
		[]expectChange{
			{Action: Modify, Name: "app-tools/rumprun"},
		},
	}} {
		f := fixtures.ByURL(t.repository).One()
		sto := s.storageFromPackfile(f)

		var tree1, tree2 *object.Tree
		var err error
		if t.commit1 != "" {
			tree1, err = s.commitFromStorer(c, sto,
				plumbing.NewHash(t.commit1)).Tree()
			c.Assert(err, IsNil,
				Commentf("subtest %d: unable to retrieve tree from commit %s and repo %s: %s", i, t.commit1, t.repository, err))
		}

		if t.commit2 != "" {
			tree2, err = s.commitFromStorer(c, sto,
				plumbing.NewHash(t.commit2)).Tree()
			c.Assert(err, IsNil,
				Commentf("subtest %d: unable to retrieve tree from commit %s and repo %s", i, t.commit2, t.repository, err))
		}

		obtained, err := DiffTree(tree1, tree2)
		c.Assert(err, IsNil,
			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.repository, t.commit1, t.commit2, t.expected, obtained))

		assertChanges(obtained, c)
	}
}