@@ -37,16 +37,16 @@ func (o GitObject) String() string {
3737 return Stringify (o )
3838}
3939
40- // createRefRequest represents the payload for creating a reference.
41- type createRefRequest struct {
42- Ref * string `json:"ref"`
43- SHA * string `json:"sha"`
40+ // CreateRef represents the payload for creating a reference.
41+ type CreateRef struct {
42+ Ref string `json:"ref"`
43+ SHA string `json:"sha"`
4444}
4545
46- // updateRefRequest represents the payload for updating a reference.
47- type updateRefRequest struct {
48- SHA * string `json:"sha"`
49- Force * bool `json:"force"`
46+ // UpdateRef represents the payload for updating a reference.
47+ type UpdateRef struct {
48+ SHA string `json:"sha"`
49+ Force * bool `json:"force,omitempty "`
5050}
5151
5252// GetRef fetches a single reference in a repository.
@@ -123,24 +123,26 @@ func (s *GitService) ListMatchingRefs(ctx context.Context, owner, repo string, o
123123}
124124
125125// CreateRef creates a new ref in a repository.
126+ // The ref field must include the 'refs/' prefix (e.g., 'refs/heads/branch-name').
126127//
127128// GitHub API docs: https://docs.github.com/rest/git/refs#create-a-reference
128129//
129130//meta:operation POST /repos/{owner}/{repo}/git/refs
130- func (s * GitService ) CreateRef (ctx context.Context , owner , repo string , ref * Reference ) (* Reference , * Response , error ) {
131- if ref == nil {
132- return nil , nil , errors .New ("reference must be provided" )
133- }
134- if ref .Ref == nil {
131+ func (s * GitService ) CreateRef (ctx context.Context , owner , repo string , ref CreateRef ) (* Reference , * Response , error ) {
132+ if ref .Ref == "" {
135133 return nil , nil , errors .New ("ref must be provided" )
136134 }
137135
136+ if ref .SHA == "" {
137+ return nil , nil , errors .New ("sha must be provided" )
138+ }
139+
140+ if ! strings .HasPrefix (ref .Ref , "refs/" ) {
141+ return nil , nil , errors .New ("ref must start with 'refs/' prefix" )
142+ }
143+
138144 u := fmt .Sprintf ("repos/%v/%v/git/refs" , owner , repo )
139- req , err := s .client .NewRequest ("POST" , u , & createRefRequest {
140- // back-compat with previous behavior that didn't require 'refs/' prefix
141- Ref : Ptr ("refs/" + strings .TrimPrefix (* ref .Ref , "refs/" )),
142- SHA : ref .Object .SHA ,
143- })
145+ req , err := s .client .NewRequest ("POST" , u , ref )
144146 if err != nil {
145147 return nil , nil , err
146148 }
@@ -159,20 +161,18 @@ func (s *GitService) CreateRef(ctx context.Context, owner, repo string, ref *Ref
159161// GitHub API docs: https://docs.github.com/rest/git/refs#update-a-reference
160162//
161163//meta:operation PATCH /repos/{owner}/{repo}/git/refs/{ref}
162- func (s * GitService ) UpdateRef (ctx context.Context , owner , repo string , ref * Reference , force bool ) (* Reference , * Response , error ) {
163- if ref == nil {
164- return nil , nil , errors .New ("reference must be provided" )
165- }
166- if ref .Ref == nil {
164+ func (s * GitService ) UpdateRef (ctx context.Context , owner , repo , ref string , updateRef UpdateRef ) (* Reference , * Response , error ) {
165+ if ref == "" {
167166 return nil , nil , errors .New ("ref must be provided" )
168167 }
169168
170- refPath := strings .TrimPrefix (* ref .Ref , "refs/" )
169+ if updateRef .SHA == "" {
170+ return nil , nil , errors .New ("sha must be provided" )
171+ }
172+
173+ refPath := strings .TrimPrefix (ref , "refs/" )
171174 u := fmt .Sprintf ("repos/%v/%v/git/refs/%v" , owner , repo , refURLEscape (refPath ))
172- req , err := s .client .NewRequest ("PATCH" , u , & updateRefRequest {
173- SHA : ref .Object .SHA ,
174- Force : & force ,
175- })
175+ req , err := s .client .NewRequest ("PATCH" , u , updateRef )
176176 if err != nil {
177177 return nil , nil , err
178178 }
0 commit comments