aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2018-12-12 16:46:17 +0800
committerLauris BH <lauris@nix.lv>2018-12-12 10:46:17 +0200
commitaf6bce3ad5a9c1b4173374201f7b10ac4811f26a (patch)
treedbe686c76eab92290f367e21872808035022043f /cmd
parent6db7dbd333204bcff50716e4840deee28e09c2f9 (diff)
downloadgitea-af6bce3ad5a9c1b4173374201f7b10ac4811f26a.tar.gz
gitea-af6bce3ad5a9c1b4173374201f7b10ac4811f26a.zip
fix detect force push failure on deletion of protected branches (#5522)
Diffstat (limited to 'cmd')
-rw-r--r--cmd/hook.go24
1 files changed, 12 insertions, 12 deletions
diff --git a/cmd/hook.go b/cmd/hook.go
index fb54ca186a..63cb605929 100644
--- a/cmd/hook.go
+++ b/cmd/hook.go
@@ -112,10 +112,15 @@ func runHookPreReceive(c *cli.Context) error {
branchName := strings.TrimPrefix(refFullName, git.BranchPrefix)
protectBranch, err := private.GetProtectedBranchBy(repoID, branchName)
if err != nil {
- log.GitLogger.Fatal(2, "retrieve protected branches information failed")
+ fail("Internal error", fmt.Sprintf("retrieve protected branches information failed: %v", err))
}
if protectBranch != nil && protectBranch.IsProtected() {
+ // check and deletion
+ if newCommitID == git.EmptySHA {
+ fail(fmt.Sprintf("branch %s is protected from deletion", branchName), "")
+ }
+
// detect force push
if git.EmptySHA != oldCommitID {
output, err := git.NewCommand("rev-list", "--max-count=1", oldCommitID, "^"+newCommitID).RunInDir(repoPath)
@@ -126,17 +131,12 @@ func runHookPreReceive(c *cli.Context) error {
}
}
- // check and deletion
- if newCommitID == git.EmptySHA {
- fail(fmt.Sprintf("branch %s is protected from deletion", branchName), "")
- } else {
- userID, _ := strconv.ParseInt(userIDStr, 10, 64)
- canPush, err := private.CanUserPush(protectBranch.ID, userID)
- if err != nil {
- fail("Internal error", "Fail to detect user can push: %v", err)
- } else if !canPush {
- fail(fmt.Sprintf("protected branch %s can not be pushed to", branchName), "")
- }
+ userID, _ := strconv.ParseInt(userIDStr, 10, 64)
+ canPush, err := private.CanUserPush(protectBranch.ID, userID)
+ if err != nil {
+ fail("Internal error", "Fail to detect user can push: %v", err)
+ } else if !canPush {
+ fail(fmt.Sprintf("protected branch %s can not be pushed to", branchName), "")
}
}
}