@@ -143,15 +143,19 @@ private List<Commit> GetCommitsWithFollow(string filePath, CancellationToken can
143143 return new List < Commit > ( ) ;
144144 }
145145
146- var commitLines = result . StandardOutput
147- . Split ( new [ ] { '\n ' , '\r ' } , StringSplitOptions . RemoveEmptyEntries )
148- . ToArray ( ) ;
146+ return ParseGitLogWithNameStatus ( result . StandardOutput , filePath , cancellationToken ) ;
147+ }
148+
149+ private List < Commit > ParseGitLogWithNameStatus ( string gitLogOutput , string originalFilePath , CancellationToken cancellationToken )
150+ {
151+ var commitLines = gitLogOutput . Split ( new [ ] { '\n ' , '\r ' } , StringSplitOptions . RemoveEmptyEntries )
152+ . ToArray ( ) ;
149153
150154 var commits = new List < Commit > ( ) ;
151155 var processedCommits = new HashSet < string > ( ) ; // Track processed commits to avoid duplicates
152156 string ? currentCommitHash = null ;
153157 string ? currentFilePath = null ;
154- string ? previousFilePath = filePath ;
158+ string ? previousFilePath = originalFilePath ;
155159
156160 foreach ( var line in commitLines )
157161 {
@@ -371,26 +375,43 @@ public List<Commit> GetGitCommitsByDate(DateTime? startDate, DateTime? endDate,
371375 var filePathArg = string . IsNullOrEmpty ( filePath ) ? string . Empty : $ "-- { FormatFilePathForGit ( filePath ) } ";
372376 var startDateArg = startDate . HasValue ? $ "--since=\" { startDate . Value : yyyy-MM-dd} \" " : string . Empty ;
373377 var endDateArg = endDate . HasValue ? $ "--until=\" { endDate . Value : yyyy-MM-dd} \" " : string . Empty ;
374- var arguments = $ "log --pretty=format:%H { startDateArg } { endDateArg } { filePathArg } ". Trim ( ) ;
375378
376- var result = RunGitCommand ( arguments , null , cancellationToken ) ;
377- if ( result == null || result . ExitCode != 0 )
379+ if ( _follow && ! string . IsNullOrEmpty ( filePath ) )
378380 {
379- _logger ? . WriteLine ( $ "Error retrieving git commits: { result ? . StandardError } ") ;
380- return new List < Commit > ( ) ;
381+ // When following file renames, we need to use --name-status to track the file path changes
382+ var arguments = $ "log --name-status --pretty=format:%H --follow { startDateArg } { endDateArg } { filePathArg } ". Trim ( ) ;
383+ var result = RunGitCommand ( arguments , null , cancellationToken ) ;
384+ if ( result == null || result . ExitCode != 0 )
385+ {
386+ _logger ? . WriteLine ( $ "Error retrieving git commits: { result ? . StandardError } ") ;
387+ return new List < Commit > ( ) ;
388+ }
389+
390+ return ParseGitLogWithNameStatus ( result . StandardOutput , filePath , cancellationToken ) ;
381391 }
392+ else
393+ {
394+ // When not following renames, use the simpler log command
395+ var arguments = $ "log --pretty=format:%H { startDateArg } { endDateArg } { filePathArg } ". Trim ( ) ;
396+ var result = RunGitCommand ( arguments , null , cancellationToken ) ;
397+ if ( result == null || result . ExitCode != 0 )
398+ {
399+ _logger ? . WriteLine ( $ "Error retrieving git commits: { result ? . StandardError } ") ;
400+ return new List < Commit > ( ) ;
401+ }
382402
383- var commits = result . StandardOutput
384- . Split ( new [ ] { '\n ' , '\r ' } , StringSplitOptions . RemoveEmptyEntries )
385- . Select ( x => new Commit ( x , filePath ) )
386- . ToList ( ) ;
403+ var commits = result . StandardOutput
404+ . Split ( new [ ] { '\n ' , '\r ' } , StringSplitOptions . RemoveEmptyEntries )
405+ . Select ( x => new Commit ( x , filePath ) )
406+ . ToList ( ) ;
387407
388- if ( ! commits . Any ( ) )
389- {
390- _logger ? . WriteLine ( $ "No commits found between { startDate ? . ToString ( "yyyy-MM-dd" ) ?? "repository start" } and { endDate ? . ToString ( "yyyy-MM-dd" ) ?? "repository end" } ") ;
391- }
408+ if ( ! commits . Any ( ) )
409+ {
410+ _logger ? . WriteLine ( $ "No commits found between { startDate ? . ToString ( "yyyy-MM-dd" ) ?? "repository start" } and { endDate ? . ToString ( "yyyy-MM-dd" ) ?? "repository end" } ") ;
411+ }
392412
393- return commits ;
413+ return commits ;
414+ }
394415 }
395416
396417 private void EnsureRepositoryInitialized ( )
0 commit comments