mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-29 04:34:46 +01:00
Audit commits based on date/time parameters (#385)
* time based audit * fixing SIGSEGV * adding options for date and time format + tests * Update repo.go * Update github.go * rebase + tests update
This commit is contained in:
1 parent
3e88ac6726
commit
e0f6399d5c
6 files changed
+151
-1
No files matched your search
+21
-1
@@ -418,9 +418,29 @@ func RegexMatched(f interface{}, re *regexp.Regexp) bool {
|
||||
// gitleaks gets the full git history.
|
||||
func getLogOptions(repo *Repo) (*git.LogOptions, error) {
|
||||
var logOpts git.LogOptions
|
||||
const dateformat string = "2006-01-02"
|
||||
const timeformat string = "2006-01-02T15:04:05-0700"
|
||||
if repo.Manager.Opts.CommitFrom != "" {
|
||||
logOpts.From = plumbing.NewHash(repo.Manager.Opts.CommitFrom)
|
||||
}
|
||||
if repo.Manager.Opts.CommitSince != "" {
|
||||
if t, err := time.Parse(timeformat, repo.Manager.Opts.CommitSince); err == nil {
|
||||
logOpts.Since = &t
|
||||
} else if t, err := time.Parse(dateformat, repo.Manager.Opts.CommitSince); err == nil {
|
||||
logOpts.Since = &t
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if repo.Manager.Opts.CommitUntil != "" {
|
||||
if t, err := time.Parse(timeformat, repo.Manager.Opts.CommitUntil); err == nil {
|
||||
logOpts.Until = &t
|
||||
} else if t, err := time.Parse(dateformat, repo.Manager.Opts.CommitUntil); err == nil {
|
||||
logOpts.Until = &t
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if repo.Manager.Opts.Branch != "" {
|
||||
refs, err := repo.Storer.IterReferences()
|
||||
if err != nil {
|
||||
@@ -449,7 +469,7 @@ func getLogOptions(repo *Repo) (*git.LogOptions, error) {
|
||||
}
|
||||
return &logOpts, nil
|
||||
}
|
||||
if !logOpts.From.IsZero() {
|
||||
if !logOpts.From.IsZero() || logOpts.Since != nil || logOpts.Until != nil {
|
||||
return &logOpts, nil
|
||||
}
|
||||
return &git.LogOptions{All: true}, nil
|
||||
|
||||
Reference in new issue
Block a user