@@ -574,7 +574,7 @@ func preReceiveSecrets(ctx *preReceiveContext, oldCommitID, newCommitID string,
574574 var detector * gitleaks.Detector
575575
576576 config , _ , err := git .NewCommand ("show" ).AddDynamicArguments (repo .DefaultBranch + ":.gitleaks.toml" ).RunStdString (ctx , & git.RunOpts {Dir : repo .RepoPath (), Env : ctx .env })
577- if err != nil { //File has to exist to be taken into consideration
577+ if err != nil { // File has to exist to be taken into consideration
578578 detector , err = newDetector (config )
579579 } else {
580580 detector , err = gitleaks .NewDetectorDefaultConfig ()
@@ -592,12 +592,22 @@ func preReceiveSecrets(ctx *preReceiveContext, oldCommitID, newCommitID string,
592592 oldCommitID = ctx .Repo .GetObjectFormat ().EmptyTree ().String ()
593593 }
594594 }
595- out , _ , err := git .NewCommand ("show" , "-U0" ).AddDynamicArguments (oldCommitID + ".." + newCommitID ).RunStdBytes (ctx , & git.RunOpts {Dir : repo .RepoPath (), Env : ctx .env })
595+
596+ stdout := & bytes.Buffer {}
597+ err = git .NewCommand ("log" , "-U0" , "-p" ).AddDynamicArguments (oldCommitID + ".." + newCommitID ).Run (
598+ ctx ,
599+ & git.RunOpts {
600+ Dir : repo .RepoPath (),
601+ Env : ctx .env ,
602+ Stdout : stdout ,
603+ },
604+ )
596605 if err != nil {
597606 ctx .JSON (http .StatusTeapot , private.Response {Err : err .Error (), UserMsg : err .Error ()})
598607 return
599608 }
600- giteaCmd , err := newPreReceiveDiff (bytes .NewReader (out ))
609+
610+ giteaCmd , err := newPreReceiveDiff (stdout )
601611 if err != nil {
602612 ctx .JSON (http .StatusTeapot , private.Response {Err : err .Error (), UserMsg : err .Error ()})
603613 return
@@ -658,7 +668,6 @@ func newDetector(config string) (*gitleaks.Detector, error) {
658668 viper .SetConfigType ("toml" )
659669
660670 err := viper .ReadConfig (strings .NewReader (config ))
661-
662671 if err != nil {
663672 return nil , err
664673 }
0 commit comments