Find, verify, and analyze leaked credentials
Go credentialsdevsecopsdynamic-analysisprecommitscanningsecretsecret-managementsecretssecuritysecurity-toolstrufflehogverification
Surface missing git as an error during initialization (#1362)
Dustin Deckerc8944825dea4
diff --git a/pkg/sources/git/git.go b/pkg/sources/git/git.goindex 20d33fe0b..3840e355a 100644--- a/pkg/sources/git/git.go+++ b/pkg/sources/git/git.go@@ -102,6 +102,11 @@ func (s *Source) Init(aCtx context.Context, name string, jobId, sourceId int64,concurrency = runtime.NumCPU()}+ err := GitCmdCheck()+ if err != nil {+ return err+ }+s.git = NewGit(s.Type(), s.jobId, s.sourceId, s.name, s.verify, concurrency,func(file, email, commit, timestamp, repository string, line int64) *source_metadatapb.MetaData {return &source_metadatapb.MetaData{@@ -256,7 +261,7 @@ func gitURLParse(gitURL string) (*url.URL, error) {}func CloneRepo(ctx context.Context, userInfo *url.Userinfo, gitUrl string, args ...string) (string, *git.Repository, error) {- if err := gitCmdCheck(); err != nil {+ if err := GitCmdCheck(); err != nil {return "", nil, err}clonePath, err := os.MkdirTemp(os.TempDir(), "trufflehog")@@ -332,8 +337,8 @@ func CloneRepoUsingSSH(ctx context.Context, gitUrl string, args ...string) (strireturn CloneRepo(ctx, userInfo, gitUrl, args...)}-// gitCmdCheck checks if git is installed.-func gitCmdCheck() error {+// GitCmdCheck checks if git is installed.+func GitCmdCheck() error {if errors.Is(exec.Command("git").Run(), exec.ErrNotFound) {return fmt.Errorf("'git' command not found in $PATH. Make sure git is installed and included in $PATH")}@@ -341,7 +346,7 @@ func gitCmdCheck() error {}func (s *Git) ScanCommits(ctx context.Context, repo *git.Repository, path string, scanOptions *ScanOptions, chunksChan chan *sources.Chunk) error {- if err := gitCmdCheck(); err != nil {+ if err := GitCmdCheck(); err != nil {return err}diff --git a/pkg/sources/github/github.go b/pkg/sources/github/github.goindex 8b7eaee54..9f413b3c8 100644--- a/pkg/sources/github/github.go+++ b/pkg/sources/github/github.go@@ -220,6 +220,11 @@ func (s *Source) Init(aCtx context.Context, name string, jobID, sourceID int64,return fmt.Errorf("cannot specify head or base with multiple repositories")}+ err = git.GitCmdCheck()+ if err != nil {+ return err+ }+s.publicMap = map[string]source_metadatapb.Visibility{}s.git = git.NewGit(s.Type(), s.JobID(), s.SourceID(), s.name, s.verify, runtime.NumCPU(),diff --git a/pkg/sources/gitlab/gitlab.go b/pkg/sources/gitlab/gitlab.goindex 73ddcf0e4..7fb96fdea 100644--- a/pkg/sources/gitlab/gitlab.go+++ b/pkg/sources/gitlab/gitlab.go@@ -111,6 +111,11 @@ func (s *Source) Init(_ context.Context, name string, jobId, sourceId int64, vers.url = "https://gitlab.com/"}+ err = git.GitCmdCheck()+ if err != nil {+ return err+ }+s.git = git.NewGit(s.Type(), s.JobID(), s.SourceID(), s.name, s.verify, runtime.NumCPU(),func(file, email, commit, timestamp, repository string, line int64) *source_metadatapb.MetaData {return &source_metadatapb.MetaData{