Skip to content

Commit

Permalink
Merge pull request #162 from yabberyabber/fetch-error
Browse files Browse the repository at this point in the history
Fetch should return a unique error type when ref not found
  • Loading branch information
mcuadros committed Oct 9, 2020
2 parents b5b59f5 + 9d7bd4d commit 97741e7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 14 additions & 1 deletion remote.go
Expand Up @@ -32,6 +32,19 @@ var (
ErrExactSHA1NotSupported = errors.New("server does not support exact SHA1 refspec")
)

type NoMatchingRefSpecError struct {
refSpec config.RefSpec
}

func (e NoMatchingRefSpecError) Error() string {
return fmt.Sprintf("couldn't find remote ref %q", e.refSpec.Src())
}

func (e NoMatchingRefSpecError) Is(target error) bool {
_, ok := target.(NoMatchingRefSpecError)
return ok
}

const (
// This describes the maximum number of commits to walk when
// computing the haves to send to a server, for each ref in the
Expand Down Expand Up @@ -751,7 +764,7 @@ func doCalculateRefs(
})

if !matched && !s.IsWildcard() {
return fmt.Errorf("couldn't find remote ref %q", s.Src())
return NoMatchingRefSpecError{refSpec: s}
}

return err
Expand Down
2 changes: 2 additions & 0 deletions remote_test.go
Expand Up @@ -3,6 +3,7 @@ package git
import (
"bytes"
"context"
"errors"
"io"
"io/ioutil"
"os"
Expand Down Expand Up @@ -145,6 +146,7 @@ func (s *RemoteSuite) TestFetchNonExistantReference(c *C) {
})

c.Assert(err, ErrorMatches, "couldn't find remote ref.*")
c.Assert(errors.Is(err, NoMatchingRefSpecError{}), Equals, true)
}

func (s *RemoteSuite) TestFetchContext(c *C) {
Expand Down

0 comments on commit 97741e7

Please sign in to comment.