9
9
"path/filepath"
10
10
"strings"
11
11
12
- "github.com/go-git/go-git/v5"
12
+ git "github.com/go-git/go-git/v5"
13
13
"github.com/go-git/go-git/v5/plumbing"
14
14
"golang.org/x/mod/modfile"
15
15
)
@@ -93,9 +93,9 @@ func NewRepo(path string) (*Repo, error) {
93
93
// packages in vendor/) that changed since the given revision. A package will
94
94
// be flagged as change if any file within the package itself changed or if any
95
95
// 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 )
99
99
if err != nil {
100
100
return nil , err
101
101
}
@@ -194,9 +194,11 @@ func (r *Repo) addDependant(dependant *Package, dependencyName string) {
194
194
}
195
195
196
196
// 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 {
200
202
repo , err := git .PlainOpen (r .path )
201
203
if err != nil {
202
204
return err
@@ -243,8 +245,8 @@ func (r *Repo) detectInternalChangesFrom(revision string) error {
243
245
}
244
246
245
247
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
248
250
continue
249
251
}
250
252
@@ -257,7 +259,11 @@ func (r *Repo) detectInternalChangesFrom(revision string) error {
257
259
258
260
// package is part of our module
259
261
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
+ }
261
267
}
262
268
263
269
r .flagPackageAsChanged (pkgName )
0 commit comments