aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2024-09-02 15:38:27 +0800
committerGitHub <noreply@github.com>2024-09-02 07:38:27 +0000
commitac344497473f92c9a04f7863374dbb14e3c09d4e (patch)
tree95594d93a5654521ac4acc49b7477b1464fa7e92 /cmd
parent052a8fe6cc6a49c4ac7f19463ce3e543fefe8274 (diff)
downloadgitea-ac344497473f92c9a04f7863374dbb14e3c09d4e.tar.gz
gitea-ac344497473f92c9a04f7863374dbb14e3c09d4e.zip
Prevent update pull refs manually and will not affect other refs update (#31931)
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.
Diffstat (limited to 'cmd')
-rw-r--r--cmd/hook.go14
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
}