Navigation Menu

Skip to content

Commit

Permalink
fix(archive): always strip parent if set (#3256)
Browse files Browse the repository at this point in the history
* 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 315935a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
3 changes: 0 additions & 3 deletions internal/archivefiles/archivefiles.go
Expand Up @@ -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))
}
Expand Down
20 changes: 20 additions & 0 deletions internal/archivefiles/archivefiles_test.go
Expand Up @@ -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"}})

Expand Down
3 changes: 0 additions & 3 deletions www/docs/customization/archive.md
Expand Up @@ -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
Expand Down

0 comments on commit 315935a

Please sign in to comment.