]> source.dussan.org Git - gitea.git/commitdiff
Fix issue: update hook text busy
authorUnknown <joe2010xtmf@163.com>
Wed, 26 Mar 2014 13:40:02 +0000 (09:40 -0400)
committerUnknown <joe2010xtmf@163.com>
Wed, 26 Mar 2014 13:40:02 +0000 (09:40 -0400)
models/repo.go

index c80d2f2c2c8277b3875c37ca5d56eea6c7279eb5..0ef049cc6e846ce44be70c475af5dd3d7274fa4f 100644 (file)
@@ -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,14 +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",
-               strings.Replace(appPath, "\\", "/", -1))); 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
        }