From 16406d9d77cb4861bba9df8ca39e7dadfe41eb45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Wed, 21 Feb 2024 20:16:02 +0100 Subject: Fix regression on handling of overlapping file mounts But note that the overlay file system is set up horizontally (project -> module1 -> module2), so I would not recommend too complex overlapping mount setups within the same module. But this worked in v0.122.0, so we should fix it. Fixes #12103 --- hugolib/filesystems/basefs_test.go | 42 +++++++++++++++++++++++++++++++++++--- hugolib/integrationtest_builder.go | 6 +++++- 2 files changed, 44 insertions(+), 4 deletions(-) (limited to 'hugolib') diff --git a/hugolib/filesystems/basefs_test.go b/hugolib/filesystems/basefs_test.go index ebbb378d3..f5b7b6170 100644 --- a/hugolib/filesystems/basefs_test.go +++ b/hugolib/filesystems/basefs_test.go @@ -478,11 +478,47 @@ Home. _ = stat("blog/b1.md") } +func TestStaticComposite(t *testing.T) { + files := ` +-- hugo.toml -- +disableKinds = ["taxonomy", "term"] +[module] +[[module.mounts]] +source = "myfiles/f1.txt" +target = "static/files/f1.txt" +[[module.mounts]] +source = "f3.txt" +target = "static/f3.txt" +[[module.mounts]] +source = "static" +target = "static" +-- static/files/f2.txt -- +f2 +-- myfiles/f1.txt -- +f1 +-- f3.txt -- +f3 +-- layouts/home.html -- +Home. + +` + b := hugolib.Test(t, files) + + b.AssertFs(b.H.BaseFs.StaticFs(""), ` +. true +f3.txt false +files true +files/f1.txt false +files/f2.txt false +`) +} + func checkFileCount(fs afero.Fs, dirname string, c *qt.C, expected int) { c.Helper() - count, _, err := countFilesAndGetFilenames(fs, dirname) - c.Assert(err, qt.IsNil) - c.Assert(count, qt.Equals, expected) + count, names, err := countFilesAndGetFilenames(fs, dirname) + namesComment := qt.Commentf("filenames: %v", names) + c.Assert(err, qt.IsNil, namesComment) + c.Assert(count, qt.Equals, expected, namesComment) } func checkFileContent(fs afero.Fs, filename string, c *qt.C, expected ...string) { diff --git a/hugolib/integrationtest_builder.go b/hugolib/integrationtest_builder.go index 194b79c68..8c7017a87 100644 --- a/hugolib/integrationtest_builder.go +++ b/hugolib/integrationtest_builder.go @@ -275,9 +275,13 @@ func (s *IntegrationTestBuilder) AssertFileContentExact(filename string, matches } func (s *IntegrationTestBuilder) AssertPublishDir(matches ...string) { + s.AssertFs(s.fs.PublishDir, matches...) +} + +func (s *IntegrationTestBuilder) AssertFs(fs afero.Fs, matches ...string) { s.Helper() var buff bytes.Buffer - helpers.PrintFs(s.H.Fs.PublishDir, "", &buff) + helpers.PrintFs(fs, "", &buff) printFsLines := strings.Split(buff.String(), "\n") sort.Strings(printFsLines) content := strings.TrimSpace((strings.Join(printFsLines, "\n"))) -- cgit v1.2.3