This commit is contained in:
parent
716c2918be
commit
e6362f3d23
1 changed files with 12 additions and 12 deletions
12
cmd/hook.go
12
cmd/hook.go
|
@ -112,10 +112,15 @@ func runHookPreReceive(c *cli.Context) error {
|
||||||
branchName := strings.TrimPrefix(refFullName, git.BranchPrefix)
|
branchName := strings.TrimPrefix(refFullName, git.BranchPrefix)
|
||||||
protectBranch, err := private.GetProtectedBranchBy(repoID, branchName)
|
protectBranch, err := private.GetProtectedBranchBy(repoID, branchName)
|
||||||
if err != nil {
|
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() {
|
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
|
// detect force push
|
||||||
if git.EmptySHA != oldCommitID {
|
if git.EmptySHA != oldCommitID {
|
||||||
output, err := git.NewCommand("rev-list", "--max-count=1", oldCommitID, "^"+newCommitID).RunInDir(repoPath)
|
output, err := git.NewCommand("rev-list", "--max-count=1", oldCommitID, "^"+newCommitID).RunInDir(repoPath)
|
||||||
|
@ -126,10 +131,6 @@ 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)
|
userID, _ := strconv.ParseInt(userIDStr, 10, 64)
|
||||||
canPush, err := private.CanUserPush(protectBranch.ID, userID)
|
canPush, err := private.CanUserPush(protectBranch.ID, userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -139,7 +140,6 @@ func runHookPreReceive(c *cli.Context) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue