aboutsummaryrefslogtreecommitdiffstats
path: root/routers/private
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2024-08-06 21:32:49 +0800
committerGitHub <noreply@github.com>2024-08-06 13:32:49 +0000
commitdf7f1c2eadac24f64adf3d823a7642a6eccf77f3 (patch)
tree6896c20f779367f5749547e60fdcf302c67095d3 /routers/private
parentde175e3b06e623280058278cdb0a62de7443cd86 (diff)
downloadgitea-df7f1c2eadac24f64adf3d823a7642a6eccf77f3.tar.gz
gitea-df7f1c2eadac24f64adf3d823a7642a6eccf77f3.zip
Fix protected branch files detection on pre_receive hook (#31778)
Fix #31738 When pushing a new branch, the old commit is zero. Most git commands cannot recognize the zero commit id. To get the changed files in the push, we need to get the first diverge commit of this branch. In most situations, we could check commits one by one until one commit is contained by another branch. Then we will think that commit is the diverge point. And in a pre-receive hook, this will be more difficult because all commits haven't been merged and they actually stored in a temporary place by git. So we need to bring some envs to let git know the commit exist.
Diffstat (limited to 'routers/private')
-rw-r--r--routers/private/hook_pre_receive.go4
1 files changed, 2 insertions, 2 deletions
diff --git a/routers/private/hook_pre_receive.go b/routers/private/hook_pre_receive.go
index 8853875014..73fe9b886c 100644
--- a/routers/private/hook_pre_receive.go
+++ b/routers/private/hook_pre_receive.go
@@ -235,7 +235,7 @@ func preReceiveBranch(ctx *preReceiveContext, oldCommitID, newCommitID string, r
globs := protectBranch.GetProtectedFilePatterns()
if len(globs) > 0 {
- _, err := pull_service.CheckFileProtection(gitRepo, oldCommitID, newCommitID, globs, 1, ctx.env)
+ _, err := pull_service.CheckFileProtection(gitRepo, branchName, oldCommitID, newCommitID, globs, 1, ctx.env)
if err != nil {
if !models.IsErrFilePathProtected(err) {
log.Error("Unable to check file protection for commits from %s to %s in %-v: %v", oldCommitID, newCommitID, repo, err)
@@ -293,7 +293,7 @@ func preReceiveBranch(ctx *preReceiveContext, oldCommitID, newCommitID string, r
// Allow commits that only touch unprotected files
globs := protectBranch.GetUnprotectedFilePatterns()
if len(globs) > 0 {
- unprotectedFilesOnly, err := pull_service.CheckUnprotectedFiles(gitRepo, oldCommitID, newCommitID, globs, ctx.env)
+ unprotectedFilesOnly, err := pull_service.CheckUnprotectedFiles(gitRepo, branchName, oldCommitID, newCommitID, globs, ctx.env)
if err != nil {
log.Error("Unable to check file protection for commits from %s to %s in %-v: %v", oldCommitID, newCommitID, repo, err)
ctx.JSON(http.StatusInternalServerError, private.Response{