@@ -3,7 +3,6 @@ package controller
33import (
44 "errors"
55 "maps"
6- "slices"
76
87 "github.com/evilmartians/lefthook/v2/internal/git"
98 "github.com/evilmartians/lefthook/v2/internal/log"
@@ -102,7 +101,7 @@ func (g *guard) after() error {
102101 log .Warnf ("Couldn't get changeset: %s\n " , err )
103102 }
104103 if ! maps .Equal (g .changesetBefore , changesetAfter ) {
105- g .changesetDiff (changesetAfter )
104+ g .printDiff (changesetAfter )
106105 return ErrFailOnChanges
107106 }
108107 }
@@ -124,34 +123,27 @@ func (g *guard) after() error {
124123 return nil
125124}
126125
127- func (g * guard ) changesetDiff (changesetAfter map [string ]string ) {
126+ func (g * guard ) printDiff (changesetAfter map [string ]string ) {
128127 if ! g .failOnChangesDiff {
129128 return
130129 }
130+
131131 changed := make ([]string , 0 , len (g .changesetBefore ))
132132 for f , hashBefore := range g .changesetBefore {
133133 if hashAfter , ok := changesetAfter [f ]; ! ok || hashBefore != hashAfter {
134134 changed = append (changed , f )
135135 }
136136 }
137+
137138 for f := range changesetAfter {
138139 if _ , ok := g .changesetBefore [f ]; ! ok {
139140 changed = append (changed , f )
140141 }
141142 }
143+
142144 if len (changed ) == 0 {
143145 return
144146 }
145- slices .Sort (changed )
146- diffCmd := make ([]string , 0 , 4 ) //nolint:mnd // 3 or 4 elements
147- diffCmd = append (diffCmd , "git" , "diff" )
148- if log .Colorized () {
149- diffCmd = append (diffCmd , "--color" )
150- }
151- diffCmd = append (diffCmd , "--" )
152- if diff , err := g .git .Git .BatchedCmd (diffCmd , changed ); err != nil {
153- log .Warnf ("Couldn't diff changed files: %s" , err )
154- } else {
155- log .Println (diff )
156- }
147+
148+ g .git .PrintDiff (changed )
157149}
0 commit comments