diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/git/error.go | 22 | ||||
-rw-r--r-- | modules/git/repo_branch.go | 13 | ||||
-rw-r--r-- | modules/middleware/repo.go | 16 |
3 files changed, 45 insertions, 6 deletions
diff --git a/modules/git/error.go b/modules/git/error.go new file mode 100644 index 0000000000..c86c56e546 --- /dev/null +++ b/modules/git/error.go @@ -0,0 +1,22 @@ +// Copyright 2015 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package git + +import ( + "fmt" +) + +type ErrUnsupportedVersion struct { + Required string +} + +func IsErrUnsupportedVersion(err error) bool { + _, ok := err.(ErrUnsupportedVersion) + return ok +} + +func (err ErrUnsupportedVersion) Error() string { + return fmt.Sprintf("Operation requires higher version [required: %s]", err.Required) +} diff --git a/modules/git/repo_branch.go b/modules/git/repo_branch.go index a4e060533c..86c4f538b4 100644 --- a/modules/git/repo_branch.go +++ b/modules/git/repo_branch.go @@ -35,3 +35,16 @@ func (repo *Repository) GetBranches() ([]string, error) { } return branches, nil } + +// SetDefaultBranch sets default branch of repository. +func (repo *Repository) SetDefaultBranch(branchName string) error { + if gitVer.LessThan(MustParseVersion("1.7.10")) { + return ErrUnsupportedVersion{"1.7.10"} + } + + _, stderr, err := com.ExecCmdDir(repo.Path, "git", "symbolic-ref", "HEAD", "refs/heads/"+branchName) + if err != nil { + return concatenateError(err, stderr) + } + return nil +} diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go index c7481743d4..a78e079d8d 100644 --- a/modules/middleware/repo.go +++ b/modules/middleware/repo.go @@ -274,19 +274,23 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler { return } - mode, err := models.AccessLevel(ctx.User, repo) - if err != nil { - ctx.Handle(500, "AccessLevel", err) - return + // Admin has super access. + if ctx.User.IsAdmin { + ctx.Repo.AccessMode = models.ACCESS_MODE_OWNER + } else { + mode, err := models.AccessLevel(ctx.User, repo) + if err != nil { + ctx.Handle(500, "AccessLevel", err) + return + } + ctx.Repo.AccessMode = mode } - ctx.Repo.AccessMode = mode // Check access. if ctx.Repo.AccessMode == models.ACCESS_MODE_NONE { ctx.Handle(404, "no access right", err) return } - ctx.Data["HasAccess"] = true if repo.IsMirror { |