trufflehog/pkg/sources/git/scan_options.go
Savely Krasovsky d062834997
initial support for bare repositories (#1499)
* feat: initial support for bare repositories

* feat: use concatenation instead of formatting and os.Getenv instead of os.Environ

Signed-off-by: Savely Krasovsky <savely@krasovs.ky>

* fix: go-git update with pre-receive hooks fix

Signed-off-by: Savely Krasovsky <savely@krasovs.ky>

* fix: remove info about pre-receive hook from README.md for now

Signed-off-by: Savely Krasovsky <savely@krasovs.ky>

* fix: don't scan staged while using --bare option, fixes to make it work with the latest master

Signed-off-by: Savely Krasovsky <savely@krasovs.ky>

* fix: small refactor according to #1518

Signed-off-by: Savely Krasovsky <savely@krasovs.ky>

---------

Signed-off-by: Savely Krasovsky <savely@krasovs.ky>
2023-08-03 11:23:41 -05:00

76 lines
1.6 KiB
Go

package git
import (
"github.com/go-git/go-git/v5"
"github.com/trufflesecurity/trufflehog/v3/pkg/common"
)
type ScanOptions struct {
Filter *common.Filter
BaseHash string // When scanning a git.Log, this is the oldest/first commit.
HeadHash string
MaxDepth int64
Bare bool
ExcludeGlobs []string
LogOptions *git.LogOptions
}
type ScanOption func(*ScanOptions)
func ScanOptionFilter(filter *common.Filter) ScanOption {
return func(scanOptions *ScanOptions) {
scanOptions.Filter = filter
}
}
func ScanOptionBaseHash(hash string) ScanOption {
return func(scanOptions *ScanOptions) {
scanOptions.BaseHash = hash
}
}
func ScanOptionHeadCommit(hash string) ScanOption {
return func(scanOptions *ScanOptions) {
scanOptions.HeadHash = hash
}
}
func ScanOptionMaxDepth(maxDepth int64) ScanOption {
return func(scanOptions *ScanOptions) {
scanOptions.MaxDepth = maxDepth
}
}
func ScanOptionExcludeGlobs(globs []string) ScanOption {
return func(scanOptions *ScanOptions) {
scanOptions.ExcludeGlobs = globs
}
}
func ScanOptionLogOptions(logOptions *git.LogOptions) ScanOption {
return func(scanOptions *ScanOptions) {
scanOptions.LogOptions = logOptions
}
}
func ScanOptionBare(bare bool) ScanOption {
return func(scanOptions *ScanOptions) {
scanOptions.Bare = bare
}
}
func NewScanOptions(options ...ScanOption) *ScanOptions {
scanOptions := &ScanOptions{
Filter: common.FilterEmpty(),
BaseHash: "",
HeadHash: "",
MaxDepth: -1,
LogOptions: &git.LogOptions{
All: true,
},
}
for _, option := range options {
option(scanOptions)
}
return scanOptions
}