summaryrefslogtreecommitdiffstats
path: root/models/branches.go
diff options
context:
space:
mode:
authorLauris BH <lauris@nix.lv>2017-05-02 03:49:55 +0300
committerLunny Xiao <xiaolunwen@gmail.com>2017-05-02 08:49:55 +0800
commit0144817971012bed2b00784064c37b1e7e5acff3 (patch)
treec1a6a95b1a1958901367c50031dcee5e85589872 /models/branches.go
parent3ebbdfaa757e1299b3a495c8fc711d574c0d278f (diff)
downloadgitea-0144817971012bed2b00784064c37b1e7e5acff3.tar.gz
gitea-0144817971012bed2b00784064c37b1e7e5acff3.zip
Do not allow commiting to protected branch from online editor (#1502)
* Do not allow commiting to protected branch from online editor * Add editor integration tests for adding new file and not allowing to add new file to protected branch
Diffstat (limited to 'models/branches.go')
-rw-r--r--models/branches.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/models/branches.go b/models/branches.go
index 322d33daae..a71c0e9622 100644
--- a/models/branches.go
+++ b/models/branches.go
@@ -63,6 +63,23 @@ func (repo *Repository) GetProtectedBranches() ([]*ProtectedBranch, error) {
return protectedBranches, x.Find(&protectedBranches, &ProtectedBranch{RepoID: repo.ID})
}
+// IsProtectedBranch checks if branch is protected
+func (repo *Repository) IsProtectedBranch(branchName string) (bool, error) {
+ protectedBranch := &ProtectedBranch{
+ RepoID: repo.ID,
+ BranchName: branchName,
+ }
+
+ has, err := x.Get(protectedBranch)
+ if err != nil {
+ return true, err
+ } else if has {
+ return true, nil
+ }
+
+ return false, nil
+}
+
// AddProtectedBranch add protection to branch
func (repo *Repository) AddProtectedBranch(branchName string, canPush bool) error {
protectedBranch := &ProtectedBranch{