diff options
author | Giteabot <teabot@gitea.io> | 2024-09-02 18:28:00 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-02 18:28:00 +0800 |
commit | 6f5748c50752e4b1f99d532a34a57bd773e466b8 (patch) | |
tree | 0604a3d28d03223f834b422e7b2e3d79f433a562 /cmd | |
parent | cc1520221a9689b4725b0e8668ce58f95e787130 (diff) | |
download | gitea-6f5748c50752e4b1f99d532a34a57bd773e466b8.tar.gz gitea-6f5748c50752e4b1f99d532a34a57bd773e466b8.zip |
Prevent update pull refs manually and will not affect other refs update (#31931) (#31955)
Backport #31931 by @lunny
All refs under `refs/pull` should only be changed from Gitea inside but
not by pushing from outside of Gitea.
This PR will prevent the pull refs update but allow other refs to be
updated on the same pushing with `--mirror` operations.
The main changes are to add checks on `update` hook but not
`pre-receive` because `update` will be invoked by every ref but
`pre-receive` will revert all changes once one ref update fails.
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/hook.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/cmd/hook.go b/cmd/hook.go index 6e31710caf..e8a8b1f4ad 100644 --- a/cmd/hook.go +++ b/cmd/hook.go @@ -290,8 +290,22 @@ Gitea or set your environment appropriately.`, "") return nil } +// runHookUpdate avoid to do heavy operations on update hook because it will be +// invoked for every ref update which does not like pre-receive and post-receive func runHookUpdate(c *cli.Context) error { + if isInternal, _ := strconv.ParseBool(os.Getenv(repo_module.EnvIsInternal)); isInternal { + return nil + } + // Update is empty and is kept only for backwards compatibility + if len(os.Args) < 3 { + return nil + } + refName := git.RefName(os.Args[len(os.Args)-3]) + if refName.IsPull() { + // ignore update to refs/pull/xxx/head, so we don't need to output any information + os.Exit(1) + } return nil } |