aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--blame_test.go2
-rw-r--r--common_test.go2
-rw-r--r--examples/basic/main.go2
-rw-r--r--examples/latest/latest.go7
-rw-r--r--examples/object_storage/main.go2
-rw-r--r--examples/object_storage/storage.go36
-rw-r--r--examples/remotes/main.go2
-rw-r--r--objects_test.go7
-rw-r--r--options.go18
-rw-r--r--references_test.go2
-rw-r--r--remote.go4
-rw-r--r--remote_test.go2
-rw-r--r--repository.go10
-rw-r--r--repository_test.go54
-rw-r--r--tree_diff_test.go2
15 files changed, 83 insertions, 69 deletions
diff --git a/blame_test.go b/blame_test.go
index f766831..61d505a 100644
--- a/blame_test.go
+++ b/blame_test.go
@@ -21,7 +21,7 @@ var _ = Suite(&BlameCommon{})
func (s *BlameCommon) SetUpSuite(c *C) {
s.repos = make(map[string]*Repository, 0)
for _, fixRepo := range fixtureRepos {
- r, _ := NewMemoryRepository()
+ r := NewMemoryRepository()
f, err := os.Open(fixRepo.packfile)
c.Assert(err, IsNil)
diff --git a/common_test.go b/common_test.go
index 386dc74..6239afe 100644
--- a/common_test.go
+++ b/common_test.go
@@ -103,7 +103,7 @@ func unpackFixtures(c *C, fixtures ...[]packedFixture) map[string]*Repository {
comment := Commentf("fixture packfile: %q", fixture.packfile)
- repos[fixture.url], _ = NewMemoryRepository()
+ repos[fixture.url] = NewMemoryRepository()
f, err := os.Open(fixture.packfile)
c.Assert(err, IsNil, comment)
diff --git a/examples/basic/main.go b/examples/basic/main.go
index 4c65a70..e192cef 100644
--- a/examples/basic/main.go
+++ b/examples/basic/main.go
@@ -16,7 +16,7 @@ func main() {
// > git clone https://github.com/git-fixtures/basic.git
color.Blue("git clone https://github.com/git-fixtures/basic.git")
- r.Clone(&git.RepositoryCloneOptions{
+ r.Clone(&git.CloneOptions{
URL: "https://github.com/git-fixtures/basic.git",
})
diff --git a/examples/latest/latest.go b/examples/latest/latest.go
index de927fa..05f583a 100644
--- a/examples/latest/latest.go
+++ b/examples/latest/latest.go
@@ -11,12 +11,9 @@ func main() {
url := os.Args[1]
fmt.Printf("Retrieving latest commit from: %q ...\n", url)
- r, err := git.NewMemoryRepository()
- if err != nil {
- panic(err)
- }
+ r := git.NewMemoryRepository()
- if err = r.Clone(&git.RepositoryCloneOptions{URL: url}); err != nil {
+ if err := r.Clone(&git.CloneOptions{URL: url}); err != nil {
panic(err)
}
diff --git a/examples/object_storage/main.go b/examples/object_storage/main.go
index d3818e0..22fa426 100644
--- a/examples/object_storage/main.go
+++ b/examples/object_storage/main.go
@@ -38,7 +38,7 @@ func clone(r *git.Repository, url string) {
fmt.Printf("Cloning %q ...\n", os.Args[2])
start := time.Now()
- if err := r.Clone(&git.RepositoryCloneOptions{URL: url}); err != nil {
+ if err := r.Clone(&git.CloneOptions{URL: url}); err != nil {
panic(err)
}
diff --git a/examples/object_storage/storage.go b/examples/object_storage/storage.go
index bb9ff29..c119adc 100644
--- a/examples/object_storage/storage.go
+++ b/examples/object_storage/storage.go
@@ -5,6 +5,7 @@ import (
"io"
"io/ioutil"
+ "gopkg.in/src-d/go-git.v4/config"
"gopkg.in/src-d/go-git.v4/core"
"github.com/aerospike/aerospike-client-go"
@@ -40,6 +41,10 @@ func (s *AerospikeStorage) ReferenceStorage() core.ReferenceStorage {
return s.rs
}
+func (s *AerospikeStorage) ConfigStorage() config.ConfigStorage {
+ return &ConfigStorage{}
+}
+
type AerospikeObjectStorage struct {
url string
client *aerospike.Client
@@ -227,3 +232,34 @@ func (s *AerospikeReferenceStorage) Iter() (core.ReferenceIter, error) {
return core.NewReferenceSliceIter(refs), nil
}
+
+type ConfigStorage struct {
+ RemotesConfig map[string]*config.RemoteConfig
+}
+
+func (c *ConfigStorage) Remote(name string) (*config.RemoteConfig, error) {
+ r, ok := c.RemotesConfig[name]
+ if ok {
+ return r, nil
+ }
+
+ return nil, config.ErrRemoteConfigNotFound
+}
+
+func (c *ConfigStorage) Remotes() ([]*config.RemoteConfig, error) {
+ var o []*config.RemoteConfig
+ for _, r := range c.RemotesConfig {
+ o = append(o, r)
+ }
+
+ return o, nil
+}
+func (c *ConfigStorage) SetRemote(r *config.RemoteConfig) error {
+ c.RemotesConfig[r.Name] = r
+ return nil
+}
+
+func (c *ConfigStorage) DeleteRemote(name string) error {
+ delete(c.RemotesConfig, name)
+ return nil
+}
diff --git a/examples/remotes/main.go b/examples/remotes/main.go
index 488986a..88662cd 100644
--- a/examples/remotes/main.go
+++ b/examples/remotes/main.go
@@ -37,7 +37,7 @@ func main() {
// > git pull example
color.Blue("git pull example")
- r.Pull(&git.RepositoryPullOptions{
+ r.Pull(&git.PullOptions{
RemoteName: "example",
})
diff --git a/objects_test.go b/objects_test.go
index 1ed35f8..7d86b1c 100644
--- a/objects_test.go
+++ b/objects_test.go
@@ -19,11 +19,8 @@ var _ = Suite(&ObjectsSuite{})
func (s *ObjectsSuite) SetUpTest(c *C) {
s.BaseSuite.SetUpTest(c)
- var err error
- s.r, err = NewMemoryRepository()
- c.Assert(err, IsNil)
-
- err = s.r.Clone(&RepositoryCloneOptions{URL: RepositoryFixture})
+ s.r = NewMemoryRepository()
+ err := s.r.Clone(&CloneOptions{URL: RepositoryFixture})
c.Assert(err, IsNil)
}
diff --git a/options.go b/options.go
index 3691a6f..0cca2e3 100644
--- a/options.go
+++ b/options.go
@@ -18,8 +18,8 @@ var (
ErrInvalidRefSpec = errors.New("invalid refspec")
)
-// RepositoryCloneOptions describe how a clone should be perform
-type RepositoryCloneOptions struct {
+// CloneOptions describe how a clone should be perform
+type CloneOptions struct {
// The (possibly remote) repository URL to clone from
URL string
// Auth credentials, if required, to uses with the remote repository
@@ -35,7 +35,7 @@ type RepositoryCloneOptions struct {
}
// Validate validate the fields and set the default values
-func (o *RepositoryCloneOptions) Validate() error {
+func (o *CloneOptions) Validate() error {
if o.URL == "" {
return ErrMissingURL
}
@@ -51,8 +51,8 @@ func (o *RepositoryCloneOptions) Validate() error {
return nil
}
-// RepositoryPullOptions describe how a pull should be perform
-type RepositoryPullOptions struct {
+// PullOptions describe how a pull should be perform
+type PullOptions struct {
// Name of the remote to be pulled
RemoteName string
// Remote branch to clone
@@ -64,7 +64,7 @@ type RepositoryPullOptions struct {
}
// Validate validate the fields and set the default values
-func (o *RepositoryPullOptions) Validate() error {
+func (o *PullOptions) Validate() error {
if o.RemoteName == "" {
o.RemoteName = DefaultRemoteName
}
@@ -76,14 +76,14 @@ func (o *RepositoryPullOptions) Validate() error {
return nil
}
-// RemoteFetchOptions describe how a fetch should be perform
-type RemoteFetchOptions struct {
+// FetchOptions describe how a fetch should be perform
+type FetchOptions struct {
RefSpecs []config.RefSpec
Depth int
}
// Validate validate the fields and set the default values
-func (o *RemoteFetchOptions) Validate() error {
+func (o *FetchOptions) Validate() error {
for _, r := range o.RefSpecs {
if !r.IsValid() {
return ErrInvalidRefSpec
diff --git a/references_test.go b/references_test.go
index 18661db..216fadf 100644
--- a/references_test.go
+++ b/references_test.go
@@ -21,7 +21,7 @@ var _ = Suite(&ReferencesSuite{})
func (s *ReferencesSuite) SetUpSuite(c *C) {
s.repos = make(map[string]*Repository, 0)
for _, fix := range fixtureRepos {
- s.repos[fix.url], _ = NewMemoryRepository()
+ s.repos[fix.url] = NewMemoryRepository()
f, err := os.Open(fix.packfile)
defer f.Close()
diff --git a/remote.go b/remote.go
index 6c020ca..a8b77b1 100644
--- a/remote.go
+++ b/remote.go
@@ -73,7 +73,7 @@ func (r *Remote) Capabilities() *common.Capabilities {
}
// Fetch returns a reader using the request
-func (r *Remote) Fetch(o *RemoteFetchOptions) (err error) {
+func (r *Remote) Fetch(o *FetchOptions) (err error) {
if err := o.Validate(); err != nil {
return err
}
@@ -122,7 +122,7 @@ func (r *Remote) getWantedReferences(spec []config.RefSpec) ([]*core.Reference,
}
func (r *Remote) buildRequest(
- s core.ReferenceStorage, o *RemoteFetchOptions, refs []*core.Reference,
+ s core.ReferenceStorage, o *FetchOptions, refs []*core.Reference,
) (*common.GitUploadPackRequest, error) {
req := &common.GitUploadPackRequest{}
req.Depth = o.Depth
diff --git a/remote_test.go b/remote_test.go
index 7bf15e4..00766ad 100644
--- a/remote_test.go
+++ b/remote_test.go
@@ -78,7 +78,7 @@ func (s *RemoteSuite) TestFetch(c *C) {
c.Assert(r.Connect(), IsNil)
- err := r.Fetch(&RemoteFetchOptions{
+ err := r.Fetch(&FetchOptions{
RefSpecs: []config.RefSpec{config.DefaultRefSpec},
})
diff --git a/repository.go b/repository.go
index 64107f1..445e90c 100644
--- a/repository.go
+++ b/repository.go
@@ -93,7 +93,7 @@ func (r *Repository) DeleteRemote(name string) error {
}
// Clone clones a remote repository
-func (r *Repository) Clone(o *RepositoryCloneOptions) error {
+func (r *Repository) Clone(o *CloneOptions) error {
if err := o.Validate(); err != nil {
return err
}
@@ -118,7 +118,7 @@ func (r *Repository) Clone(o *RepositoryCloneOptions) error {
return err
}
- if err = remote.Fetch(&RemoteFetchOptions{Depth: o.Depth}); err != nil {
+ if err = remote.Fetch(&FetchOptions{Depth: o.Depth}); err != nil {
return err
}
@@ -133,7 +133,7 @@ func (r *Repository) Clone(o *RepositoryCloneOptions) error {
const refspecSingleBranch = "+refs/heads/%s:refs/remotes/%s/%[1]s"
func (r *Repository) updateRemoteConfig(
- remote *Remote, o *RepositoryCloneOptions, c *config.RemoteConfig,
+ remote *Remote, o *CloneOptions, c *config.RemoteConfig,
) error {
if o.SingleBranch {
head, err := core.ResolveReference(remote.Info().Refs, o.ReferenceName)
@@ -167,7 +167,7 @@ func (r *Repository) createReferences(ref *core.Reference) error {
}
// Pull incorporates changes from a remote repository into the current branch
-func (r *Repository) Pull(o *RepositoryPullOptions) error {
+func (r *Repository) Pull(o *PullOptions) error {
if err := o.Validate(); err != nil {
return err
}
@@ -194,7 +194,7 @@ func (r *Repository) Pull(o *RepositoryPullOptions) error {
defer remote.Disconnect()
- err = remote.Fetch(&RemoteFetchOptions{
+ err = remote.Fetch(&FetchOptions{
Depth: o.Depth,
})
diff --git a/repository_test.go b/repository_test.go
index 462fbcf..6ad0d1e 100644
--- a/repository_test.go
+++ b/repository_test.go
@@ -61,20 +61,18 @@ func (s *RepositorySuite) TearDownSuite(c *C) {
}
func (s *RepositorySuite) TestNewRepository(c *C) {
- r, err := NewMemoryRepository()
- c.Assert(err, IsNil)
+ r := NewMemoryRepository()
c.Assert(r, NotNil)
}
func (s *RepositorySuite) TestClone(c *C) {
- r, err := NewMemoryRepository()
- c.Assert(err, IsNil)
+ r := NewMemoryRepository()
head, err := r.Head()
c.Assert(err, Equals, core.ErrReferenceNotFound)
c.Assert(head, IsNil)
- err = r.Clone(&RepositoryCloneOptions{
+ err = r.Clone(&CloneOptions{
URL: RepositoryFixture,
})
@@ -109,14 +107,13 @@ func (s *RepositorySuite) TestClone(c *C) {
}
func (s *RepositorySuite) TestCloneSingleBranchAndNonHEAD(c *C) {
- r, err := NewMemoryRepository()
- c.Assert(err, IsNil)
+ r := NewMemoryRepository()
head, err := r.Head()
c.Assert(err, Equals, core.ErrReferenceNotFound)
c.Assert(head, IsNil)
- err = r.Clone(&RepositoryCloneOptions{
+ err = r.Clone(&CloneOptions{
URL: RepositoryFixture,
ReferenceName: core.ReferenceName("refs/heads/branch"),
SingleBranch: true,
@@ -147,14 +144,13 @@ func (s *RepositorySuite) TestCloneSingleBranchAndNonHEAD(c *C) {
}
func (s *RepositorySuite) TestCloneSingleBranch(c *C) {
- r, err := NewMemoryRepository()
- c.Assert(err, IsNil)
+ r := NewMemoryRepository()
head, err := r.Head()
c.Assert(err, Equals, core.ErrReferenceNotFound)
c.Assert(head, IsNil)
- err = r.Clone(&RepositoryCloneOptions{
+ err = r.Clone(&CloneOptions{
URL: RepositoryFixture,
SingleBranch: true,
})
@@ -184,10 +180,8 @@ func (s *RepositorySuite) TestCloneSingleBranch(c *C) {
}
func (s *RepositorySuite) TestCloneDetachedHEAD(c *C) {
- r, err := NewMemoryRepository()
- c.Assert(err, IsNil)
-
- err = r.Clone(&RepositoryCloneOptions{
+ r := NewMemoryRepository()
+ err := r.Clone(&CloneOptions{
URL: RepositoryFixture,
ReferenceName: core.ReferenceName("refs/tags/v1.0.0"),
})
@@ -200,10 +194,8 @@ func (s *RepositorySuite) TestCloneDetachedHEAD(c *C) {
}
func (s *RepositorySuite) TestCommit(c *C) {
- r, err := NewMemoryRepository()
- c.Assert(err, IsNil)
-
- err = r.Clone(&RepositoryCloneOptions{
+ r := NewMemoryRepository()
+ err := r.Clone(&CloneOptions{
URL: RepositoryFixture,
})
@@ -222,10 +214,8 @@ func (s *RepositorySuite) TestCommit(c *C) {
}
func (s *RepositorySuite) TestCommits(c *C) {
- r, err := NewMemoryRepository()
- c.Assert(err, IsNil)
-
- err = r.Clone(&RepositoryCloneOptions{URL: RepositoryFixture})
+ r := NewMemoryRepository()
+ err := r.Clone(&CloneOptions{URL: RepositoryFixture})
c.Assert(err, IsNil)
count := 0
@@ -288,10 +278,8 @@ func (s *RepositorySuite) TestObject(c *C) {
}
func (s *RepositorySuite) TestCommitIterClosePanic(c *C) {
- r, err := NewMemoryRepository()
- c.Assert(err, IsNil)
-
- err = r.Clone(&RepositoryCloneOptions{URL: RepositoryFixture})
+ r := NewMemoryRepository()
+ err := r.Clone(&CloneOptions{URL: RepositoryFixture})
c.Assert(err, IsNil)
commits, err := r.Commits()
@@ -300,10 +288,8 @@ func (s *RepositorySuite) TestCommitIterClosePanic(c *C) {
}
func (s *RepositorySuite) TestRef(c *C) {
- r, err := NewMemoryRepository()
- c.Assert(err, IsNil)
-
- err = r.Clone(&RepositoryCloneOptions{URL: RepositoryFixture})
+ r := NewMemoryRepository()
+ err := r.Clone(&CloneOptions{URL: RepositoryFixture})
c.Assert(err, IsNil)
ref, err := r.Ref(core.HEAD, false)
@@ -316,10 +302,8 @@ func (s *RepositorySuite) TestRef(c *C) {
}
func (s *RepositorySuite) TestRefs(c *C) {
- r, err := NewMemoryRepository()
- c.Assert(err, IsNil)
-
- err = r.Clone(&RepositoryCloneOptions{URL: RepositoryFixture})
+ r := NewMemoryRepository()
+ err := r.Clone(&CloneOptions{URL: RepositoryFixture})
c.Assert(err, IsNil)
c.Assert(err, IsNil)
diff --git a/tree_diff_test.go b/tree_diff_test.go
index 8e53a4f..40c7f94 100644
--- a/tree_diff_test.go
+++ b/tree_diff_test.go
@@ -39,7 +39,7 @@ func (s *DiffTreeSuite) SetUpSuite(c *C) {
s.repos = make(map[string]*Repository, 0)
for _, fixRepo := range fixtureRepos {
- s.repos[fixRepo.url], _ = NewMemoryRepository()
+ s.repos[fixRepo.url] = NewMemoryRepository()
f, err := os.Open(fixRepo.packfile)
c.Assert(err, IsNil)