Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion github/git_refs.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ func (s *GitService) GetRef(ctx context.Context, owner string, repo string, ref
resp, err := s.client.Do(ctx, req, r)
if _, ok := err.(*json.UnmarshalTypeError); ok {
// Multiple refs, means there wasn't an exact match.
return nil, resp, errors.New("no exact match found for this ref")
return nil, resp, errors.New("multiple matches found for this ref")
} else if resp.StatusCode == 404 {
// No ref, there was no match for the ref
return nil, resp, errors.New("no match found for this ref")
} else if err != nil {
return nil, resp, err
}
Expand Down
19 changes: 18 additions & 1 deletion github/git_refs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,23 @@ func TestGitService_GetRef_singleRef(t *testing.T) {
}
}

func TestGitService_GetRef_noRefs(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()

mux.HandleFunc("/repos/o/r/git/refs/heads/b", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
w.WriteHeader(http.StatusNotFound)
fmt.Fprint(w, "[]")
})

_, _, err := client.Git.GetRef(context.Background(), "o", "r", "refs/heads/b")
want := "no match found for this ref"
if err.Error() != want {
t.Errorf("Git.GetRef returned %+v, want %+v", err, want)
}
}

func TestGitService_GetRef_multipleRefs(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
Expand Down Expand Up @@ -87,7 +104,7 @@ func TestGitService_GetRef_multipleRefs(t *testing.T) {
})

_, _, err := client.Git.GetRef(context.Background(), "o", "r", "refs/heads/b")
want := "no exact match found for this ref"
want := "multiple matches found for this ref"
if err.Error() != want {
t.Errorf("Git.GetRef returned %+v, want %+v", err, want)
}
Expand Down