Find, verify, and analyze leaked credentials
Go credentialsdevsecopsdynamic-analysisprecommitscanningsecretsecret-managementsecretssecuritysecurity-toolstrufflehogverification
add merge support (#1561)
Zachary Rice3897454dbb4c
diff --git a/pkg/gitparse/gitparse.go b/pkg/gitparse/gitparse.goindex e22c809c9..84a9da26e 100644--- a/pkg/gitparse/gitparse.go+++ b/pkg/gitparse/gitparse.go@@ -56,6 +56,7 @@ type ParseState intconst (Initial ParseState = iotaCommitLine+ MergeLineAuthorLineDateLineMessageStartLine@@ -76,6 +77,7 @@ func (state ParseState) String() string {return [...]string{"Initial","CommitLine",+ "MergeLine","AuthorLine","DateLine","MessageStartLine",@@ -276,6 +278,8 @@ func (c *Parser) FromReader(ctx context.Context, stdOut io.Reader, commitChan chif len(line) >= 47 {currentCommit.Hash = string(line[7:47])}+ case isMergeLine(isStaged, latestState, line):+ latestState = MergeLinecase isAuthorLine(isStaged, latestState, line):latestState = AuthorLine@@ -428,6 +432,16 @@ func (c *Parser) FromReader(ctx context.Context, stdOut io.Reader, commitChan chctx.Logger().V(2).Info("finished parsing git log.", "total_log_size", totalLogSize)}+func isMergeLine(isStaged bool, latestState ParseState, line []byte) bool {+ if isStaged || latestState != CommitLine {+ return false+ }+ if len(line) > 6 && bytes.Equal(line[:6], []byte("Merge:")) {+ return true+ }+ return false+}+// commit 7a95bbf0199e280a0e42dbb1d1a3f56cdd0f6e05func isCommitLine(isStaged bool, latestState ParseState, line []byte) bool {if isStaged || !(latestState == Initial ||@@ -450,7 +464,7 @@ func isCommitLine(isStaged bool, latestState ParseState, line []byte) bool {// Author: Bill Rich <[email protected]>func isAuthorLine(isStaged bool, latestState ParseState, line []byte) bool {- if isStaged || !(latestState == CommitLine) {+ if isStaged || !(latestState == CommitLine || latestState == MergeLine) {return false}if len(line) > 8 && bytes.Equal(line[:7], []byte("Author:")) {diff --git a/pkg/gitparse/gitparse_test.go b/pkg/gitparse/gitparse_test.goindex 2c400b865..ce8427fd9 100644--- a/pkg/gitparse/gitparse_test.go+++ b/pkg/gitparse/gitparse_test.go@@ -67,6 +67,25 @@ func TestLineChecks(t *testing.T) {},function: isCommitLine,},+ "mergeLine": {+ passes: []testCaseLine{+ {+ CommitLine,+ []byte("Merge: f21a95535a2 ed08d10bcf5"),+ },+ },+ fails: []testCaseLine{+ {+ DateLine,+ []byte(" Merge pull request #34511 from cescoffier/duplicated-context-doc"),+ },+ {+ CommitLine,+ []byte("notcorrect"),+ },+ },+ function: isMergeLine,+ },"authorLine": {passes: []testCaseLine{{