Skip to content

Commit 8cf692b

Browse files
authored
internal/repotools: IsModuleChanged bugfix (#1342)
1 parent e58d850 commit 8cf692b

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

internal/repotools/gomod/diff.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ import (
1111
func IsModuleChanged(moduleDir string, submodules []string, changes []string) (bool, error) {
1212
if moduleDir == "." {
1313
moduleDir = ""
14+
} else {
15+
// Append the path separator to ensure it is used in prefix matches. This ensure that we are looking
16+
// at this specific directory and children rather then any directory that has this moduleDir prefix.
17+
moduleDir += "/"
1418
}
1519

1620
isChildPathCache := make(map[string]bool)

internal/repotools/gomod/diff_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@ func TestIsModuleChanged(t *testing.T) {
9191
},
9292
want: true,
9393
},
94+
"module with no changes, but shares common prefix with a changed module": {
95+
moduleDir: "foobar",
96+
submodules: []string{"foobar/sub1"},
97+
changes: []string{
98+
"foobarbaz/baz.go",
99+
"foobar/sub1/sub1.go",
100+
},
101+
want: false,
102+
},
94103
}
95104
for name, tt := range tests {
96105
t.Run(name, func(t *testing.T) {

0 commit comments

Comments
 (0)