From 53bcb7352ff838610c537c9b589ca79bca92c661 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Fri, 22 Jul 2016 21:29:50 +0800 Subject: [PATCH] gogits/gogs#3302 remove hook script and recreate with proper permission If permission of hook script somehow changed, the rewrite operation does not fix the permission to what is expteced. --- git.go | 2 +- hook.go | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/git.go b/git.go index ef3d5ad..4f67e2a 100644 --- a/git.go +++ b/git.go @@ -10,7 +10,7 @@ import ( "time" ) -const _VERSION = "0.3.2" +const _VERSION = "0.3.3" func Version() string { return _VERSION diff --git a/hook.go b/hook.go index 90f2aa7..379743a 100644 --- a/hook.go +++ b/hook.go @@ -10,6 +10,8 @@ import ( "os" "path" "strings" + + "github.com/Unknwon/com" ) // hookNames is a list of Git hooks' name that are supported. @@ -119,9 +121,16 @@ const ( ) // SetUpdateHook writes given content to update hook of the reposiotry. -func SetUpdateHook(repoPath, content string) error { +func SetUpdateHook(repoPath, content string) (err error) { log("Setting update hook: %s", repoPath) hookPath := path.Join(repoPath, HOOK_PATH_UPDATE) - os.MkdirAll(path.Dir(hookPath), os.ModePerm) + if com.IsExist(hookPath) { + err = os.Remove(hookPath) + } else { + err = os.MkdirAll(path.Dir(hookPath), os.ModePerm) + } + if err != nil { + return err + } return ioutil.WriteFile(hookPath, []byte(content), 0777) }