|
7 | 7 | "errors" |
8 | 8 | "fmt" |
9 | 9 | "io" |
10 | | - "io/ioutil" |
11 | 10 | "os" |
12 | 11 | "os/exec" |
13 | 12 | "path/filepath" |
@@ -158,16 +157,20 @@ func createRepo(repoPath string) (bool, error) { |
158 | 157 |
|
159 | 158 | // createPreReceiveHook renders preReceiveHookTpl to repoPath/hooks/pre-receive |
160 | 159 | func createPreReceiveHook(gitHome, repoPath string) error { |
161 | | - // parse & generate the template anew each receive for each new git home |
162 | | - var hookByteBuf bytes.Buffer |
163 | | - if err := preReceiveHookTpl.Execute(&hookByteBuf, map[string]string{"GitHome": gitHome}); err != nil { |
164 | | - return err |
| 160 | + writePath := filepath.Join(repoPath, "hooks", "pre-receive") |
| 161 | + fd, err := os.Create(writePath) |
| 162 | + if err != nil { |
| 163 | + return fmt.Errorf("Cannot create pre-receive hook file at %s (%s)", writePath, err) |
165 | 164 | } |
| 165 | + defer fd.Close() |
166 | 166 |
|
167 | | - writePath := filepath.Join(repoPath, "hooks", "pre-receive") |
168 | | - log.Info("Writing pre-receive hook to %s", writePath) |
169 | | - if err := ioutil.WriteFile(writePath, hookByteBuf.Bytes(), 0755); err != nil { |
| 167 | + // parse & generate the template anew each receive for each new git home |
| 168 | + if err := preReceiveHookTpl.Execute(fd, map[string]string{"GitHome": gitHome}); err != nil { |
170 | 169 | return fmt.Errorf("Cannot write pre-receive hook to %s (%s)", writePath, err) |
171 | 170 | } |
| 171 | + if err := os.Chmod(writePath, 0755); err != nil { |
| 172 | + return fmt.Errorf("Cannot change pre-receive hook script permissions (%s)", err) |
| 173 | + } |
| 174 | + |
172 | 175 | return nil |
173 | 176 | } |
0 commit comments