diff --git a/cmd/lakectl/cmd/branch_protect.go b/cmd/lakectl/cmd/branch_protect.go index 9005b57c3a3..2079011de74 100644 --- a/cmd/lakectl/cmd/branch_protect.go +++ b/cmd/lakectl/cmd/branch_protect.go @@ -62,9 +62,12 @@ var branchProtectAddCmd = &cobra.Command{ rules = append(rules, apigen.BranchProtectionRule{ Pattern: args[1], }) - setResp, err := client.SetBranchProtectionRulesWithResponse(cmd.Context(), u.Repository, &apigen.SetBranchProtectionRulesParams{ - IfMatch: swag.String(resp.HTTPResponse.Header.Get("ETag")), - }, rules) + params := &apigen.SetBranchProtectionRulesParams{} + etag := swag.String(resp.HTTPResponse.Header.Get("ETag")) + if etag != nil && *etag != "" { + params.IfMatch = etag + } + setResp, err := client.SetBranchProtectionRulesWithResponse(cmd.Context(), u.Repository, params, rules) DieOnErrorOrUnexpectedStatusCode(setResp, err, http.StatusNoContent) }, } diff --git a/esti/golden/lakectl_branch_protection_list.term.golden b/esti/golden/lakectl_branch_protection_list.term.golden new file mode 100644 index 00000000000..a4dbeaa7d5f --- /dev/null +++ b/esti/golden/lakectl_branch_protection_list.term.golden @@ -0,0 +1,2 @@ +${BRANCH} + diff --git a/esti/lakectl_test.go b/esti/lakectl_test.go index 1ed9ca04627..ece5cd72cd0 100644 --- a/esti/lakectl_test.go +++ b/esti/lakectl_test.go @@ -811,3 +811,17 @@ func TestLakectlUsage(t *testing.T) { runCmd(t, r.Replace("{lakectl} repo list"), false, false, nil) RunCmdAndVerifyFailureWithFile(t, r.Replace("{lakectl} usage summary"), false, "lakectl_usage_summary", vars) } + +func TestLakectlBranchProtection(t *testing.T) { + repoName := generateUniqueRepositoryName() + storage := generateUniqueStorageNamespace(repoName) + vars := map[string]string{ + "REPO": repoName, + "STORAGE": storage, + "BRANCH": mainBranch, + } + RunCmdAndVerifySuccessWithFile(t, Lakectl()+" repo create lakefs://"+repoName+" "+storage, false, "lakectl_repo_create", vars) + + RunCmdAndVerifySuccessWithFile(t, Lakectl()+" branch-protect add lakefs://"+repoName+" "+mainBranch, false, "lakectl_empty", vars) + RunCmdAndVerifySuccessWithFile(t, Lakectl()+" branch-protect list lakefs://"+repoName, false, "lakectl_branch_protection_list.term", vars) +}