From c758a1c57fb6084631736a7dda5ac0aaeeffa946 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Fri, 26 Apr 2024 20:50:10 +0200 Subject: [PATCH] fix: Apply .chezmoiignore to dirs in external archives --- internal/chezmoi/sourcestate.go | 3 +++ internal/cmd/applycmd_test.go | 21 +++++++++++++++++++ internal/cmd/testdata/scripts/issue2597.txtar | 20 ++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 internal/cmd/testdata/scripts/issue2597.txtar 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 --