migration.v15: don't generate hook file if wiki not exist (#1623)

pull/4129/head
Unknwon 2017-02-15 05:45:15 -05:00
parent 4da325a45c
commit a4f9e5031f
No known key found for this signature in database
GPG Key ID: 25B575AE3213B2B3
1 changed files with 8 additions and 5 deletions

View File

@ -64,11 +64,12 @@ func generateAndMigrateGitHooks(x *xorm.Engine) (err error) {
repoBase := filepath.Join(setting.RepoRootPath, strings.ToLower(user.Name), strings.ToLower(repo.Name)) repoBase := filepath.Join(setting.RepoRootPath, strings.ToLower(user.Name), strings.ToLower(repo.Name))
repoPath := repoBase + ".git" repoPath := repoBase + ".git"
wikiPath := repoBase + ".wiki.git"
log.Trace("[%04d]: %s", idx, repoPath) log.Trace("[%04d]: %s", idx, repoPath)
hookDir := filepath.Join(repoPath, "hooks") hookDir := filepath.Join(repoPath, "hooks")
customHookDir := filepath.Join(repoPath, "custom_hooks") customHookDir := filepath.Join(repoPath, "custom_hooks")
wikiHookDir := filepath.Join(repoBase+".wiki.git", "hooks") wikiHookDir := filepath.Join(wikiPath, "hooks")
for i, hookName := range hookNames { for i, hookName := range hookNames {
oldHookPath := filepath.Join(hookDir, hookName) oldHookPath := filepath.Join(hookDir, hookName)
@ -88,10 +89,12 @@ func generateAndMigrateGitHooks(x *xorm.Engine) (err error) {
return fmt.Errorf("write hook file '%s': %v", oldHookPath, err) return fmt.Errorf("write hook file '%s': %v", oldHookPath, err)
} }
os.MkdirAll(wikiHookDir, os.ModePerm) if com.IsDir(wikiPath) {
wikiHookPath := filepath.Join(wikiHookDir, hookName) os.MkdirAll(wikiHookDir, os.ModePerm)
if err = ioutil.WriteFile(wikiHookPath, []byte(hookTpls[i]), os.ModePerm); err != nil { wikiHookPath := filepath.Join(wikiHookDir, hookName)
return fmt.Errorf("write wiki hook file '%s': %v", wikiHookPath, err) if err = ioutil.WriteFile(wikiHookPath, []byte(hookTpls[i]), os.ModePerm); err != nil {
return fmt.Errorf("write wiki hook file '%s': %v", wikiHookPath, err)
}
} }
} }
return nil return nil