/
githubmirror
/
gitleaks
ΠΠ±Π·ΠΎΡ
ΠΠΎΠΊΡΠΌΠ΅Π½ΡΠ°ΡΠΈΡ
ΠΠΎΠΉΡΠΈ
/
githubmirror
/
gitleaks
ΠΠΎΠ΄
ΠΠ°Π΄Π°ΡΠΈ
ΠΠΈΠΊΠΈ
ΠΠ°ΠΊΠ΅ΡΡ
0
Π Π΅Π»ΠΈΠ·Ρ
0
ΠΠ½Π°Π»ΠΈΡΠΈΠΊΠ°
ΠΠ΅Π·ΠΎΠΏΠ°ΡΠ½ΠΎΡΡΡ
v8.23.1
detect/git.go
74 ΡΡΡΠΎΠΊΠΈ
2 KB
Richard Gomez
refactor: central logger (#1692)
13 ΡΠ½Π² 2025, 17:09
ΠΠ΅ Π²Π΅ΡΠΈΡΠΈΡΠΈΡΠΎΠ²Π°Π½
13 ΡΠ½Π² 2025, 17:09
ab38a46
ΠΠΎΠ΄
ΠΠ²ΡΠΎΡΡΡΠ²ΠΎ
Π ΡΡΠΌ ΠΊΠΎΠ΄?
package detect import ( "github.com/gitleaks/go-gitdiff/gitdiff" "github.com/zricethezav/gitleaks/v8/logging" "github.com/zricethezav/gitleaks/v8/report" "github.com/zricethezav/gitleaks/v8/sources" ) func (d *Detector) DetectGit(gitCmd *sources.GitCmd) ([]report.Finding, error) { defer gitCmd.Wait() diffFilesCh := gitCmd.DiffFilesCh() errCh := gitCmd.ErrCh() // loop to range over both DiffFiles (stdout) and ErrCh (stderr) for diffFilesCh != nil || errCh != nil { select { case gitdiffFile, open := <-diffFilesCh: if !open { diffFilesCh = nil break } // skip binary files if gitdiffFile.IsBinary || gitdiffFile.IsDelete { continue } // Check if commit is allowed commitSHA := "" if gitdiffFile.PatchHeader != nil { commitSHA = gitdiffFile.PatchHeader.SHA if d.Config.Allowlist.CommitAllowed(gitdiffFile.PatchHeader.SHA) { continue } } d.addCommit(commitSHA) d.Sema.Go(func() error { for _, textFragment := range gitdiffFile.TextFragments { if textFragment == nil { return nil } fragment := Fragment{ Raw: textFragment.Raw(gitdiff.OpAdd), CommitSHA: commitSHA, FilePath: gitdiffFile.NewName, } for _, finding := range d.Detect(fragment) { d.addFinding(augmentGitFinding(finding, textFragment, gitdiffFile)) } } return nil }) case err, open := <-errCh: if !open { errCh = nil break } return d.findings, err } } if err := d.Sema.Wait(); err != nil { return d.findings, err } logging.Info().Msgf("%d commits scanned.", len(d.commitMap)) logging.Debug().Msg("Note: this number might be smaller than expected due to commits with no additions") return d.findings, nil }