Skip to content

Commit 8f444ad

Browse files
committed
Fix \#9091: Remove and recreate the hook to set them executable with the umask
1 parent 5748755 commit 8f444ad

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

models/repo.go

+7
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,7 @@ func CreateDelegateHooks(repoPath string) error {
967967

968968
// createDelegateHooks creates all the hooks scripts for the repo
969969
func createDelegateHooks(repoPath string) (err error) {
970+
970971
var (
971972
hookNames = []string{"pre-receive", "update", "post-receive"}
972973
hookTpls = []string{
@@ -992,10 +993,16 @@ func createDelegateHooks(repoPath string) (err error) {
992993
}
993994

994995
// WARNING: This will override all old server-side hooks
996+
if err = os.Remove(oldHookPath); err != nil && !os.IsNotExist(err) {
997+
return fmt.Errorf("unable to pre-remove old hook file '%s' prior to rewriting: %v ", oldHookPath, err)
998+
}
995999
if err = ioutil.WriteFile(oldHookPath, []byte(hookTpls[i]), 0777); err != nil {
9961000
return fmt.Errorf("write old hook file '%s': %v", oldHookPath, err)
9971001
}
9981002

1003+
if err = os.Remove(newHookPath); err != nil && !os.IsNotExist(err) {
1004+
return fmt.Errorf("unable to pre-remove new hook file '%s' prior to rewriting: %v", newHookPath, err)
1005+
}
9991006
if err = ioutil.WriteFile(newHookPath, []byte(giteaHookTpls[i]), 0777); err != nil {
10001007
return fmt.Errorf("write new hook file '%s': %v", newHookPath, err)
10011008
}

0 commit comments

Comments
 (0)