|
|
|
|
@ -7,11 +7,9 @@ package git
|
|
|
|
|
import (
|
|
|
|
|
"errors"
|
|
|
|
|
"os"
|
|
|
|
|
"path"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/modules/log"
|
|
|
|
|
"code.gitea.io/gitea/modules/util"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
@ -51,7 +49,7 @@ func GetHook(repoPath, name string) (*Hook, error) {
|
|
|
|
|
}
|
|
|
|
|
h := &Hook{
|
|
|
|
|
name: name,
|
|
|
|
|
path: path.Join(repoPath, "hooks", name+".d", name),
|
|
|
|
|
path: filepath.Join(repoPath, "hooks", name+".d", name),
|
|
|
|
|
}
|
|
|
|
|
samplePath := filepath.Join(repoPath, "hooks", name+".sample")
|
|
|
|
|
if isFile(h.path) {
|
|
|
|
|
@ -103,7 +101,7 @@ func (h *Hook) Update() error {
|
|
|
|
|
|
|
|
|
|
// ListHooks returns a list of Git hooks of given repository.
|
|
|
|
|
func ListHooks(repoPath string) (_ []*Hook, err error) {
|
|
|
|
|
if !isDir(path.Join(repoPath, "hooks")) {
|
|
|
|
|
if !isDir(filepath.Join(repoPath, "hooks")) {
|
|
|
|
|
return nil, errors.New("hooks path does not exist")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -116,28 +114,3 @@ func ListHooks(repoPath string) (_ []*Hook, err error) {
|
|
|
|
|
}
|
|
|
|
|
return hooks, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
// HookPathUpdate hook update path
|
|
|
|
|
HookPathUpdate = "hooks/update"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// SetUpdateHook writes given content to update hook of the repository.
|
|
|
|
|
func SetUpdateHook(repoPath, content string) (err error) {
|
|
|
|
|
log.Debug("Setting update hook: %s", repoPath)
|
|
|
|
|
hookPath := path.Join(repoPath, HookPathUpdate)
|
|
|
|
|
isExist, err := util.IsExist(hookPath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Debug("Unable to check if %s exists. Error: %v", hookPath, err)
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if isExist {
|
|
|
|
|
err = util.Remove(hookPath)
|
|
|
|
|
} else {
|
|
|
|
|
err = os.MkdirAll(path.Dir(hookPath), os.ModePerm)
|
|
|
|
|
}
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
return os.WriteFile(hookPath, []byte(content), 0o777)
|
|
|
|
|
}
|
|
|
|
|
|