From 315935aedc9908b078ae525b33ddb42b2fafcc54 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Wed, 27 Jul 2022 09:55:55 -0300 Subject: [PATCH] fix(archive): always strip parent if set (#3256) * Always strip parents. * refactor: improve code a bit Signed-off-by: Carlos A Becker * refactor: even simpler Signed-off-by: Carlos A Becker Co-authored-by: Nathan Hammond --- internal/archivefiles/archivefiles.go | 3 --- internal/archivefiles/archivefiles_test.go | 20 ++++++++++++++++++++ www/docs/customization/archive.md | 3 --- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/internal/archivefiles/archivefiles.go b/internal/archivefiles/archivefiles.go index 7be9e35dd88..4852e977aef 100644 --- a/internal/archivefiles/archivefiles.go +++ b/internal/archivefiles/archivefiles.go @@ -64,9 +64,6 @@ func unique(in []config.File) []config.File { } func destinationFor(f config.File, path string) string { - if f.Destination == "" { - return path - } if f.StripParent { return filepath.Join(f.Destination, filepath.Base(path)) } diff --git a/internal/archivefiles/archivefiles_test.go b/internal/archivefiles/archivefiles_test.go index a67cf4e68f6..3c99662c6e4 100644 --- a/internal/archivefiles/archivefiles_test.go +++ b/internal/archivefiles/archivefiles_test.go @@ -31,6 +31,26 @@ func TestEval(t *testing.T) { }, result) }) + t.Run("strip parent plays nicely with destination omitted", func(t *testing.T) { + result, err := Eval(tmpl, []config.File{{Source: "./testdata/a/b", StripParent: true}}) + + require.NoError(t, err) + require.Equal(t, []config.File{ + {Source: "testdata/a/b/a.txt", Destination: "a.txt"}, + {Source: "testdata/a/b/c/d.txt", Destination: "d.txt"}, + }, result) + }) + + t.Run("strip parent plays nicely with destination as an empty string", func(t *testing.T) { + result, err := Eval(tmpl, []config.File{{Source: "./testdata/a/b", Destination: "", StripParent: true}}) + + require.NoError(t, err) + require.Equal(t, []config.File{ + {Source: "testdata/a/b/a.txt", Destination: "a.txt"}, + {Source: "testdata/a/b/c/d.txt", Destination: "d.txt"}, + }, result) + }) + t.Run("match multiple files within tree without destination", func(t *testing.T) { result, err := Eval(tmpl, []config.File{{Source: "./testdata/a"}}) diff --git a/www/docs/customization/archive.md b/www/docs/customization/archive.md index 83d1ee80105..01645bd88e3 100644 --- a/www/docs/customization/archive.md +++ b/www/docs/customization/archive.md @@ -142,9 +142,6 @@ files: # ... ``` -!!! warning - `strip_parent` is only effective if `dst` is not empty. - ## Packaging only the binaries Since GoReleaser will always add the `README` and `LICENSE` files to the