Skip to content

Commit

Permalink
Remove the unused and inefficent update hook
Browse files Browse the repository at this point in the history
  • Loading branch information
zeripath committed Dec 26, 2019
1 parent 7bfb83e commit 9c4604e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
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

0 comments on commit 9c4604e

Please sign in to comment.