diff options
author | FuXiaoHei <fuxiaohei@hexiaz.com> | 2014-03-26 21:49:09 +0800 |
---|---|---|
committer | FuXiaoHei <fuxiaohei@hexiaz.com> | 2014-03-26 21:49:09 +0800 |
commit | 8c2f751bbb22ebf06c7f7f9621614b6e46130210 (patch) | |
tree | 5b90a56d40ef41431aa68bfc4c3733d9d5745b55 /models/repo.go | |
parent | 08405a4fea1d2e5c73a73dafd866e0c00c7749c2 (diff) | |
parent | 32e05ae2120e864d6e1bd85fb01ef87e23c3ae89 (diff) |
Merge branch 'master' of https://github.com/gogits/gogs
Diffstat (limited to 'models/repo.go')
-rw-r--r-- | models/repo.go | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/models/repo.go b/models/repo.go index 477f9472..0ef049cc 100644 --- a/models/repo.go +++ b/models/repo.go @@ -235,6 +235,18 @@ func initRepoCommit(tmpPath string, sig *git.Signature) (err error) { return nil } +func createHookUpdate(hookPath, content string) error { + pu, err := os.OpenFile(hookPath, os.O_CREATE|os.O_WRONLY, 0777) + if err != nil { + return err + } + defer pu.Close() + if _, err = pu.WriteString(content); err != nil { + return err + } + return nil +} + // InitRepository initializes README and .gitignore if needed. func initRepository(f string, user *User, repo *Repository, initReadme bool, repoLang, license string) error { repoPath := RepoPath(user.Name, repo.Name) @@ -245,13 +257,9 @@ func initRepository(f string, user *User, repo *Repository, initReadme bool, rep } // hook/post-update - pu, err := os.OpenFile(filepath.Join(repoPath, "hooks", "update"), os.O_CREATE|os.O_WRONLY, 0777) - if err != nil { - return err - } - defer pu.Close() - // TODO: Windows .bat - if _, err = pu.WriteString(fmt.Sprintf("#!/usr/bin/env bash\n%s update $1 $2 $3\n", appPath)); err != nil { + if err := createHookUpdate(filepath.Join(repoPath, "hooks", "update"), + fmt.Sprintf("#!/usr/bin/env bash\n%s update $1 $2 $3\n", + strings.Replace(appPath, "\\", "/", -1))); err != nil { return err } |