hook.go RawHistoryFolder
1// SPDX-License-Identifier: AGPL-3.0-or-later
2
3package app
4
5import (
6 "os"
7
8 "github.com/spf13/cobra"
9
10 "bnema.dev/ermite/internal/adapters/githttp"
11)
12
13// newHookCmd is the hidden command that git's receive hooks run (through the
14// scripts in run/hooks): it forwards the pushed ref updates to the server.
15func newHookCmd() *cobra.Command {
16 hook := &cobra.Command{
17 Use: "hook",
18 Short: "Run a Git receive hook (called by git, not by users)",
19 Hidden: true,
20 Args: cobra.NoArgs,
21 }
22 for _, name := range []string{githttp.HookPreReceive, githttp.HookPostReceive} {
23 hook.AddCommand(&cobra.Command{
24 Use: name,
25 Short: "Report the pushed ref updates to the server",
26 Hidden: true,
27 Args: cobra.NoArgs,
28 // A refusal is the exit status; its message is already on stderr.
29 SilenceErrors: true,
30 SilenceUsage: true,
31 RunE: func(cmd *cobra.Command, _ []string) error {
32 return githttp.RunHook(cmd.Context(), name, cmd.InOrStdin(), cmd.ErrOrStderr(),
33 os.Getenv(githttp.EnvHookSocket), os.Getenv(githttp.EnvHookToken))
34 },
35 })
36 }
37 return hook
38}