diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2016-08-19 17:42:13 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2016-08-19 17:42:13 +0200 |
commit | 1d56b98d9b02e20f7feea542c75746eab34fad63 (patch) | |
tree | 006e8c3ac5e40353032109a5259bb28c37751996 /options.go | |
parent | b1d116c59f7656dc8d5ff7294ba8f8a82c51bfd1 (diff) | |
download | go-git-1d56b98d9b02e20f7feea542c75746eab34fad63.tar.gz |
Remote.Fetch base on RefSpec, improvement of the responsabilities separation
Diffstat (limited to 'options.go')
-rw-r--r-- | options.go | 38 |
1 files changed, 27 insertions, 11 deletions
@@ -2,19 +2,23 @@ package git import ( "errors" + "fmt" "gopkg.in/src-d/go-git.v3/clients/common" + "gopkg.in/src-d/go-git.v4/config" "gopkg.in/src-d/go-git.v4/core" ) const ( // DefaultRemoteName name of the default Remote, just like git command - DefaultRemoteName = "origin" + DefaultRemoteName = "origin" + DefaultSingleBranchRefSpec = "+refs/heads/%s:refs/remotes/%s/%[1]s" + DefaultRefSpec = "+refs/heads/*:refs/remotes/%s/*" ) var ( - ErrMissingURL = errors.New("URL field is required") - ErrMissingReferences = errors.New("references cannot be empty") + ErrMissingURL = errors.New("URL field is required") + ErrInvalidRefSpec = errors.New("invalid refspec") ) // RepositoryCloneOptions describe how a clone should be perform @@ -50,6 +54,22 @@ func (o *RepositoryCloneOptions) Validate() error { return nil } +func (o *RepositoryCloneOptions) refSpec(s core.ReferenceStorage) (config.RefSpec, error) { + var spec string + if o.SingleBranch { + head, err := core.ResolveReference(s, o.ReferenceName) + if err != nil { + return "", err + } + + spec = fmt.Sprintf(DefaultSingleBranchRefSpec, head.Name().Short(), o.RemoteName) + } else { + spec = fmt.Sprintf(DefaultRefSpec, o.RemoteName) + } + + return config.RefSpec(spec), nil +} + // RepositoryPullOptions describe how a pull should be perform type RepositoryPullOptions struct { // Name of the remote to be pulled @@ -77,18 +97,14 @@ func (o *RepositoryPullOptions) Validate() error { // RemoteFetchOptions describe how a fetch should be perform type RemoteFetchOptions struct { - // Remote branchs to fetch - References []*core.Reference - // Local references present on the local storage - LocalReferences []*core.Reference - // Limit fetching to the specified number of commits - Depth int + RefSpec config.RefSpec + Depth int } // Validate validate the fields and set the default values func (o *RemoteFetchOptions) Validate() error { - if len(o.References) == 0 { - return ErrMissingReferences + if !o.RefSpec.IsValid() { + return ErrInvalidRefSpec } return nil |