aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorDenis Denisov <denji@users.noreply.github.com>2017-02-21 17:02:10 +0200
committerLunny Xiao <xiaolunwen@gmail.com>2017-02-21 23:02:10 +0800
commitfd941db246e66244ec81f43d74b8358c06173fd6 (patch)
treebe563ff04f3b809b2d11489447086d5251e9b55a /cmd
parentfe5ff8e4b2b3c951fa85572f3760ee2a396247ac (diff)
downloadgitea-fd941db246e66244ec81f43d74b8358c06173fd6.tar.gz
gitea-fd941db246e66244ec81f43d74b8358c06173fd6.zip
Protected branches system (#339)
* Protected branches system * Moved default branch to branches section (`:org/:reponame/settings/branches`). * Initial support Protected Branch. - Admin does not restrict - Owner not to limit - To write permission restrictions * reformat tmpl * finished the UI and add/delete protected branch response * remove unused comment * indent all the template files and remove ru translations since we use crowdin * fix the push bug
Diffstat (limited to 'cmd')
-rw-r--r--cmd/serve.go4
-rw-r--r--cmd/update.go20
-rw-r--r--cmd/web.go5
3 files changed, 29 insertions, 0 deletions
diff --git a/cmd/serve.go b/cmd/serve.go
index 7141d85c92..f4a3c3d2c6 100644
--- a/cmd/serve.go
+++ b/cmd/serve.go
@@ -342,6 +342,10 @@ func runServ(c *cli.Context) error {
} else {
gitcmd = exec.Command(verb, repoPath)
}
+
+ os.Setenv(models.ProtectedBranchAccessMode, requestedMode.String())
+ os.Setenv(models.ProtectedBranchRepoID, fmt.Sprintf("%d", repo.ID))
+
gitcmd.Dir = setting.RepoRootPath
gitcmd.Stdout = os.Stdout
gitcmd.Stdin = os.Stdin
diff --git a/cmd/update.go b/cmd/update.go
index 4bbab9a3af..58e60493d0 100644
--- a/cmd/update.go
+++ b/cmd/update.go
@@ -6,9 +6,12 @@ package cmd
import (
"os"
+ "strconv"
+ "strings"
"github.com/urfave/cli"
+ "code.gitea.io/git"
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
@@ -48,6 +51,23 @@ func runUpdate(c *cli.Context) error {
log.GitLogger.Fatal(2, "First argument 'refName' is empty, shouldn't use")
}
+ // protected branch check
+ branchName := strings.TrimPrefix(args[0], git.BranchPrefix)
+ repoID, _ := strconv.ParseInt(os.Getenv(models.ProtectedBranchRepoID), 10, 64)
+ log.GitLogger.Trace("pushing to %d %v", repoID, branchName)
+ accessMode := models.ParseAccessMode(os.Getenv(models.ProtectedBranchAccessMode))
+ // skip admin or owner AccessMode
+ if accessMode == models.AccessModeWrite {
+ protectBranch, err := models.GetProtectedBranchBy(repoID, branchName)
+ if err != nil {
+ log.GitLogger.Fatal(2, "retrieve protected branches information failed")
+ }
+
+ if protectBranch != nil {
+ log.GitLogger.Fatal(2, "protected branches can not be pushed to")
+ }
+ }
+
task := models.UpdateTask{
UUID: os.Getenv("GITEA_UUID"),
RefName: args[0],
diff --git a/cmd/web.go b/cmd/web.go
index 03a87ca0d6..f9b4bdd270 100644
--- a/cmd/web.go
+++ b/cmd/web.go
@@ -421,6 +421,11 @@ func runWeb(ctx *cli.Context) error {
m.Post("/access_mode", repo.ChangeCollaborationAccessMode)
m.Post("/delete", repo.DeleteCollaboration)
})
+ m.Group("/branches", func() {
+ m.Combo("").Get(repo.ProtectedBranch).Post(repo.ProtectedBranchPost)
+ m.Post("/can_push", repo.ChangeProtectedBranch)
+ m.Post("/delete", repo.DeleteProtectedBranch)
+ })
m.Group("/hooks", func() {
m.Get("", repo.Webhooks)