Skip to content
Permalink
Browse files
fix(archive): always strip parent if set (#3256)
* Always strip parents.

* refactor: improve code a bit

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>

* refactor: even simpler

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>

Co-authored-by: Nathan Hammond <nathan.hammond@vercel.com>
  • Loading branch information
caarlos0 and nathanhammond committed Jul 27, 2022
1 parent a02bcef commit 315935aedc9908b078ae525b33ddb42b2fafcc54
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
@@ -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))
}
@@ -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"}})

@@ -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

0 comments on commit 315935a

Please sign in to comment.