mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-29 12:44:22 +01:00
Fixing patch direction and making additions the default (#408)
* Fixing patch direction and making additions the default * adding test
This commit is contained in:
1 parent
e36b550851
commit
cfbb600fcb
16 files changed
+103
-410
No files matched your search
@@ -366,6 +366,16 @@ func TestAudit(t *testing.T) {
|
||||
},
|
||||
wantPath: "../test_data/test_local_repo_two_whitelist_commits.json",
|
||||
},
|
||||
{
|
||||
description: "test local repo two deletion",
|
||||
opts: options.Options{
|
||||
RepoPath: "../test_data/test_repos/test_repo_2",
|
||||
Report: "../test_data/test_local_repo_two_leaks_deletion.json.got",
|
||||
ReportFormat: "json",
|
||||
Deletion: true,
|
||||
},
|
||||
wantPath: "../test_data/test_local_repo_two_leaks_deletion.json",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
|
||||
+7
-5
@@ -213,10 +213,7 @@ func (repo *Repo) AuditUncommitted() error {
|
||||
diffs := diffmatchpatch.New().DiffMain(prevFileContents, currFileContents, false)
|
||||
var diffContents string
|
||||
for _, d := range diffs {
|
||||
switch d.Type {
|
||||
case diffmatchpatch.DiffInsert:
|
||||
diffContents += fmt.Sprintf("%s\n", d.Text)
|
||||
case diffmatchpatch.DiffDelete:
|
||||
if d.Type == diffmatchpatch.DiffInsert {
|
||||
diffContents += fmt.Sprintf("%s\n", d.Text)
|
||||
}
|
||||
}
|
||||
@@ -312,8 +309,13 @@ func (repo *Repo) Audit() error {
|
||||
if repo.timeoutReached() {
|
||||
return nil
|
||||
}
|
||||
if parent == nil {
|
||||
// shouldn't reach this point but just in case
|
||||
return nil
|
||||
}
|
||||
|
||||
start := time.Now()
|
||||
patch, err := c.Patch(parent)
|
||||
patch, err := parent.Patch(c)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not generate patch")
|
||||
}
|
||||
|
||||
+5
-2
@@ -33,7 +33,7 @@ func inspectPatch(patch *object.Patch, c *object.Commit, repo *Repo) {
|
||||
continue
|
||||
}
|
||||
for _, chunk := range f.Chunks() {
|
||||
if chunk.Type() == fdiff.Delete || chunk.Type() == fdiff.Add {
|
||||
if chunk.Type() == fdiff.Add || (repo.Manager.Opts.Deletion && chunk.Type() == fdiff.Delete){
|
||||
InspectFile(chunk.Content(), getFileFullPath(f), c, repo)
|
||||
}
|
||||
}
|
||||
@@ -294,8 +294,11 @@ func inspectCommitPatches(c *object.Commit, repo *Repo) error {
|
||||
if repo.timeoutReached() {
|
||||
return nil
|
||||
}
|
||||
if parent == nil {
|
||||
return nil
|
||||
}
|
||||
start := time.Now()
|
||||
patch, err := c.Patch(parent)
|
||||
patch, err := parent.Patch(c)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not generate patch")
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user