Skip to content

Commit

Permalink
fix: Apply changes to directories recursively when editing directories
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Sep 1, 2022
1 parent 5413626 commit 7a525b7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
3 changes: 2 additions & 1 deletion pkg/cmd/editcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ TARGETRELPATH:
if err := c.applyArgs(cmd.Context(), c.destSystem, c.DestDirAbsPath, args, applyArgsOptions{
include: c.Edit.include,
init: c.Edit.init,
recursive: false,
recursive: true,
umask: c.Umask,
preApplyFunc: c.defaultPreApplyFunc,
}); err != nil {
Expand All @@ -193,6 +193,7 @@ TARGETRELPATH:
defer watcher.Close()

for _, editorArg := range editorArgs {
// FIXME watch directories recursively
if err := watcher.Add(editorArg); err != nil {
return err
}
Expand Down
7 changes: 5 additions & 2 deletions pkg/cmd/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@ func setup(env *testscript.Env) error {
`:loop`,
`IF EXIST %~s1\NUL (`,
` copy /y NUL "%~1\.edited" >NUL`,
// FIXME recursively edit all files if in a directory
`) ELSE (`,
` echo # edited >> "%~1"`,
`)`,
Expand All @@ -677,8 +678,7 @@ func setup(env *testscript.Env) error {
default:
root["/bin"] = map[string]any{
// editor is a non-interactive script that appends "# edited\n" to
// the end of each file and creates an empty .edited file in each
// directory.
// the end of each file.
"editor": &vfst.File{
Perm: 0o755,
Contents: []byte(chezmoitest.JoinLines(
Expand All @@ -687,6 +687,9 @@ func setup(env *testscript.Env) error {
`for name in $*; do`,
` if [ -d $name ]; then`,
` touch $name/.edited`,
` for filename in $(find $name -type f); do`,
` echo "# edited" >> $filename`,
` done`,
` else`,
` echo "# edited" >> $name`,
` fi`,
Expand Down
13 changes: 13 additions & 0 deletions pkg/cmd/testdata/scripts/issue2300.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[windows] skip 'UNIX only' # FIXME

# test that chezmoi edit --apply applies changes to a directory
exec chezmoi edit --apply $HOME/.dir
grep '# edited' $HOME/.dir/file

-- home/user/.dir/file --
# contents of .dir/file
-- home/user/.config/chezmoi/chezmoi.toml --
[edit]
minDuration = 0
-- home/user/.local/share/chezmoi/dot_dir/file --
# contents of .dir/file

0 comments on commit 7a525b7

Please sign in to comment.