Skip to content
This repository has been archived by the owner on Feb 26, 2023. It is now read-only.

Don't create a blank template when parsing templates #22

Merged
merged 1 commit into from
Sep 5, 2017

Conversation

SnoFox
Copy link
Contributor

@SnoFox SnoFox commented Sep 5, 2017

I ran across a bug where using a template in a subdirectory would fail because it was reading an empty template. Here's the task I was using:

[tasks.setup_git]
templates = [
  [".gitconfig.d/user.inc", "git/user.inc.tmpl"]
]

Using template.New() created a new, empty-content template with the name "git/user.inc.tmpl".
Afterwards, using .ParseFiles() creates another template with the name "user.inc.tmpl" with my template.
Finally, when .Execute is called, it picked the first, empty template "git/user.inc.tmpl".

This works fine when you don't place templates in subdirectories, as the name you generate matches the name .ParseFiles() does (and therefore gets clobbered with real content).

Using template.ParseTemplate() directly makes the first (and default) template for .Execute the file the user provides.

This created a template with two entries within it; using
template.Execute would execute an empty template when you attempted to
use templates within a sub-directory
@FooSoft FooSoft merged commit a17a114 into FooSoft:master Sep 5, 2017
@FooSoft
Copy link
Owner

FooSoft commented Sep 5, 2017

Looks good, thank you for the contribution.

@aphistic
Copy link

I'm actually running into this with the latest release tarballs as well. Any chance those could be updated so I can pull them into my repo?

Thanks for your project, btw. It fits my use-case perfectly. :)

@FooSoft
Copy link
Owner

FooSoft commented Sep 11, 2017

@aphistic binaries updated! 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants