Skip to content

Commit 9026bc3

Browse files
committed
Fix adding branch as protected to not allow pushing to it
1 parent d14a724 commit 9026bc3

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

cmd/hook.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,12 @@ func runHookPreReceive(c *cli.Context) error {
127127
}
128128

129129
if protectBranch != nil {
130-
if !protectBranch.CanPush {
131-
// check and deletion
132-
if newCommitID == git.EmptySHA {
133-
fail(fmt.Sprintf("branch %s is protected from deletion", branchName), "")
134-
} else {
135-
fail(fmt.Sprintf("protected branch %s can not be pushed to", branchName), "")
136-
//fail(fmt.Sprintf("branch %s is protected from force push", branchName), "")
137-
}
130+
// check and deletion
131+
if newCommitID == git.EmptySHA {
132+
fail(fmt.Sprintf("branch %s is protected from deletion", branchName), "")
133+
} else if !protectBranch.CanPush {
134+
fail(fmt.Sprintf("protected branch %s can not be pushed to", branchName), "")
135+
//fail(fmt.Sprintf("branch %s is protected from force push", branchName), "")
138136
}
139137
}
140138
}

public/js/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ function initProtectedBranch() {
625625
var $this = $(this);
626626
$.post($this.data('url'), {
627627
"_csrf": csrf,
628-
"canPush": true,
628+
"canPush": false,
629629
"branchName": $this.val(),
630630
},
631631
function (data) {
@@ -642,7 +642,7 @@ function initProtectedBranch() {
642642
var $this = $(this);
643643
$.post($this.data('url'), {
644644
"_csrf": csrf,
645-
"canPush": false,
645+
"canPush": true,
646646
"branchName": $this.data('val'),
647647
},
648648
function (data) {

routers/repo/setting.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ func ProtectedBranchPost(ctx *context.Context) {
520520

521521
canPush := ctx.QueryBool("canPush")
522522

523-
if canPush {
523+
if !canPush {
524524
if err := ctx.Repo.Repository.AddProtectedBranch(branchName, canPush); err != nil {
525525
ctx.Flash.Error(ctx.Tr("repo.settings.add_protected_branch_failed", branchName))
526526
ctx.JSON(200, map[string]string{

0 commit comments

Comments
 (0)