Skip to content

Commit

Permalink
fix: Apply .chezmoiignore to dirs in external archives
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Apr 26, 2024
1 parent cb162d6 commit c758a1c
Show file tree
Hide file tree
Showing 3 changed files with 44 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 @@ -2310,6 +2310,9 @@ func (s *SourceState) readExternalArchive(
targetRelPath := externalRelPath.JoinString(name)

if s.Ignore(targetRelPath) {
if fileInfo.IsDir() {
return fs.SkipDir
}
return nil
}

Expand Down
21 changes: 21 additions & 0 deletions internal/cmd/applycmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,27 @@ func TestIssue2132(t *testing.T) {
})
}

func TestIssue2597(t *testing.T) {
chezmoitest.WithTestFS(t, map[string]any{
"/home/user": map[string]any{
".local/share/chezmoi": map[string]any{
".chezmoiexternal.toml": chezmoitest.JoinLines(
`[".oh-my-zsh"]`,
` type = "archive"`,
` url = "https://github.com/ohmyzsh/ohmyzsh/archive/master.tar.gz"`,
` exact = true`,
` stripComponents = 1`,
),
".chezmoiignore": chezmoitest.JoinLines(
`.oh-my-zsh/cache`,
),
},
},
}, func(fileSystem vfs.FS) {
assert.NoError(t, newTestConfig(t, fileSystem).execute([]string{"apply"}))
})
}

func TestIssue3206(t *testing.T) {
chezmoitest.WithTestFS(t, map[string]any{
"/home/user": map[string]any{
Expand Down
20 changes: 20 additions & 0 deletions internal/cmd/testdata/scripts/issue2597.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
exec tar czf www/master.tar.gz master

httpd www

exec chezmoi apply
exists $HOME/.oh-my-zsh/README.md
! exists $HOME/.oh-my-zsh/cache/.gitkeep

-- home/user/.local/share/chezmoi/.chezmoiexternal.toml.tmpl --
[".oh-my-zsh"]
type = "archive"
url = "{{ env "HTTPD_URL" }}/master.tar.gz"
exact = true
stripComponents = 1
-- home/user/.local/share/chezmoi/.chezmoiignore --
.oh-my-zsh/cache
-- master/README.md --
# contents of README.md
-- master/cache/.gitkeep --
-- www/.keep --

0 comments on commit c758a1c

Please sign in to comment.