aboutsummaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
Diffstat (limited to 'models')
-rw-r--r--models/migrations/migrations.go2
-rw-r--r--models/migrations/v36.go15
-rw-r--r--models/models.go5
-rw-r--r--models/repo.go10
4 files changed, 26 insertions, 6 deletions
diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go
index ae15c9f479..437b63f604 100644
--- a/models/migrations/migrations.go
+++ b/models/migrations/migrations.go
@@ -120,6 +120,8 @@ var migrations = []Migration{
NewMigration("give all units to owner teams", giveAllUnitsToOwnerTeams),
// v35 -> v36
NewMigration("adds comment to an action", addCommentIDToAction),
+ // v36 -> v37
+ NewMigration("regenerate git hooks", regenerateGitHooks36),
}
// Migrate database to current version
diff --git a/models/migrations/v36.go b/models/migrations/v36.go
new file mode 100644
index 0000000000..06f76a26d6
--- /dev/null
+++ b/models/migrations/v36.go
@@ -0,0 +1,15 @@
+// Copyright 2017 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package migrations
+
+import (
+ "code.gitea.io/gitea/models"
+
+ "github.com/go-xorm/xorm"
+)
+
+func regenerateGitHooks36(x *xorm.Engine) (err error) {
+ return models.SyncRepositoryHooks()
+}
diff --git a/models/models.go b/models/models.go
index 6a8fbfe624..1688a63649 100644
--- a/models/models.go
+++ b/models/models.go
@@ -24,7 +24,6 @@ import (
// Needed for the MSSSQL driver
_ "github.com/denisenkom/go-mssqldb"
- "code.gitea.io/gitea/models/migrations"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
)
@@ -259,7 +258,7 @@ func SetEngine() (err error) {
}
// NewEngine initializes a new xorm.Engine
-func NewEngine() (err error) {
+func NewEngine(migrateFunc func(*xorm.Engine) error) (err error) {
if err = SetEngine(); err != nil {
return err
}
@@ -268,7 +267,7 @@ func NewEngine() (err error) {
return err
}
- if err = migrations.Migrate(x); err != nil {
+ if err = migrateFunc(x); err != nil {
return fmt.Errorf("migrate: %v", err)
}
diff --git a/models/repo.go b/models/repo.go
index 8d97138420..cb6d6d5c3c 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -948,8 +948,12 @@ func cleanUpMigrateGitConfig(configPath string) error {
// createDelegateHooks creates all the hooks scripts for the repo
func createDelegateHooks(repoPath string) (err error) {
var (
- hookNames = []string{"pre-receive", "update", "post-receive"}
- hookTpl = fmt.Sprintf("#!/usr/bin/env %s\ndata=$(cat)\nexitcodes=\"\"\nhookname=$(basename $0)\nGIT_DIR=${GIT_DIR:-$(dirname $0)}\n\nfor hook in ${GIT_DIR}/hooks/${hookname}.d/*; do\ntest -x \"${hook}\" || continue\necho \"${data}\" | \"${hook}\"\nexitcodes=\"${exitcodes} $?\"\ndone\n\nfor i in ${exitcodes}; do\n[ ${i} -eq 0 ] || exit ${i}\ndone\n", setting.ScriptType)
+ hookNames = []string{"pre-receive", "update", "post-receive"}
+ hookTpls = []string{
+ fmt.Sprintf("#!/usr/bin/env %s\ndata=$(cat)\nexitcodes=\"\"\nhookname=$(basename $0)\nGIT_DIR=${GIT_DIR:-$(dirname $0)}\n\nfor hook in ${GIT_DIR}/hooks/${hookname}.d/*; do\ntest -x \"${hook}\" || continue\necho \"${data}\" | \"${hook}\"\nexitcodes=\"${exitcodes} $?\"\ndone\n\nfor i in ${exitcodes}; do\n[ ${i} -eq 0 ] || exit ${i}\ndone\n", setting.ScriptType),
+ fmt.Sprintf("#!/usr/bin/env %s\nexitcodes=\"\"\nhookname=$(basename $0)\nGIT_DIR=${GIT_DIR:-$(dirname $0)}\n\nfor hook in ${GIT_DIR}/hooks/${hookname}.d/*; do\ntest -x \"${hook}\" || continue\n\"${hook}\" $1 $2 $3\nexitcodes=\"${exitcodes} $?\"\ndone\n\nfor i in ${exitcodes}; do\n[ ${i} -eq 0 ] || exit ${i}\ndone\n", setting.ScriptType),
+ fmt.Sprintf("#!/usr/bin/env %s\ndata=$(cat)\nexitcodes=\"\"\nhookname=$(basename $0)\nGIT_DIR=${GIT_DIR:-$(dirname $0)}\n\nfor hook in ${GIT_DIR}/hooks/${hookname}.d/*; do\ntest -x \"${hook}\" || continue\necho \"${data}\" | \"${hook}\"\nexitcodes=\"${exitcodes} $?\"\ndone\n\nfor i in ${exitcodes}; do\n[ ${i} -eq 0 ] || exit ${i}\ndone\n", setting.ScriptType),
+ }
giteaHookTpls = []string{
fmt.Sprintf("#!/usr/bin/env %s\n\"%s\" hook --config='%s' pre-receive\n", setting.ScriptType, setting.AppPath, setting.CustomConf),
fmt.Sprintf("#!/usr/bin/env %s\n\"%s\" hook --config='%s' update $1 $2 $3\n", setting.ScriptType, setting.AppPath, setting.CustomConf),
@@ -968,7 +972,7 @@ func createDelegateHooks(repoPath string) (err error) {
}
// WARNING: This will override all old server-side hooks
- if err = ioutil.WriteFile(oldHookPath, []byte(hookTpl), 0777); err != nil {
+ if err = ioutil.WriteFile(oldHookPath, []byte(hookTpls[i]), 0777); err != nil {
return fmt.Errorf("write old hook file '%s': %v", oldHookPath, err)
}