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 377 - Raise error when same branches are compared #471

Merged
merged 1 commit into from
Oct 17, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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] Raise error when the same branches are compared (by [@rishijain][])

# v4.8.1 / 2023-05-17 [(commits)](https://github.com/whitesmith/rubycritic/compare/v4.8.0...v4.8.1)

Expand Down
4 changes: 4 additions & 0 deletions lib/rubycritic/commands/compare.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ def initialize(options)
end

def execute
if Config.send(:base_branch) == Config.send(:feature_branch)
raise('The branch you are on and are comparing with are the same.
Please switch to a different branch or choose a different branch to compare.')
end
compare_branches
status_reporter.score = Config.feature_branch_score
status_reporter
Expand Down
17 changes: 17 additions & 0 deletions test/lib/rubycritic/commands/compare_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@ def abort(str); end
RubyCritic::SourceControlSystem::Git.stubs(:modified_files).returns('test/samples/compare_file.rb')
end

describe 'comparing the branches with the compare option' do
context 'when same branches are compared' do
it 'it aborts with the error message' do
options = ['-b', 'feature_branch']
options = RubyCritic::Cli::Options.new(options).parse.to_h
RubyCritic::Config.set(options)
comparison = RubyCritic::Command::Compare.new(options)

assert_raises('The branch you are on and are comparing with are the same.
Please switch to a different branch or choose a different branch to compare.') do
comparison.execute
end
end
end
end

describe 'comparing the same file for two different branches' do
after do
# clear file contents after tests
Expand Down Expand Up @@ -65,6 +81,7 @@ def abort(str); end
options = ['-b', 'feature_branch', '-t', '0', 'test/samples/compare_file.rb']
options = RubyCritic::Cli::Options.new(options).parse.to_h
RubyCritic::Config.set(options)
RubyCritic::Config.set(base_branch: 'base_branch')
copy_proc = proc do |_|
FileUtils.cp 'test/samples/base_branch_file.rb', 'test/samples/compare_file.rb'
end
Expand Down