diff --git a/internal/chezmoi/sourcestate.go b/internal/chezmoi/sourcestate.go index 343086e22e2..0e2b905b99c 100644 --- a/internal/chezmoi/sourcestate.go +++ b/internal/chezmoi/sourcestate.go @@ -2310,6 +2310,9 @@ func (s *SourceState) readExternalArchive( targetRelPath := externalRelPath.JoinString(name) if s.Ignore(targetRelPath) { + if fileInfo.IsDir() { + return fs.SkipDir + } return nil } diff --git a/internal/cmd/applycmd_test.go b/internal/cmd/applycmd_test.go index c65be9c0497..bf06101192b 100644 --- a/internal/cmd/applycmd_test.go +++ b/internal/cmd/applycmd_test.go @@ -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{ diff --git a/internal/cmd/testdata/scripts/issue2597.txtar b/internal/cmd/testdata/scripts/issue2597.txtar new file mode 100644 index 00000000000..c89ba35c276 --- /dev/null +++ b/internal/cmd/testdata/scripts/issue2597.txtar @@ -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 --