Skip to content

Commit 6f2ee28

Browse files
arschlesAaron Schlesinger
authored andcommitted
ref(git.go): simplify the template rendering logic
1 parent fe65084 commit 6f2ee28

1 file changed

Lines changed: 5 additions & 13 deletions

File tree

pkg/git/git.go

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -196,25 +196,17 @@ func createRepo(c cookoo.Context, repoPath, gitHome string) (bool, error) {
196196
return false, err
197197
}
198198

199-
hook, err := prereceiveHook(map[string]string{"GitHome": gitHome})
200-
if err != nil {
199+
// parse the template anew each receive for each new git home
200+
var hookByteBuf bytes.Buffer
201+
if err := preReceiveHookTpl.Execute(&hookByteBuf, map[string]string{"GitHome": gitHome}); err != nil {
201202
return true, err
202203
}
203-
ioutil.WriteFile(filepath.Join(repoPath, "hooks", "pre-receive"), hook, 0755)
204+
205+
ioutil.WriteFile(filepath.Join(repoPath, "hooks", "pre-receive"), hookByteBuf.Bytes(), 0755)
204206

205207
return true, nil
206208
} else if err == nil {
207209
return false, errors.New("Expected directory, found file.")
208210
}
209211
return false, err
210212
}
211-
212-
//prereceiveHook templates a pre-receive hook for Git.
213-
func prereceiveHook(vars map[string]string) ([]byte, error) {
214-
var out bytes.Buffer
215-
// We parse the template anew each receive in case it has changed.
216-
if err := preReceiveHookTpl.Execute(&out, vars); err != nil {
217-
return nil, err
218-
}
219-
return out.Bytes(), nil
220-
}

0 commit comments

Comments
 (0)