From 59d86fb63f070934256f51895ba8cfa2a712d3c0 Mon Sep 17 00:00:00 2001 From: rishijain Date: Wed, 11 Oct 2023 19:12:40 +0700 Subject: [PATCH] fix for issue #461 * bug fix * reek fixes * updated changelog --- .reek.yml | 4 ++++ CHANGELOG.md | 1 + lib/rubycritic/source_control_systems/git/churn.rb | 10 ++++++++++ 3 files changed, 15 insertions(+) diff --git a/.reek.yml b/.reek.yml index 2b39fba1..e35fae5a 100644 --- a/.reek.yml +++ b/.reek.yml @@ -145,6 +145,7 @@ detectors: - RubyCritic::SourceControlSystem::Git#head_reference - RubyCritic::SourceControlSystem::Git#revisions_count - RubyCritic::SourceControlSystem::Git#stashes_count + - RubyCritic::SourceControlSystem::Git::Churn#filename_for_subdirectory - RubyCritic::SourceControlSystem::Mercurial#date_of_last_commit - RubyCritic::SourceControlSystem::Mercurial#revisions_count - RubyCritic::ViewHelpers#code_index_path @@ -180,3 +181,6 @@ detectors: exclude: - RubyCritic::Config#self.method_missing - RubyCritic::Config#self.respond_to_missing? + TooManyMethods: + exclude: + - RubyCritic::SourceControlSystem::Git::Churn diff --git a/CHANGELOG.md b/CHANGELOG.md index 529eb58d..0e778d08 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ * [CHANGE] Fix test warning related to `cucumber_opts` declaration (by [@faisal][]) * [BUGFIX] Stop using long-deprecated MiniTest module name, removed in 5.19.0 (by [@faisal][]) * [CHANGE] Disable VERBOSE warnings in test stubs (by [@fbuys][]) +* [BUGFIX] Churn score was always 0 when rubycritic was executed from a sub-directory (by [@rishijain][]) # v4.8.1 / 2023-05-17 [(commits)](https://github.com/whitesmith/rubycritic/compare/v4.8.0...v4.8.1) diff --git a/lib/rubycritic/source_control_systems/git/churn.rb b/lib/rubycritic/source_control_systems/git/churn.rb index 8c77f784..83c84fa1 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