@@ -277,15 +277,6 @@ func resourceGithubRepositoryFileRead(ctx context.Context, d *schema.ResourceDat
277277
278278 opts := & github.RepositoryContentGetOptions {}
279279
280- if err := checkRepositoryBranchExists (ctx , client , owner , repoName , branch ); err != nil {
281- if d .Get ("autocreate_branch" ).(bool ) {
282- branch = d .Get ("autocreate_branch_source_branch" ).(string )
283- } else {
284- tflog .Info (ctx , "Removing repository path from state because the branch no longer exists in GitHub" )
285- d .SetId ("" )
286- return nil
287- }
288- }
289280 opts .Ref = branch
290281
291282 fc , _ , _ , err := client .Repositories .GetContents (ctx , owner , repoName , file , opts )
@@ -294,6 +285,7 @@ func resourceGithubRepositoryFileRead(ctx context.Context, d *schema.ResourceDat
294285 if errors .As (err , & errorResponse ) && errorResponse .Response .StatusCode == http .StatusTooManyRequests {
295286 return diag .FromErr (err )
296287 }
288+ return diag .FromErr (deleteResourceOn404AndSwallow304OtherwiseReturnError (err , d , "repository file %s/%s:%s:%s" , owner , repoName , file , branch ))
297289 }
298290 if fc == nil {
299291 tflog .Info (ctx , "Removing repository path from state because it no longer exists in GitHub" )
@@ -378,21 +370,12 @@ func resourceGithubRepositoryFileUpdate(ctx context.Context, d *schema.ResourceD
378370
379371 repo := d .Get ("repository" ).(string )
380372 file := d .Get ("file" ).(string )
373+ branch := d .Get ("branch" ).(string )
374+
381375 ctx = tflog .SetField (ctx , "repository" , repo )
382376 ctx = tflog .SetField (ctx , "file" , file )
383377 ctx = tflog .SetField (ctx , "owner" , owner )
384-
385- branch := d .Get ("branch" ).(string )
386-
387- if err := checkRepositoryBranchExists (ctx , client , owner , repo , branch ); err != nil {
388- if d .Get ("autocreate_branch" ).(bool ) {
389- if err := resourceGithubRepositoryFileCreateBranch (ctx , d , meta ); err != nil {
390- return diag .FromErr (err )
391- }
392- } else {
393- return diag .FromErr (err )
394- }
395- }
378+ ctx = tflog .SetField (ctx , "branch" , branch )
396379
397380 opts := resourceGithubRepositoryFileOptions (d )
398381
@@ -435,16 +418,6 @@ func resourceGithubRepositoryFileDelete(ctx context.Context, d *schema.ResourceD
435418 }
436419
437420 branch := d .Get ("branch" ).(string )
438-
439- if err := checkRepositoryBranchExists (ctx , client , owner , repo , branch ); err != nil {
440- if d .Get ("autocreate_branch" ).(bool ) {
441- if err := resourceGithubRepositoryFileCreateBranch (ctx , d , meta ); err != nil {
442- return diag .FromErr (err )
443- }
444- } else {
445- return diag .FromErr (err )
446- }
447- }
448421 opts .Branch = github .Ptr (branch )
449422
450423 _ , _ , err := client .Repositories .DeleteFile (ctx , owner , repo , file , opts )
0 commit comments