Skip to content

Commit 3ff5a6a

Browse files
authored
Fix missing message in git hook when pull requests disabled on fork (#22625)
And also the other way around, it would show an non-working URL in the message when pull requests are disabled on the base repository but enabled on the fork.
1 parent d283a31 commit 3ff5a6a

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

routers/private/hook_post_receive.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,6 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) {
173173
return
174174
}
175175

176-
if !repo.AllowsPulls() {
177-
// We can stop there's no need to go any further
178-
ctx.JSON(http.StatusOK, private.HookPostReceiveResult{
179-
RepoWasEmpty: wasEmpty,
180-
})
181-
return
182-
}
183176
baseRepo = repo
184177

185178
if repo.IsFork {
@@ -191,7 +184,17 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) {
191184
})
192185
return
193186
}
194-
baseRepo = repo.BaseRepo
187+
if repo.BaseRepo.AllowsPulls() {
188+
baseRepo = repo.BaseRepo
189+
}
190+
}
191+
192+
if !baseRepo.AllowsPulls() {
193+
// We can stop there's no need to go any further
194+
ctx.JSON(http.StatusOK, private.HookPostReceiveResult{
195+
RepoWasEmpty: wasEmpty,
196+
})
197+
return
195198
}
196199
}
197200

@@ -217,14 +220,14 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) {
217220
branch = fmt.Sprintf("%s:%s", repo.OwnerName, branch)
218221
}
219222
results = append(results, private.HookPostReceiveBranchResult{
220-
Message: setting.Git.PullRequestPushMessage && repo.AllowsPulls(),
223+
Message: setting.Git.PullRequestPushMessage && baseRepo.AllowsPulls(),
221224
Create: true,
222225
Branch: branch,
223226
URL: fmt.Sprintf("%s/compare/%s...%s", baseRepo.HTMLURL(), util.PathEscapeSegments(baseRepo.DefaultBranch), util.PathEscapeSegments(branch)),
224227
})
225228
} else {
226229
results = append(results, private.HookPostReceiveBranchResult{
227-
Message: setting.Git.PullRequestPushMessage && repo.AllowsPulls(),
230+
Message: setting.Git.PullRequestPushMessage && baseRepo.AllowsPulls(),
228231
Create: false,
229232
Branch: branch,
230233
URL: fmt.Sprintf("%s/pulls/%d", baseRepo.HTMLURL(), pr.Index),

0 commit comments

Comments
 (0)