Skip to content

Commit

Permalink
Use headref and check empty commits for base (#815)
Browse files Browse the repository at this point in the history
  • Loading branch information
bill-rich committed Sep 21, 2022
1 parent ddc81bd commit 509cf8b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pkg/engine/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 14 additions & 14 deletions pkg/sources/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,22 +301,22 @@ func (s *Git) ScanCommits(ctx context.Context, repo *git.Repository, path string
var reachedBase = false
log.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
Expand Down

0 comments on commit 509cf8b

Please sign in to comment.