Find, verify, and analyze leaked credentials
Go credentialsdevsecopsdynamic-analysisprecommitscanningsecretsecret-managementsecretssecuritysecurity-toolstrufflehogverification
Use headref and check empty commits for base (#815)
Bill Rich509cf8b6fa9b
diff --git a/pkg/engine/git.go b/pkg/engine/git.goindex 1638d4ff2..379b90442 100644--- a/pkg/engine/git.go+++ b/pkg/engine/git.go@@ -59,7 +59,7 @@ func (e *Engine) ScanGit(ctx context.Context, c sources.Config) error {return errors.WrapPrefix(err, "unable to resolve head ref", 0)} else {c.HeadRef = head.String()- headCommit, _ = repo.CommitObject(plumbing.NewHash(c.BaseRef))+ headCommit, _ = repo.CommitObject(plumbing.NewHash(c.HeadRef))}} else {headCommit, err = repo.CommitObject(headHash)diff --git a/pkg/sources/git/git.go b/pkg/sources/git/git.goindex 2e686f3af..b5cc68313 100644--- a/pkg/sources/git/git.go+++ b/pkg/sources/git/git.go@@ -301,22 +301,22 @@ func (s *Git) ScanCommits(ctx context.Context, repo *git.Repository, path stringvar reachedBase = falselog.Debugf("Scanning repo")for commit := range commitChan {+ if scanOptions.MaxDepth > 0 && depth >= scanOptions.MaxDepth {+ log.Debugf("reached max depth")+ break+ }+ depth+++ if reachedBase && commit.Hash != scanOptions.BaseHash {+ break+ }+ if len(scanOptions.BaseHash) > 0 {+ if commit.Hash == scanOptions.BaseHash {+ log.Debugf("Reached base commit. Finishing scanning files.")+ reachedBase = true+ }+ }for _, diff := range commit.Diffs {log.WithField("commit", commit.Hash).WithField("file", diff.PathB).Trace("Scanning file from git")- if scanOptions.MaxDepth > 0 && depth >= scanOptions.MaxDepth {- log.Debugf("reached max depth")- break- }- depth++- if reachedBase && commit.Hash != scanOptions.BaseHash {- break- }- if len(scanOptions.BaseHash) > 0 {- if commit.Hash == scanOptions.BaseHash {- log.Debugf("Reached base commit. Finishing scanning files.")- reachedBase = true- }- }if !scanOptions.Filter.Pass(diff.PathB) {continue