Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tighten the scope of changes considered #42

Merged
merged 2 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions gta.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,13 +353,29 @@ func (g *GTA) markedPackages() (map[string]map[string]bool, error) {
return nil, fmt.Errorf("pulling package information for %q, %v", abs, err)
}

// create a simple set of changed pkgs by import path
changed[pkg.ImportPath] = false
// create a simple set of changed pkgs by import path. The packages that are tracked have at least one of the following properties:
// * deleted (there's no need to check for this property here; it's already handled by this point)
// * changed Go files
// * tests are affected (e.g. files below a testdata directory)
// * changed embedded files
shouldMark := hasGoFile(dir.Files)
if _, ok := onlyTestsAffected[abs]; ok {
onlyTestPackagesChanged[pkg.ImportPath] = struct{}{}
shouldMark = true
}
if _, ok := onlyTestPackagesChanged[pkg.ImportPath]; ok {
shouldMark = true
}

if shouldMark {
changed[pkg.ImportPath] = false
}
}

// do not assume that only tests are affected if the package's embedded files
// were changed. We do not have enough information to know whether the
// embedded files are exclusively used by the tests, so assume that are used
// by more than the tests.
for k := range onlyTestPackagesChanged {
if _, ok := embeddedChanged[k]; ok {
delete(onlyTestPackagesChanged, k)
Expand Down
19 changes: 19 additions & 0 deletions gta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,25 @@ func TestGTA_ChangedPackages(t *testing.T) {

testChangedPackages(t, diff, nil, want)
})

t.Run("change non-go file", func(t *testing.T) {
diff := map[string]Directory{
"embed": {Exists: true, Files: []string{"README.md"}},
"unimported": {Exists: true, Files: []string{"unimported.go"}},
}

want := &Packages{
Dependencies: map[string][]Package{},
Changes: []Package{
{ImportPath: "unimported", Dir: "unimported"},
},
AllChanges: []Package{
{ImportPath: "unimported", Dir: "unimported"},
},
}

testChangedPackages(t, diff, nil, want)
})
}

func TestGTA_Prefix(t *testing.T) {
Expand Down
Loading