From 7058bf9039ac243a3ac1b0eedf8a8291d3e5b6cb Mon Sep 17 00:00:00 2001 From: Nathan Parekh <33500247+nathanparekh@users.noreply.github.com> Date: Sun, 5 Jul 2026 18:46:27 -0700 Subject: [PATCH 1/3] create default branch when status is 200 but no branches exist --- internal/provider/branch_resource.go | 5 +++-- internal/provider/branch_resource_test.go | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/internal/provider/branch_resource.go b/internal/provider/branch_resource.go index ac50736..b1a87a3 100644 --- a/internal/provider/branch_resource.go +++ b/internal/provider/branch_resource.go @@ -283,13 +283,14 @@ func readBranchDatabase(ctx context.Context, state *BranchResourceModel, client } func createBranch(ctx context.Context, plan *BranchResourceModel, client *api.ClientWithResponses) diag.Diagnostics { - resp, err := client.V1ListAllBranches(ctx, plan.ParentProjectRef.ValueString()) + resp, err := client.V1ListAllBranchesWithResponse(ctx, plan.ParentProjectRef.ValueString()) if err != nil { msg := fmt.Sprintf("Unable to enable branching, got error: %s", err) return diag.Diagnostics{diag.NewErrorDiagnostic("Client Error", msg)} } // 1. Enable branching - if resp.StatusCode == http.StatusUnprocessableEntity { + if resp.StatusCode() == http.StatusUnprocessableEntity || + (resp.StatusCode() == http.StatusOK && len(*resp.JSON200) == 0) { httpResp, err := client.V1CreateABranchWithResponse(ctx, plan.ParentProjectRef.ValueString(), api.CreateBranchBody{ BranchName: "Production", }) diff --git a/internal/provider/branch_resource_test.go b/internal/provider/branch_resource_test.go index c9cc568..c4e57ed 100644 --- a/internal/provider/branch_resource_test.go +++ b/internal/provider/branch_resource_test.go @@ -29,7 +29,8 @@ func TestAccBranchResource(t *testing.T) { // Step 1: create gock.New(defaultApiEndpoint). Get(branchesApiPath). - Reply(http.StatusUnprocessableEntity) + Reply(http.StatusOK). + JSON([]api.BranchResponse{}) gock.New(defaultApiEndpoint). Post(branchesApiPath). Reply(http.StatusCreated). From b5e0f7015c6f04c51b0138b5d7bbe5bc8385506f Mon Sep 17 00:00:00 2001 From: Nathan Parekh <33500247+nathanparekh@users.noreply.github.com> Date: Sun, 5 Jul 2026 20:48:02 -0700 Subject: [PATCH 2/3] default branch should be default --- internal/provider/branch_resource.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/provider/branch_resource.go b/internal/provider/branch_resource.go index b1a87a3..f1e93dd 100644 --- a/internal/provider/branch_resource.go +++ b/internal/provider/branch_resource.go @@ -293,6 +293,7 @@ func createBranch(ctx context.Context, plan *BranchResourceModel, client *api.Cl (resp.StatusCode() == http.StatusOK && len(*resp.JSON200) == 0) { httpResp, err := client.V1CreateABranchWithResponse(ctx, plan.ParentProjectRef.ValueString(), api.CreateBranchBody{ BranchName: "Production", + IsDefault: Ptr(true), }) if err != nil { msg := fmt.Sprintf("Unable to enable branching, got error: %s", err) From 735cd07f14d417800d7358212add0a9113551e46 Mon Sep 17 00:00:00 2001 From: Nathan Parekh <33500247+nathanparekh@users.noreply.github.com> Date: Sun, 5 Jul 2026 21:34:48 -0700 Subject: [PATCH 3/3] add nil guard --- internal/provider/branch_resource.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/provider/branch_resource.go b/internal/provider/branch_resource.go index f1e93dd..022b9d3 100644 --- a/internal/provider/branch_resource.go +++ b/internal/provider/branch_resource.go @@ -289,6 +289,10 @@ func createBranch(ctx context.Context, plan *BranchResourceModel, client *api.Cl return diag.Diagnostics{diag.NewErrorDiagnostic("Client Error", msg)} } // 1. Enable branching + if resp.StatusCode() == http.StatusOK && resp.JSON200 == nil { + msg := fmt.Sprintf("Unable to list branches, got status %d: %s", resp.StatusCode(), resp.Body) + return diag.Diagnostics{diag.NewErrorDiagnostic("Client Error", msg)} + } if resp.StatusCode() == http.StatusUnprocessableEntity || (resp.StatusCode() == http.StatusOK && len(*resp.JSON200) == 0) { httpResp, err := client.V1CreateABranchWithResponse(ctx, plan.ParentProjectRef.ValueString(), api.CreateBranchBody{