@@ -21,7 +21,7 @@ import (
2121 "fmt"
2222
2323 "github.com/fluxcd/go-git-providers/gitprovider"
24- "github.com/google/go-github/v72 /github"
24+ "github.com/google/go-github/v75 /github"
2525)
2626
2727var githubNewFileMode = "100644"
@@ -98,7 +98,7 @@ func (c *CommitClient) Create(ctx context.Context, branch string, message string
9898 }
9999
100100 latestCommitSHA := commits [0 ].Get ().Sha
101- nCommit , _ , err := c .c .Client ().Git .CreateCommit (ctx , c .ref .GetIdentity (), c .ref .GetRepository (), & github.Commit {
101+ nCommit , _ , err := c .c .Client ().Git .CreateCommit (ctx , c .ref .GetIdentity (), c .ref .GetRepository (), github.Commit {
102102 Message : & message ,
103103 Tree : tree ,
104104 Parents : []* github.Commit {
@@ -110,16 +110,18 @@ func (c *CommitClient) Create(ctx context.Context, branch string, message string
110110 if err != nil {
111111 return nil , err
112112 }
113+ if nCommit .SHA == nil {
114+ // The UpdateRef API requires a SHA.
115+ return nil , fmt .Errorf ("created commit has no SHA" )
116+ }
113117
114118 ref := "refs/heads/" + branch
115- ghRef := & github.Reference {
116- Ref : & ref ,
117- Object : & github.GitObject {
118- SHA : nCommit .SHA ,
119- },
119+ updateRef := github.UpdateRef {
120+ SHA : * nCommit .SHA ,
121+ Force : github .Ptr (true ),
120122 }
121123
122- if _ , _ , err := c .c .Client ().Git .UpdateRef (ctx , c .ref .GetIdentity (), c .ref .GetRepository (), ghRef , true ); err != nil {
124+ if _ , _ , err := c .c .Client ().Git .UpdateRef (ctx , c .ref .GetIdentity (), c .ref .GetRepository (), ref , updateRef ); err != nil {
123125 return nil , err
124126 }
125127
0 commit comments