Skip to content

Commit a46d04f

Browse files
authored
Merge pull request #404 from twpayne/disable-autotemplate
Disable autotemplate by default
2 parents 1792d38 + d918f7e commit a46d04f

File tree

7 files changed

+43
-14
lines changed

7 files changed

+43
-14
lines changed

cmd/add.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func init() {
3939
persistentFlags.BoolVarP(&config.add.prompt, "prompt", "p", false, "prompt before adding")
4040
persistentFlags.BoolVarP(&config.add.recursive, "recursive", "r", false, "recurse in to subdirectories")
4141
persistentFlags.BoolVarP(&config.add.options.Template, "template", "T", false, "add files as templates")
42+
persistentFlags.BoolVarP(&config.add.options.AutoTemplate, "autotemplate", "a", false, "auto generate the template when adding files as templates")
4243
}
4344

4445
func (c *Config) runAddCmd(fs vfs.FS, args []string) (err error) {

cmd/add_test.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ func TestAddCommand(t *testing.T) {
7272
args: []string{"/home/user/.gitconfig"},
7373
add: addCmdConfig{
7474
options: chezmoi.AddOptions{
75-
Template: true,
75+
Template: true,
76+
AutoTemplate: true,
7677
},
7778
},
7879
root: map[string]interface{}{
@@ -87,6 +88,28 @@ func TestAddCommand(t *testing.T) {
8788
),
8889
},
8990
},
91+
{
92+
// Test for PR #393
93+
// Ensure that auto template generating is disabled by default
94+
name: "add_autotemplate_off_by_default",
95+
args: []string{"/home/user/.gitconfig"},
96+
add: addCmdConfig{
97+
options: chezmoi.AddOptions{
98+
Template: true,
99+
},
100+
},
101+
root: map[string]interface{}{
102+
"/home/user": &vfst.Dir{Perm: 0755},
103+
"/home/user/.chezmoi": &vfst.Dir{Perm: 0700},
104+
"/home/user/.gitconfig": "[user]\n\tname = John Smith\n\temail = john.smith@company.com\n",
105+
},
106+
tests: []vfst.Test{
107+
vfst.TestPath("/home/user/.chezmoi/dot_gitconfig.tmpl",
108+
vfst.TestModeIsRegular,
109+
vfst.TestContentsString("[user]\n\tname = John Smith\n\temail = john.smith@company.com\n"),
110+
),
111+
},
112+
},
90113
{
91114
name: "add_recursive",
92115
args: []string{"/home/user/.config"},

cmd/helps.gen.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ var helps = map[string]help{
3838
"\n" +
3939
"\"-T\", \"--template\"\n" +
4040
"\n" +
41-
"Set the \"template\" attribute on added files and symlinks. In addition, chezmoi\n" +
42-
"attempts to automatically generate the template by replacing any template data\n" +
43-
"values with the equivalent template data keys. Longer subsitutions occur before\n" +
44-
"shorter ones.\n",
41+
"Set the \"template\" attribute on added files and symlinks. In addition, \"if\n" +
42+
"the \"--template-auto-generate\" flag is set, chezmoi attempts to automatically\n" +
43+
"generate the template by replacing any template data values with the equivalent\n" +
44+
"template data keys. Longer subsitutions occur before shorter ones.\n",
4545
example: "" +
4646
" chezmoi add ~/.bashrc\n" +
4747
" chezmoi add ~/.gitconfig --template\n" +

completions/chezmoi-completion.bash

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@ _chezmoi_add()
264264
flags_with_completion=()
265265
flags_completion=()
266266

267+
flags+=("--autotemplate")
268+
flags+=("-a")
267269
flags+=("--empty")
268270
flags+=("-e")
269271
flags+=("--encrypt")

completions/chezmoi.fish

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ complete -c chezmoi -f -n '__fish_chezmoi_no_subcommand' -s n -l dry-run -d 'dr
6868
complete -c chezmoi -f -n '__fish_chezmoi_no_subcommand' -l remove -d 'remove targets'
6969
complete -c chezmoi -f -n '__fish_chezmoi_no_subcommand' -r -s S -l source -d 'source directory'
7070
complete -c chezmoi -f -n '__fish_chezmoi_no_subcommand' -s v -l verbose -d 'verbose'
71+
complete -c chezmoi -f -n '__fish_chezmoi_seen_subcommand_path add' -s a -l autotemplate -d 'auto generate the template when adding files as templates'
7172
complete -c chezmoi -f -n '__fish_chezmoi_seen_subcommand_path add' -s e -l empty -d 'add empty files'
7273
complete -c chezmoi -f -n '__fish_chezmoi_seen_subcommand_path add' -l encrypt -d 'encrypt files'
7374
complete -c chezmoi -f -n '__fish_chezmoi_seen_subcommand_path add' -s x -l exact -d 'add directories exactly'

docs/REFERENCE.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,10 @@ Recursively add all files, directories, and symlinks.
320320

321321
#### `-T`, `--template`
322322

323-
Set the `template` attribute on added files and symlinks. In addition, chezmoi
324-
attempts to automatically generate the template by replacing any template data
325-
values with the equivalent template data keys. Longer subsitutions occur before
323+
Set the `template` attribute on added files and symlinks. In addition, "if the
324+
`--template-auto-generate` flag is set, chezmoi attempts to automatically
325+
generate the template by replacing any template data values with the equivalent
326+
template data keys. Longer subsitutions occur before
326327
shorter ones.
327328

328329
#### `add` examples

lib/chezmoi/targetstate.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@ const (
2626

2727
// An AddOptions contains options for TargetState.Add.
2828
type AddOptions struct {
29-
Empty bool
30-
Encrypt bool
31-
Exact bool
32-
Follow bool
33-
Template bool
29+
Empty bool
30+
Encrypt bool
31+
Exact bool
32+
Follow bool
33+
Template bool
34+
AutoTemplate bool
3435
}
3536

3637
// An ImportTAROptions contains options for TargetState.ImportTAR.
@@ -153,7 +154,7 @@ func (ts *TargetState) Add(fs vfs.FS, addOptions AddOptions, targetPath string,
153154
if err != nil {
154155
return err
155156
}
156-
if addOptions.Template {
157+
if addOptions.Template && addOptions.AutoTemplate {
157158
contents = autoTemplate(contents, ts.Data)
158159
}
159160
if addOptions.Encrypt {

0 commit comments

Comments
 (0)