diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2016-08-25 17:25:31 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2016-08-25 17:25:31 +0200 |
commit | a3418c5e0a3c6e925b5a4fb3ecb1d3db56408d1a (patch) | |
tree | 23ab46cb3269a104d9b69e0d1a1bec3c340df112 /remote.go | |
parent | 0f97041639b55bc4631145e2053a47a1eb8cdef0 (diff) | |
download | go-git-a3418c5e0a3c6e925b5a4fb3ecb1d3db56408d1a.tar.gz |
Repository: Clone protection if non empty object storage, Remote: NoErrAlreadyUpToDate
Diffstat (limited to 'remote.go')
-rw-r--r-- | remote.go | 22 |
1 files changed, 17 insertions, 5 deletions
@@ -1,6 +1,7 @@ package git import ( + "errors" "fmt" "io" @@ -11,6 +12,8 @@ import ( "gopkg.in/src-d/go-git.v4/formats/packfile" ) +var NoErrAlreadyUpToDate = errors.New("already up-to-date") + // Remote represents a connection to a remote repository type Remote struct { c *config.RemoteConfig @@ -87,6 +90,10 @@ func (r *Remote) Fetch(o *FetchOptions) (err error) { return err } + if len(refs) == 0 { + return NoErrAlreadyUpToDate + } + req, err := r.buildRequest(r.s.ReferenceStorage(), o, refs) if err != nil { return err @@ -107,17 +114,22 @@ func (r *Remote) Fetch(o *FetchOptions) (err error) { func (r *Remote) getWantedReferences(spec []config.RefSpec) ([]*core.Reference, error) { var refs []*core.Reference + return refs, r.Refs().ForEach(func(ref *core.Reference) error { + if ref.Type() != core.HashReference { + return nil + } - return refs, r.Refs().ForEach(func(r *core.Reference) error { - if r.Type() != core.HashReference { + if !config.MatchAny(spec, ref.Name()) { return nil } - if config.MatchAny(spec, r.Name()) { - refs = append(refs, r) + _, err := r.s.ObjectStorage().Get(ref.Hash()) + if err == core.ErrObjectNotFound { + refs = append(refs, ref) + return nil } - return nil + return err }) } |