Scan commit in since-commit (#416)

* Scan commit in since-commit.

Fixes #413

* address lint issue

Co-authored-by: Dustin Decker <dustin@trufflesec.com>
This commit is contained in:
Bill Rich 2022-04-15 14:58:54 -08:00 committed by GitHub
parent b970c43069
commit 1f55171437
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -277,6 +277,7 @@ func (s *Git) ScanCommits(repo *git.Repository, path string, scanOptions *ScanOp
urlMetadata := getSafeRemoteURL(repo, "origin")
var depth int64
var reachedBase = false
for file := range fileChan {
log.WithField("commit", file.PatchHeader.SHA).WithField("file", file.NewName).Trace("Scanning file from git")
if scanOptions.MaxDepth > 0 && depth >= scanOptions.MaxDepth {
@ -284,10 +285,13 @@ func (s *Git) ScanCommits(repo *git.Repository, path string, scanOptions *ScanOp
break
}
depth++
if reachedBase && file.PatchHeader.SHA != scanOptions.BaseHash {
break
}
if len(scanOptions.BaseHash) > 0 {
if file.PatchHeader.SHA == scanOptions.BaseHash {
log.Debugf("reached base commit")
break
log.Debugf("Reached base commit. Finishing scanning files.")
reachedBase = true
}
}
if !scanOptions.Filter.Pass(file.NewName) {