Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 461 - Fix for churn score when accessed from a sub-directory #468

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .reek.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -180,3 +181,6 @@ detectors:
exclude:
- RubyCritic::Config#self.method_missing
- RubyCritic::Config#self.respond_to_missing?
TooManyMethods:
exclude:
- RubyCritic::SourceControlSystem::Git::Churn
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* [CHANGE] Disable VERBOSE warnings in test stubs (by [@fbuys][])
* [CHANGE] Add rexml dependency for Ruby 3.0.0+ support (by [@fbuys][])
* [BUGFIX] Raise error when the same branches are compared (by [@rishijain][])
* [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)

Expand Down
10 changes: 10 additions & 0 deletions lib/rubycritic/source_control_systems/git/churn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading