diff --git a/github/git_refs.go b/github/git_refs.go index 3f381d5f2b6..fe16880e7b0 100644 --- a/github/git_refs.go +++ b/github/git_refs.go @@ -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 } diff --git a/github/git_refs_test.go b/github/git_refs_test.go index 3cae3c085fd..6c8a1d87951 100644 --- a/github/git_refs_test.go +++ b/github/git_refs_test.go @@ -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() @@ -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) }