Skip to content

Commit

Permalink
fix: Handle .chezmoidata files in subdirectories when template has al…
Browse files Browse the repository at this point in the history
…ready been executed
  • Loading branch information
twpayne committed Sep 3, 2023
1 parent 9d4cfc0 commit 40b711d
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 0 deletions.
3 changes: 3 additions & 0 deletions internal/chezmoi/sourcestate.go
Original file line number Diff line number Diff line change
Expand Up @@ -1431,6 +1431,9 @@ func (s *SourceState) addTemplateData(sourceAbsPath AbsPath) error {
}
s.Lock()
RecursiveMerge(s.userTemplateData, templateData)
// Clear the cached template data, as the change to the user template data
// means that the cached value is now invalid.
s.templateData = nil
s.Unlock()
return nil
}
Expand Down
16 changes: 16 additions & 0 deletions internal/cmd/applycmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,19 @@ func TestApplyCmd(t *testing.T) {
})
}
}

func TestIssue3206(t *testing.T) {
chezmoitest.WithTestFS(t, map[string]any{
"/home/user": map[string]any{
".local/share/chezmoi": map[string]any{
".chezmoiignore": "",
"dot_config/private_expanso/match": map[string]any{
".chezmoidata.yaml": "key: value\n",
"greek.yml.tmpl": "{{ .key }}",
},
},
},
}, func(fileSystem vfs.FS) {
assert.NoError(t, newTestConfig(t, fileSystem).execute([]string{"apply"}))
})
}
96 changes: 96 additions & 0 deletions internal/cmd/testdata/scripts/issue3206.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# test that chezmoi apply sees .chezmoidata files in a subdirectory when a .chezmoiignore file is present
exec chezmoi apply --debug
cmp $HOME/.config/expanso/match/greek.yml golden/greek.yml

-- golden/greek.yml --
# `propagate_case` allows e.g.:
# alpha^ => α
# ALPHA^ => Α [or Alpha^ since it's just 1 char]

matches:
- trigger: "alpha^"
replace: "α"
propagate_case: true
- trigger: "beta^"
replace: "β"
propagate_case: true
- trigger: "chi^"
replace: "χ"
propagate_case: true
- trigger: "delta^"
replace: "δ"
propagate_case: true
- trigger: "epsilon^"
replace: "ε"
propagate_case: true
- trigger: "eta^"
replace: "η"
propagate_case: true
- trigger: "gamma^"
replace: "γ"
propagate_case: true
- trigger: "iota^"
replace: "ι"
propagate_case: true
- trigger: "kappa^"
replace: "κ"
propagate_case: true
- trigger: "lambda^"
replace: "λ"
propagate_case: true
- trigger: "mu^"
replace: "μ"
propagate_case: true
- trigger: "nu^"
replace: "ν"
propagate_case: true
- trigger: "omega^"
replace: "ω"
propagate_case: true
- trigger: "omicron^"
replace: "ο"
propagate_case: true
- trigger: "phi^"
replace: "φ"
propagate_case: true
- trigger: "pi^"
replace: "π"
propagate_case: true
- trigger: "psi^"
replace: "ψ"
propagate_case: true
- trigger: "rho^"
replace: "ρ"
propagate_case: true
- trigger: "sigma^"
replace: "σ"
propagate_case: true
- trigger: "tau^"
replace: "τ"
propagate_case: true
- trigger: "theta^"
replace: "θ"
propagate_case: true
- trigger: "upsilon^"
replace: "υ"
propagate_case: true
- trigger: "xi^"
replace: "ξ"
propagate_case: true
- trigger: "zeta^"
replace: "ζ"
propagate_case: true
-- home/user/.local/share/chezmoi/.chezmoiignore --
-- home/user/.local/share/chezmoi/dot_config/private_expanso/match/.chezmoidata.yaml --
greek_alphabet: {alpha: α, beta: β, chi: χ, delta: δ, epsilon: ε, eta: η, gamma: γ, iota: ι, kappa: κ, lambda: λ, mu: μ, nu: ν, omega: ω, omicron: ο, phi: φ, pi: π, psi: ψ, rho: ρ, sigma: σ, tau: τ, theta: θ, upsilon: υ, xi: ξ, zeta: ζ}
-- home/user/.local/share/chezmoi/dot_config/private_expanso/match/greek.yml.tmpl --
# `propagate_case` allows e.g.:
# alpha^ => α
# ALPHA^ => Α [or Alpha^ since it's just 1 char]

matches:
{{- range $trigger, $replace := .greek_alphabet }}
- trigger: "{{ $trigger }}^"
replace: "{{ $replace }}"
propagate_case: true
{{- end }}

0 comments on commit 40b711d

Please sign in to comment.