@@ -78,27 +78,15 @@ private IEnumerable<IIssue> CheckForBinaryFilesNotTrackedByLfs(IssueCommentForma
7878            } 
7979
8080            var  textFiles  =  this . GetTextFilesFromRepository ( ) ; 
81-             if  ( ! textFiles . Any ( ) ) 
82-             { 
83-                 return  new  List < IIssue > ( ) ; 
84-             } 
85- 
86-             this . Log . Information ( "Determine binary files..." ) ; 
87-             var  binaryFiles  =  allFiles . Except ( textFiles ) ; 
88-             this . Log . Information ( "Found {0} binary file(s)" ,  binaryFiles . Count ( ) ) ; 
8981
82+             var  binaryFiles  =  this . DetermineBinaryFiles ( allFiles ,  textFiles ) ; 
9083            if  ( ! binaryFiles . Any ( ) ) 
9184            { 
9285                return  new  List < IIssue > ( ) ; 
9386            } 
9487
95-             this . Log . Debug ( string . Join ( Environment . NewLine ,  binaryFiles ) ) ; 
96- 
97-             this . Log . Information ( "Checking if binary files are tracked by LFS..." ) ; 
9888            var  lfsTrackedFiles  =  this . GetLfsTrackedFilesFromRepository ( ) ; 
99- 
100-             var  binaryFilesNotTrackedByLfs  =  binaryFiles . Except ( lfsTrackedFiles ) ; 
101-             this . Log . Information ( "Found {0} binary file(s) not tracked by LFS" ,  binaryFilesNotTrackedByLfs . Count ( ) ) ; 
89+             var  binaryFilesNotTrackedByLfs  =  this . DetermineBinaryFilesNotTrackedWithLfs ( binaryFiles ,  lfsTrackedFiles ) ; 
10290
10391            var  result  =  new  List < IIssue > ( ) ; 
10492            foreach  ( var  file  in  binaryFilesNotTrackedByLfs ) 
@@ -137,22 +125,23 @@ private IEnumerable<IIssue> CheckForBinaryFilesNotTrackedByLfs(IssueCommentForma
137125        /// <returns>List of files in the repository.</returns> 
138126        private  IEnumerable < string >  GetAllFilesFromRepository ( ) 
139127        { 
128+             this . Log . Verbose ( "Reading all files from repository '{0}'..." ,  this . Settings . RepositoryRoot ) ; 
129+ 
140130            var  settings  =  new  GitRunnerSettings 
141131            { 
142132                WorkingDirectory  =  this . Settings . RepositoryRoot , 
143133            } ; 
144134
145-             this . Log . Information ( "Reading all files from repository '{0}'..." ,  this . Settings . RepositoryRoot ) ; 
146135            settings . Arguments . Clear ( ) ; 
147-             settings . Arguments . Add ( "ls-files" ) ; 
148-             var  allFiles  =  this . runner . RunCommand ( settings ) ; 
136+             settings . Arguments . Add ( "ls-files -z " ) ; 
137+             var  allFiles  =  string . Join ( string . Empty ,   this . runner . RunCommand ( settings ) ) . Split ( ' \0 ' ) . Where ( x  =>   ! string . IsNullOrEmpty ( x ) ) ; 
149138
150139            if  ( allFiles  ==  null ) 
151140            { 
152141                throw  new  Exception ( "Error reading files from repository" ) ; 
153142            } 
154143
155-             this . Log . Information ( "Found {0} file(s)" ,  allFiles . Count ( ) ) ; 
144+             this . Log . Verbose ( "Found {0} file(s)" ,  allFiles . Count ( ) ) ; 
156145
157146            return  allFiles ; 
158147        } 
@@ -163,12 +152,13 @@ private IEnumerable<string> GetAllFilesFromRepository()
163152        /// <returns>List of text files in the repository.</returns> 
164153        private  IEnumerable < string >  GetTextFilesFromRepository ( ) 
165154        { 
155+             this . Log . Verbose ( "Reading all text files from repository '{0}'..." ,  this . Settings . RepositoryRoot ) ; 
156+ 
166157            var  settings  =  new  GitRunnerSettings 
167158            { 
168159                WorkingDirectory  =  this . Settings . RepositoryRoot , 
169160            } ; 
170161
171-             this . Log . Information ( "Reading all text files from repository '{0}'..." ,  this . Settings . RepositoryRoot ) ; 
172162            settings . Arguments . Clear ( ) ; 
173163            settings . Arguments . Add ( "grep -Il ." ) ; 
174164            var  textFiles  =  this . runner . RunCommand ( settings ) ; 
@@ -177,7 +167,7 @@ private IEnumerable<string> GetTextFilesFromRepository()
177167                throw  new  Exception ( "Error reading text files from repository" ) ; 
178168            } 
179169
180-             this . Log . Information ( "Found {0} text file(s)" ,  textFiles . Count ( ) ) ; 
170+             this . Log . Verbose ( "Found {0} text file(s)" ,  textFiles . Count ( ) ) ; 
181171
182172            return  textFiles ; 
183173        } 
@@ -188,23 +178,68 @@ private IEnumerable<string> GetTextFilesFromRepository()
188178        /// <returns>List of files tracked by Git LFS.</returns> 
189179        private  IEnumerable < string >  GetLfsTrackedFilesFromRepository ( ) 
190180        { 
181+             this . Log . Verbose ( "Reading all LFS tracked files from repository '{0}'..." ,  this . Settings . RepositoryRoot ) ; 
182+ 
191183            var  settings  =  new  GitRunnerSettings 
192184            { 
193185                WorkingDirectory  =  this . Settings . RepositoryRoot , 
194186            } ; 
195187
196-             this . Log . Information ( "Reading all LFS tracked files from repository '{0}'..." ,  this . Settings . RepositoryRoot ) ; 
197188            settings . Arguments . Clear ( ) ; 
198-             settings . Arguments . Add ( "lfs ls-files" ) ; 
189+             settings . Arguments . Add ( "lfs ls-files -n " ) ; 
199190            var  lfsTrackedFiles  =  this . runner . RunCommand ( settings ) ; 
200191            if  ( lfsTrackedFiles  ==  null ) 
201192            { 
202193                throw  new  Exception ( "Error reading LFS tracked files from repository" ) ; 
203194            } 
204195
205-             this . Log . Information ( "Found {0} LFS tracked file(s)" ,  lfsTrackedFiles . Count ( ) ) ; 
196+             this . Log . Verbose ( "Found {0} LFS tracked file(s)" ,  lfsTrackedFiles . Count ( ) ) ; 
206197
207198            return  lfsTrackedFiles ; 
208199        } 
200+ 
201+         /// <summary> 
202+         /// Determines binary files. 
203+         /// </summary> 
204+         /// <param name="allFiles">List of all files in the repository.</param> 
205+         /// <param name="textFiles">List of text files in the repository.</param> 
206+         /// <returns>List of binary files in the repository.</returns> 
207+         private  IEnumerable < string >  DetermineBinaryFiles ( IEnumerable < string >  allFiles ,  IEnumerable < string >  textFiles ) 
208+         { 
209+             this . Log . Verbose ( "Determine binary files..." ) ; 
210+ 
211+             var  binaryFiles  =  allFiles . Except ( textFiles ) ; 
212+ 
213+             if  ( binaryFiles . Any ( ) ) 
214+             { 
215+                 this . Log . Debug ( string . Join ( Environment . NewLine ,  binaryFiles ) ) ; 
216+             } 
217+ 
218+             this . Log . Verbose ( "Found {0} binary file(s)" ,  binaryFiles . Count ( ) ) ; 
219+ 
220+             return  binaryFiles ; 
221+         } 
222+ 
223+         /// <summary> 
224+         /// Determines binary files which are not tracked with LFS. 
225+         /// </summary> 
226+         /// <param name="binaryFiles">List of binary files in the repository.</param> 
227+         /// <param name="lfsTrackedFiles">List of files tracked with LFS in the repository.</param> 
228+         /// <returns>List of binary files in the repository which are not tracked with LFS.</returns> 
229+         private  IEnumerable < string >  DetermineBinaryFilesNotTrackedWithLfs ( IEnumerable < string >  binaryFiles ,  IEnumerable < string >  lfsTrackedFiles ) 
230+         { 
231+             this . Log . Verbose ( "Checking if binary files are tracked by LFS..." ) ; 
232+ 
233+             var  binaryFilesNotTrackedWithLfs  =  binaryFiles . Except ( lfsTrackedFiles ) ; 
234+ 
235+             if  ( binaryFilesNotTrackedWithLfs . Any ( ) ) 
236+             { 
237+                 this . Log . Debug ( string . Join ( Environment . NewLine ,  binaryFilesNotTrackedWithLfs ) ) ; 
238+             } 
239+ 
240+             this . Log . Verbose ( "Found {0} binary file(s) not tracked by LFS" ,  binaryFilesNotTrackedWithLfs . Count ( ) ) ; 
241+ 
242+             return  binaryFilesNotTrackedWithLfs ; 
243+         } 
209244    } 
210245} 
0 commit comments