diff options
Diffstat (limited to 'models/repo_branch.go')
-rw-r--r-- | models/repo_branch.go | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/models/repo_branch.go b/models/repo_branch.go index 6c5b7ec8..de0ee26d 100644 --- a/models/repo_branch.go +++ b/models/repo_branch.go @@ -187,6 +187,13 @@ func UpdateOrgProtectBranch(repo *Repository, protectBranch *ProtectBranch, whit protectBranch.WhitelistTeamIDs = strings.Join(base.Int64sToStrings(validTeamIDs), ",") } + // Make sure protectBranch.ID is not 0 for whitelists + if protectBranch.ID == 0 { + if _, err = x.Insert(protectBranch); err != nil { + return fmt.Errorf("Insert: %v", err) + } + } + // Merge users and members of teams var whitelists []*ProtectBranchWhitelist if hasUsersChanged || hasTeamsChanged { @@ -226,12 +233,6 @@ func UpdateOrgProtectBranch(repo *Repository, protectBranch *ProtectBranch, whit return err } - if protectBranch.ID == 0 { - if _, err = sess.Insert(protectBranch); err != nil { - return fmt.Errorf("Insert: %v", err) - } - } - if _, err = sess.Id(protectBranch.ID).AllCols().Update(protectBranch); err != nil { return fmt.Errorf("Update: %v", err) } |