From c503eb6b47084e3761caab3d5f34f6e3a18ddbd7 Mon Sep 17 00:00:00 2001 From: rishijain Date: Wed, 11 Oct 2023 19:12:40 +0700 Subject: [PATCH] fix for issue #461 --- lib/rubycritic/source_control_systems/git/churn.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/rubycritic/source_control_systems/git/churn.rb b/lib/rubycritic/source_control_systems/git/churn.rb index 8c77f784..0d7000ce 100644 --- a/lib/rubycritic/source_control_systems/git/churn.rb +++ b/lib/rubycritic/source_control_systems/git/churn.rb @@ -73,6 +73,7 @@ def process_line(line) when /^[RC]/ process_rename(*rest) else + rest = filename_for_subdirectory(rest[0]) process_file(*rest) end end @@ -86,6 +87,15 @@ def process_rename(from, to) process_file(to) end + def filename_for_subdirectory(filename) + git_path = Git.git("rev-parse --show-toplevel") + cd_path = Dir.pwd + if cd_path.length > git_path.length + filename = filename.sub(/^#{Regexp.escape(File.basename(cd_path) + '/')}/, '') + end + [filename] + end + def process_file(filename) record_commit(renames.current(filename), @date) end