| 152 | } |
| 153 | |
| 154 | func runHookUpdate(c *cli.Context) error { |
| 155 | if os.Getenv("SSH_ORIGINAL_COMMAND") == "" { |
| 156 | return nil |
| 157 | } |
| 158 | setup(c, "update.log", false) |
| 159 | |
| 160 | args := c.Args() |
| 161 | if len(args) != 3 { |
| 162 | fail("Arguments received are not equal to three", "Arguments received are not equal to three") |
| 163 | } else if args[0] == "" { |
| 164 | fail("First argument 'refName' is empty", "First argument 'refName' is empty") |
| 165 | } |
| 166 | |
| 167 | customHooksPath := filepath.Join(os.Getenv(database.EnvRepoCustomHooksPath), "update") |
| 168 | if !com.IsFile(customHooksPath) { |
| 169 | return nil |
| 170 | } |
| 171 | |
| 172 | var hookCmd *exec.Cmd |
| 173 | if conf.IsWindowsRuntime() { |
| 174 | hookCmd = exec.Command("bash.exe", append([]string{"custom_hooks/update"}, args...)...) |
| 175 | } else { |
| 176 | hookCmd = exec.Command(customHooksPath, args...) |
| 177 | } |
| 178 | hookCmd.Dir = database.RepoPath(os.Getenv(database.EnvRepoOwnerName), os.Getenv(database.EnvRepoName)) |
| 179 | hookCmd.Stdout = os.Stdout |
| 180 | hookCmd.Stdin = os.Stdin |
| 181 | hookCmd.Stderr = os.Stderr |
| 182 | if err := hookCmd.Run(); err != nil { |
| 183 | fail("Internal error", "Failed to execute custom pre-receive hook: %v", err) |
| 184 | } |
| 185 | return nil |
| 186 | } |
| 187 | |
| 188 | func runHookPostReceive(c *cli.Context) error { |
| 189 | if os.Getenv("SSH_ORIGINAL_COMMAND") == "" { |