Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary loading of settings in update hook #9496

Merged
merged 4 commits into from
Dec 27, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions cmd/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
11 changes: 10 additions & 1 deletion models/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
)
Expand All @@ -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
}

Expand Down