From 9b419717e6988027367f5f3f08387632fac228ca Mon Sep 17 00:00:00 2001 From: Owen Rumney Date: Tue, 30 Mar 2021 17:26:55 +0100 Subject: [PATCH] fix issue with ignore on first commit --- internal/app/squealer/scan/git_scanner.go | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/internal/app/squealer/scan/git_scanner.go b/internal/app/squealer/scan/git_scanner.go index 5756148..f33f15b 100644 --- a/internal/app/squealer/scan/git_scanner.go +++ b/internal/app/squealer/scan/git_scanner.go @@ -2,14 +2,15 @@ package scan import ( "bufio" + "io" + "os" + "sync" + "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/plumbing" "github.com/go-git/go-git/v5/plumbing/object" "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus" - "io" - "os" - "sync" "github.com/owenrumney/squealer/internal/app/squealer/match" "github.com/owenrumney/squealer/internal/app/squealer/mertics" @@ -211,7 +212,13 @@ func (s *gitScanner) processFile(cf CommitFile) error { if isBin, err := file.IsBinary(); err != nil || isBin { return nil } - if shouldIgnore(cf.changePath, s.ignorePaths, s.ignoreExtensions) { + + filepath := cf.changePath + if filepath == "" { + filepath = cf.file.Name + } + + if shouldIgnore(filepath, s.ignorePaths, s.ignoreExtensions) { return nil } content, err := file.Contents() @@ -219,11 +226,6 @@ func (s *gitScanner) processFile(cf CommitFile) error { return err } - filepath := cf.changePath - if filepath == "" { - filepath = cf.file.Name - } - err = s.mc.Evaluate(filepath, content, cf.commit) s.metrics.IncrementFilesProcessed() return err