Skip to content

Commit 53bcb73

Browse files
committed
gogs/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.
1 parent db93fa5 commit 53bcb73

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

git.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"time"
1111
)
1212

13-
const _VERSION = "0.3.2"
13+
const _VERSION = "0.3.3"
1414

1515
func Version() string {
1616
return _VERSION

hook.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"os"
1111
"path"
1212
"strings"
13+
14+
"github.com/Unknwon/com"
1315
)
1416

1517
// hookNames is a list of Git hooks' name that are supported.
@@ -119,9 +121,16 @@ const (
119121
)
120122

121123
// SetUpdateHook writes given content to update hook of the reposiotry.
122-
func SetUpdateHook(repoPath, content string) error {
124+
func SetUpdateHook(repoPath, content string) (err error) {
123125
log("Setting update hook: %s", repoPath)
124126
hookPath := path.Join(repoPath, HOOK_PATH_UPDATE)
125-
os.MkdirAll(path.Dir(hookPath), os.ModePerm)
127+
if com.IsExist(hookPath) {
128+
err = os.Remove(hookPath)
129+
} else {
130+
err = os.MkdirAll(path.Dir(hookPath), os.ModePerm)
131+
}
132+
if err != nil {
133+
return err
134+
}
126135
return ioutil.WriteFile(hookPath, []byte(content), 0777)
127136
}

0 commit comments

Comments
 (0)