99 "path/filepath"
1010 "strings"
1111
12- "github.com/go-git/go-git/v5"
12+ git "github.com/go-git/go-git/v5"
1313 "github.com/go-git/go-git/v5/plumbing"
1414 "golang.org/x/mod/modfile"
1515)
@@ -93,9 +93,9 @@ func NewRepo(path string) (*Repo, error) {
9393// packages in vendor/) that changed since the given revision. A package will
9494// be flagged as change if any file within the package itself changed or if any
9595// packages it imports (whether local, vendored or external modules) changed
96- // since the given revision.
97- func (r * Repo ) ChangesFrom (revision string ) ([]string , error ) {
98- err := r .detectInternalChangesFrom (revision )
96+ // since the given revision. If allChanges is false it will be only concerned about changes in .go files.
97+ func (r * Repo ) ChangesFrom (revision string , allChanges bool ) ([]string , error ) {
98+ err := r .detectInternalChangesFrom (revision , allChanges )
9999 if err != nil {
100100 return nil , err
101101 }
@@ -194,9 +194,11 @@ func (r *Repo) addDependant(dependant *Package, dependencyName string) {
194194}
195195
196196// detectInternalChangesFrom will run a git diff (revision...HEAD) and flag as
197- // changed any packages (part of the module in repo or vendored packages) that
198- // have *.go files that are part of the that diff and packages that depend on them
199- func (r * Repo ) detectInternalChangesFrom (revision string ) error {
197+ // changed any packages (part of the module in the repo or vendored packages) that
198+ // have files that are part of that diff and packages that depend on them. If allFiles
199+ // is set to true, it checks for changes in all file types. If false, it only checks for
200+ // changes in *.go files.
201+ func (r * Repo ) detectInternalChangesFrom (revision string , allFiles bool ) error {
200202 repo , err := git .PlainOpen (r .path )
201203 if err != nil {
202204 return err
@@ -243,8 +245,8 @@ func (r *Repo) detectInternalChangesFrom(revision string) error {
243245 }
244246
245247 for _ , change := range diff {
246- // we're only interested in Go files
247- if ! strings . HasSuffix ( change . From . Name , ".go" ) {
248+ if ! allFiles && ! strings . HasSuffix ( change . From . Name , ".go" ) {
249+ // we're only interested in Go files
248250 continue
249251 }
250252
@@ -257,7 +259,11 @@ func (r *Repo) detectInternalChangesFrom(revision string) error {
257259
258260 // package is part of our module
259261 if pkgName == "" {
260- pkgName = r .ModuleName () + "/" + filepath .Dir (change .From .Name )
262+ if allFiles {
263+ pkgName = r .ModuleName ()
264+ } else {
265+ pkgName = r .ModuleName () + "/" + filepath .Dir (change .From .Name )
266+ }
261267 }
262268
263269 r .flagPackageAsChanged (pkgName )
0 commit comments