Skip to content

Commit fe65084

Browse files
arschlesAaron Schlesinger
authored andcommitted
ref(git.go): render the template on startup
1 parent 8ee3bc5 commit fe65084

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

pkg/git/git.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ import (
2020
"golang.org/x/crypto/ssh"
2121
)
2222

23-
// prereceiveHookTpl is the template for a pre-receive hook. The following template variables are passed into it:
23+
// prereceiveHookTplStr is the template for a pre-receive hook. The following template variables are passed into it:
2424
//
2525
// .GitHome: the path to Git's home directory.
26-
const prereceiveHookTpl = `#!/bin/bash
26+
const preReceiveHookTplStr = `#!/bin/bash
2727
strip_remote_prefix() {
2828
stdbuf -i0 -o0 -e0 sed "s/^/"$'\e[1G'"/"
2929
}
@@ -57,6 +57,8 @@ do
5757
done
5858
`
5959

60+
var preReceiveHookTpl = template.Must(template.New("hooks").Parse(preReceiveHookTplStr))
61+
6062
// Receive receives a Git repo.
6163
// This will only work for git-receive-pack.
6264
//
@@ -211,11 +213,8 @@ func createRepo(c cookoo.Context, repoPath, gitHome string) (bool, error) {
211213
func prereceiveHook(vars map[string]string) ([]byte, error) {
212214
var out bytes.Buffer
213215
// We parse the template anew each receive in case it has changed.
214-
t, err := template.New("hooks").Parse(prereceiveHookTpl)
215-
if err != nil {
216-
return []byte{}, err
216+
if err := preReceiveHookTpl.Execute(&out, vars); err != nil {
217+
return nil, err
217218
}
218-
219-
err = t.Execute(&out, vars)
220-
return out.Bytes(), err
219+
return out.Bytes(), nil
221220
}

0 commit comments

Comments
 (0)