fix(templater): add baseDir to gitHead cmd so that directory is overwritten
This makes it so that when gitHead is called in a template the git hash that is returned is the hash of the folder containing the template, not the hash of the folder where kontemplate is called.
This commit is contained in:
parent
ac445d5235
commit
3ea3bed7ac
1 changed files with 8 additions and 8 deletions
|
@ -103,7 +103,7 @@ func processFiles(c *context.Context, rs *context.ResourceSet, rp string, files
|
||||||
}
|
}
|
||||||
|
|
||||||
func templateFile(c *context.Context, rs *context.ResourceSet, filename string) (string, error) {
|
func templateFile(c *context.Context, rs *context.ResourceSet, filename string) (string, error) {
|
||||||
tpl, err := template.New(path.Base(filename)).Funcs(templateFuncs(rs)).Option(failOnMissingKeys).ParseFiles(filename)
|
tpl, err := template.New(path.Base(filename)).Funcs(templateFuncs(c, rs)).Option(failOnMissingKeys).ParseFiles(filename)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("Template %s not found: %v", filename, err)
|
return "", fmt.Errorf("Template %s not found: %v", filename, err)
|
||||||
|
@ -163,7 +163,7 @@ func matchesResourceSet(s *[]string, rs *context.ResourceSet) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func templateFuncs(rs *context.ResourceSet) template.FuncMap {
|
func templateFuncs(c *context.Context, rs *context.ResourceSet) template.FuncMap {
|
||||||
m := sprig.TxtFuncMap()
|
m := sprig.TxtFuncMap()
|
||||||
m["json"] = func(data interface{}) string {
|
m["json"] = func(data interface{}) string {
|
||||||
b, _ := json.Marshal(data)
|
b, _ := json.Marshal(data)
|
||||||
|
@ -171,7 +171,7 @@ func templateFuncs(rs *context.ResourceSet) template.FuncMap {
|
||||||
}
|
}
|
||||||
m["passLookup"] = GetFromPass
|
m["passLookup"] = GetFromPass
|
||||||
m["gitHEAD"] = func() (string, error) {
|
m["gitHEAD"] = func() (string, error) {
|
||||||
out, err := exec.Command("git", "rev-parse", "HEAD").Output()
|
out, err := exec.Command("git", "-C", c.BaseDir, "rev-parse", "HEAD").Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue