Repository: gohugoio/hugo (language: go)

Issue:
Bug in overlapping content when ignoring everything 
Discovered while adding test cases for #12912. 

A little hard to explain, but this test setup did not work as expected:

```toml
-- hugo.toml --
theme = "t1"
[[module.mounts]]
source = 'content'
target = 'content'
[[module.mounts]]
source = 'content2'
target = 'content/c2'
[[module.mounts]]
source = 'content3'
target = 'content/watchdisabled'
disableWatch = true
[[module.mounts]]
source = 'content4'
target = 'content/excludedsome'
excludeFiles = 'p1.md'
[[module.mounts]]
source = 'content5'
target = 'content/excludedall'
excludeFiles = '/**'
[[module.mounts]]
source = "hugo_stats.json"
target = "assets/watching/hugo_stats.json"
-- hugo_stats.json --
Some stats.
-- content/foo.md --
foo
-- content2/bar.md --
-- themes/t1/layouts/_default/single.html --
{{ .Content }}
-- themes/t1/static/f1.txt --
-- content3/p1.md --
-- content4/p1.md --
-- content4/p2.md --
-- content5/p3.md --
-- content5/p4.md --
```

The `excludeFiles = '/**'` effectively excluded the entire mount (correct), but due to a logic error in the code, we skipped all the other content mounts mounted to the same target root.

I don't suspect this to be a common setup, though.




Discussion / hints:

Fix patch:
diff --git a/hugofs/rootmapping_fs.go b/hugofs/rootmapping_fs.go
index 2ecd88e9e84..02e541a05b1 100644
--- a/hugofs/rootmapping_fs.go
+++ b/hugofs/rootmapping_fs.go
@@ -246,11 +246,11 @@ func (fs *RootMappingFs) Mounts(base string) ([]FileMetaInfo, error) {
 		return nil, nil
 	}
 
-	fss := make([]FileMetaInfo, len(roots))
-	for i, r := range roots {
+	fss := make([]FileMetaInfo, 0, len(roots))
+	for _, r := range roots {
 		if r.fiSingleFile != nil {
 			// A single file mount.
-			fss[i] = r.fiSingleFile
+			fss = append(fss, r.fiSingleFile)
 			continue
 		}
 		bfs := NewBasePathFs(fs.Fs, r.To)
@@ -261,9 +261,9 @@ func (fs *RootMappingFs) Mounts(base string) ([]FileMetaInfo, error) {
 		fs = decorateDirs(fs, r.Meta)
 		fi, err := fs.Stat("")
 		if err != nil {
-			return nil, fmt.Errorf("RootMappingFs.Dirs: %w", err)
+			continue
 		}
-		fss[i] = fi.(FileMetaInfo)
+		fss = append(fss, fi.(FileMetaInfo))
 	}
 
 	return fss, nil


Test patch:
diff --git a/hugolib/filesystems/basefs_test.go b/hugolib/filesystems/basefs_test.go
index e3970938665..3f189c8601a 100644
--- a/hugolib/filesystems/basefs_test.go
+++ b/hugolib/filesystems/basefs_test.go
@@ -220,6 +220,18 @@ target = 'content'
 source = 'content2'
 target = 'content/c2'
 [[module.mounts]]
+source = 'content3'
+target = 'content/watchdisabled'
+disableWatch = true
+[[module.mounts]]
+source = 'content4'
+target = 'content/excludedsome'
+excludeFiles = 'p1.md'
+[[module.mounts]]
+source = 'content5'
+target = 'content/excludedall'
+excludeFiles = '/**'
+[[module.mounts]]
 source = "hugo_stats.json"
 target = "assets/watching/hugo_stats.json"
 -- hugo_stats.json --
@@ -230,12 +242,27 @@ foo
 -- themes/t1/layouts/_default/single.html --
 {{ .Content }}
 -- themes/t1/static/f1.txt --
+-- content3/p1.md --
+-- content4/p1.md --
+-- content4/p2.md --
+-- content5/p3.md --
+-- content5/p4.md --
 `
 	b := hugolib.Test(t, files)
 	bfs := b.H.BaseFs
-	watchFilenames := bfs.WatchFilenames()
-	//   []string{"/hugo_stats.json", "/content", "/content2", "/themes/t1/layouts", "/themes/t1/layouts/_default", "/themes/t1/static"}
-	b.Assert(watchFilenames, qt.HasLen, 6)
+	watchFilenames := toSlashes(bfs.WatchFilenames())
+
+	// content3 has disableWatch = true
+	// content5 has excludeFiles = '/**'
+	b.Assert(watchFilenames, qt.DeepEquals, []string{"/hugo_stats.json", "/content", "/content2", "/content4", "/themes/t1/layouts", "/themes/t1/layouts/_default", "/themes/t1/static"})
+}
+
+func toSlashes(in []string) []string {
+	out := make([]string, len(in))
+	for i, s := range in {
+		out[i] = filepath.ToSlash(s)
+	}
+	return out
 }
 
 func TestNoSymlinks(t *testing.T) {