Skip to content

Commit

Permalink
Don't delete ignored files in exact directories
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Jan 15, 2019
1 parent 34eb20d commit 4fecad4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
3 changes: 3 additions & 0 deletions lib/chezmoi/dir.go
Expand Up @@ -124,6 +124,9 @@ func (d *Dir) Apply(fs vfs.FS, destDir string, ignore func(string) bool, umask o
for _, info := range infos {
name := info.Name()
if _, ok := d.Entries[name]; !ok {
if ignore(filepath.Join(d.targetName, name)) {
continue
}
if err := mutator.RemoveAll(filepath.Join(targetPath, name)); err != nil {
return err
}
Expand Down
26 changes: 16 additions & 10 deletions lib/chezmoi/target_state_test.go
Expand Up @@ -28,20 +28,22 @@ func TestEndToEnd(t *testing.T) {
"dir": map[string]interface{}{
"foo": "foo",
"bar": "bar",
"qux": "qux",
},
"replace_symlink": &vfst.Symlink{Target: "foo"},
},
"/home/user/.chezmoi": map[string]interface{}{
".git/HEAD": "HEAD",
".chezmoiignore": "{{ .ignore }} # comment\n",
"README.md": "contents of README.md\n",
"dot_bashrc": "bar",
"dot_hgrc.tmpl": "[ui]\nusername = {{ .name }} <{{ .email }}>\n",
"empty.tmpl": "{{ if false }}foo{{ end }}",
"empty_foo": "",
"exact_dir/foo": "foo",
"symlink_bar": "empty",
"symlink_replace_symlink": "bar",
".git/HEAD": "HEAD",
".chezmoiignore": "{{ .ignore }} # comment\n",
"README.md": "contents of README.md\n",
"dot_bashrc": "bar",
"dot_hgrc.tmpl": "[ui]\nusername = {{ .name }} <{{ .email }}>\n",
"empty.tmpl": "{{ if false }}foo{{ end }}",
"empty_foo": "",
"exact_dir/foo": "foo",
"exact_dir/.chezmoiignore": "qux\n",
"symlink_bar": "empty",
"symlink_replace_symlink": "bar",
},
},
sourceDir: "/home/user/.chezmoi",
Expand Down Expand Up @@ -76,6 +78,10 @@ func TestEndToEnd(t *testing.T) {
vfst.TestPath("/home/user/dir/bar",
vfst.TestDoesNotExist,
),
vfst.TestPath("/home/user/dir/qux",
vfst.TestModeIsRegular,
vfst.TestContentsString("qux"),
),
vfst.TestPath("/home/user/README.md",
vfst.TestDoesNotExist,
),
Expand Down

0 comments on commit 4fecad4

Please sign in to comment.