@@ -421,16 +421,28 @@ If the SHA is not provided, the tool will attempt to acquire it by fetching the
421421 currentFileContent , _ , respContents , err := client .Repositories .GetContents (ctx , owner , repo , path , getOpts )
422422 defer func () { _ = respContents .Body .Close () }()
423423
424- if err == nil && currentFileContent != nil {
425- opts .SHA = currentFileContent .SHA
426- fileContent , resp , err = client .Repositories .CreateFile (ctx , owner , repo , path , opts )
427- if err != nil {
428- return ghErrors .NewGitHubAPIErrorResponse (ctx ,
429- "failed to create/update file after retrieving current SHA" ,
430- resp ,
431- err ,
432- ), nil , nil
424+ if err == nil {
425+ if currentFileContent != nil && currentFileContent .SHA != nil {
426+ opts .SHA = currentFileContent .SHA
427+ fileContent , resp , err = client .Repositories .CreateFile (ctx , owner , repo , path , opts )
428+ defer func () { _ = resp .Body .Close () }()
429+
430+ if err != nil {
431+ return ghErrors .NewGitHubAPIErrorResponse (ctx ,
432+ "failed to create/update file after retrieving current SHA" ,
433+ resp ,
434+ err ,
435+ ), nil , nil
436+ }
437+ } else {
438+ return utils .NewToolResultError ("file content SHA is nil, cannot update the file" ), nil , nil
433439 }
440+ } else {
441+ return ghErrors .NewGitHubAPIErrorResponse (ctx ,
442+ "failed to get file SHA for update" ,
443+ resp ,
444+ err ,
445+ ), nil , nil
434446 }
435447 } else {
436448 return ghErrors .NewGitHubAPIErrorResponse (ctx ,
0 commit comments