Skip to content

Commit

Permalink
update with toHash
Browse files Browse the repository at this point in the history
  • Loading branch information
owenrumney-f3 committed Feb 9, 2021
1 parent 26754fe commit f149a3b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
3 changes: 3 additions & 0 deletions cmd/squealer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var (
noGit = false
configFilePath string
fromHash string
toHash string
)

func squeal(_ *cobra.Command, args []string) {
Expand Down Expand Up @@ -62,6 +63,7 @@ func getScanner(cfg *config.Config, basePath string) scan.Scanner {
Redacted: redacted,
NoGit: noGit,
FromHash: fromHash,
ToHash: toHash,
})
if err != nil {
panic(err)
Expand Down Expand Up @@ -97,6 +99,7 @@ func main() {
rootcmd.PersistentFlags().BoolVar(&noGit, "no-git", false, "Scan as a directory rather than a git history.")
rootcmd.PersistentFlags().StringVar(&configFilePath, "config-file", "", "Path to the config file with the rules.")
rootcmd.PersistentFlags().StringVar(&fromHash, "from-hash", "", "The starting hash to scan from.")
rootcmd.PersistentFlags().StringVar(&toHash, "to-hash", "", "The starting hash to scan from.")

listenForExit()
if err := rootcmd.Execute(); err != nil {
Expand Down
26 changes: 22 additions & 4 deletions internal/app/squealer/scan/git_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ type gitScanner struct {
workingDirectory string
ignorePaths []string
fromHash plumbing.Hash
toHash plumbing.Hash
ignoreExtensions []string
headSet bool
}

func (s *gitScanner) GetType() ScannerType {
Expand All @@ -46,6 +48,12 @@ func newGitScanner(sc ScannerConfig) (*gitScanner, error) {
scanner.fromHash = plumbing.NewHash(sc.FromHash)
}

if len(sc.ToHash) > 0 {
fmt.Printf("setting the from hash to %s\n", sc.ToHash)
scanner.toHash = plumbing.NewHash(sc.ToHash)
scanner.headSet = true
}

return scanner, nil
}

Expand Down Expand Up @@ -84,16 +92,26 @@ func (s *gitScanner) Scan() error {
}

func (s *gitScanner) getRelevantCommitIter(client *git.Repository) (object.CommitIter, error) {
headRef, _ := client.Head()
var headRef plumbing.Hash
if s.headSet {
headRef = s.toHash

} else {
ref, _ := client.Head()
if ref != nil {
headRef = ref.Hash()
}
headRef = plumbing.ZeroHash
}

var commits object.CommitIter
var err error

if headRef != nil {
if headRef != plumbing.ZeroHash {
commits, err = client.Log(&git.LogOptions{
From: headRef.Hash(),
From: headRef,
Order: git.LogOrderCommitterTime,
} )
})
if err != nil {
return nil, err
}
Expand Down
1 change: 1 addition & 0 deletions internal/app/squealer/scan/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type ScannerConfig struct {
Redacted bool
NoGit bool
FromHash string
ToHash string
}

type Scanner interface {
Expand Down

0 comments on commit f149a3b

Please sign in to comment.