From 9c4604e40c087eed74257ac93c9b991dfbbbcff2 Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Thu, 26 Dec 2019 11:57:42 +0000 Subject: [PATCH 1/2] Remove the unused and inefficent update hook --- cmd/hook.go | 13 +------------ models/repo.go | 11 ++++++++++- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/cmd/hook.go b/cmd/hook.go index 03fa15aabc072..ebd230999a531 100644 --- a/cmd/hook.go +++ b/cmd/hook.go @@ -181,18 +181,7 @@ Gitea or set your environment appropriately.`, "") } func runHookUpdate(c *cli.Context) error { - if len(os.Getenv("SSH_ORIGINAL_COMMAND")) == 0 { - if setting.OnlyAllowPushIfGiteaEnvironmentSet { - fail(`Rejecting changes as Gitea environment not set. -If you are pushing over SSH you must push with a key managed by -Gitea or set your environment appropriately.`, "") - } else { - return nil - } - } - - setup("hooks/update.log", false) - + // Update is empty and is kept only for backwards compatibility return nil } diff --git a/models/repo.go b/models/repo.go index 02cb3b912866f..7cc759a400e49 100644 --- a/models/repo.go +++ b/models/repo.go @@ -976,7 +976,7 @@ func createDelegateHooks(repoPath string) (err error) { } giteaHookTpls = []string{ fmt.Sprintf("#!/usr/bin/env %s\n\"%s\" hook --config='%s' pre-receive\n", setting.ScriptType, setting.AppPath, setting.CustomConf), - fmt.Sprintf("#!/usr/bin/env %s\n\"%s\" hook --config='%s' update $1 $2 $3\n", setting.ScriptType, setting.AppPath, setting.CustomConf), + "", fmt.Sprintf("#!/usr/bin/env %s\n\"%s\" hook --config='%s' post-receive\n", setting.ScriptType, setting.AppPath, setting.CustomConf), } ) @@ -996,11 +996,20 @@ func createDelegateHooks(repoPath string) (err error) { return fmt.Errorf("write old hook file '%s': %v", oldHookPath, err) } + if len(giteaHookTpls[i]) == 0 { + continue + } if err = ioutil.WriteFile(newHookPath, []byte(giteaHookTpls[i]), 0777); err != nil { return fmt.Errorf("write new hook file '%s': %v", newHookPath, err) } } + // Remove the old unused update.d/gitea hook as it is empty + newHookPath := filepath.Join(hookDir, "update.d", "gitea") + if err := os.Remove(newHookPath); err != nil && !os.IsNotExist(err) { + return fmt.Errorf("remove unused update hook file '%s': %v", newHookPath, err) + } + return nil } From 5715478d5a07b14220bb7c0abf365a6fca210874 Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Fri, 27 Dec 2019 11:52:52 +0000 Subject: [PATCH 2/2] As per @lunny - keep the old update.d/gitea hook around for future use --- models/repo.go | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/models/repo.go b/models/repo.go index 7cc759a400e49..02cb3b912866f 100644 --- a/models/repo.go +++ b/models/repo.go @@ -976,7 +976,7 @@ func createDelegateHooks(repoPath string) (err error) { } giteaHookTpls = []string{ fmt.Sprintf("#!/usr/bin/env %s\n\"%s\" hook --config='%s' pre-receive\n", setting.ScriptType, setting.AppPath, setting.CustomConf), - "", + fmt.Sprintf("#!/usr/bin/env %s\n\"%s\" hook --config='%s' update $1 $2 $3\n", setting.ScriptType, setting.AppPath, setting.CustomConf), fmt.Sprintf("#!/usr/bin/env %s\n\"%s\" hook --config='%s' post-receive\n", setting.ScriptType, setting.AppPath, setting.CustomConf), } ) @@ -996,20 +996,11 @@ func createDelegateHooks(repoPath string) (err error) { return fmt.Errorf("write old hook file '%s': %v", oldHookPath, err) } - if len(giteaHookTpls[i]) == 0 { - continue - } if err = ioutil.WriteFile(newHookPath, []byte(giteaHookTpls[i]), 0777); err != nil { return fmt.Errorf("write new hook file '%s': %v", newHookPath, err) } } - // Remove the old unused update.d/gitea hook as it is empty - newHookPath := filepath.Join(hookDir, "update.d", "gitea") - if err := os.Remove(newHookPath); err != nil && !os.IsNotExist(err) { - return fmt.Errorf("remove unused update hook file '%s': %v", newHookPath, err) - } - return nil }