diff options
author | Unknwon <u@gogs.io> | 2017-02-14 18:06:54 -0500 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2017-02-14 18:06:54 -0500 |
commit | 0386b5ae540b2a86d201db8135684075a26bc5fe (patch) | |
tree | 06d64295f1c80c06e938d584912577e66e5bf173 /cmd | |
parent | a0253cab62d02ac0ce5c55a6b1d08a76f281bf44 (diff) |
cmd/hook: check existence before call custom hook
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/hook.go | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/cmd/hook.go b/cmd/hook.go index a917554d..1a494373 100644 --- a/cmd/hook.go +++ b/cmd/hook.go @@ -11,6 +11,7 @@ import ( "os/exec" "path/filepath" + "github.com/Unknwon/com" "github.com/urfave/cli" "github.com/gogits/gogs/models" @@ -65,6 +66,10 @@ func runHookPreReceive(c *cli.Context) error { } customHooksPath := os.Getenv(_ENV_REPO_CUSTOM_HOOKS_PATH) + if !com.IsFile(customHooksPath) { + return nil + } + hookCmd := exec.Command(filepath.Join(customHooksPath, "pre-receive")) hookCmd.Stdout = os.Stdout hookCmd.Stdin = buf @@ -99,6 +104,10 @@ func runHookUpdate(c *cli.Context) error { } customHooksPath := os.Getenv(_ENV_REPO_CUSTOM_HOOKS_PATH) + if !com.IsFile(customHooksPath) { + return nil + } + hookCmd := exec.Command(filepath.Join(customHooksPath, "update"), args...) hookCmd.Stdout = os.Stdout hookCmd.Stdin = os.Stdin @@ -116,6 +125,10 @@ func runHookPostReceive(c *cli.Context) error { setup(c, "hooks/post-receive.log") customHooksPath := os.Getenv(_ENV_REPO_CUSTOM_HOOKS_PATH) + if !com.IsFile(customHooksPath) { + return nil + } + hookCmd := exec.Command(filepath.Join(customHooksPath, "post-receive")) hookCmd.Stdout = os.Stdout hookCmd.Stdin = os.Stdin |