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

Preventing NoMethodError at Pronto::Runners#run with exclude config #203

Merged
merged 1 commit into from
Feb 20, 2017
Merged

Preventing NoMethodError at Pronto::Runners#run with exclude config #203

merged 1 commit into from
Feb 20, 2017

Conversation

juno
Copy link
Contributor

@juno juno commented Feb 20, 2017

This PR prevents NoMethodError while running pronto run with exclude config.

How to reproduce

Setup:

[~/src]$ ruby -v
ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-darwin16]

[~/src]$ mkdir test && cd test

[~/src/test]$ vi Gemfile
[~/src/test]$ cat Gemfile
source 'https://rubygems.org'
gem 'rake'
gem 'pronto', '0.8.1'
gem 'pronto-rubocop', '0.8.0'

[~/src/test]$ bundle install --path .bundle

Initialize repo, create branch and add commit:

[~/src/test]$ git init
[~/src/test]$ git add Gemfile*
[~/src/test]$ git commit -m 'first commit'

[~/src/test]$ git checkout -b feature 

[~/src/test]$ echo "puts 'Foo'" > foo.rb
[~/src/test]$ mkdir spec
[~/src/test]$ echo "puts 'Bar'" > spec/bar.rb
[~/src/test]$ git add foo.rb spec/bar.rb
[~/src/test]$ git commit -m 'add foo.rb and spec/bar.rb'

Run with exclude config (NG):

$ vi .pronto.yml
$ cat .pronto.yml
all:
  exclude:
    - 'spec/**/*'

$ bundle exec pronto run
bundler: failed to load command: pronto (/Users/juno/src/test/.bundle/ruby/2.4.0/bin/pronto)
NoMethodError: undefined method `commit' for #<Array:0x007f93977c7798>
  /Users/juno/src/test/.bundle/ruby/2.4.0/gems/pronto-0.8.1/lib/pronto/runners.rb:20:in `block in run'
  /Users/juno/src/test/.bundle/ruby/2.4.0/gems/pronto-0.8.1/lib/pronto/runners.rb:13:in `each'
  /Users/juno/src/test/.bundle/ruby/2.4.0/gems/pronto-0.8.1/lib/pronto/runners.rb:13:in `run'
  /Users/juno/src/test/.bundle/ruby/2.4.0/gems/pronto-0.8.1/lib/pronto.rb:56:in `run'
  /Users/juno/src/test/.bundle/ruby/2.4.0/gems/pronto-0.8.1/lib/pronto/cli.rb:54:in `block in run'
  /Users/juno/src/test/.bundle/ruby/2.4.0/gems/pronto-0.8.1/lib/pronto/cli.rb:53:in `chdir'
  /Users/juno/src/test/.bundle/ruby/2.4.0/gems/pronto-0.8.1/lib/pronto/cli.rb:53:in `run'
  /Users/juno/src/test/.bundle/ruby/2.4.0/gems/thor-0.19.4/lib/thor/command.rb:27:in `run'
  /Users/juno/src/test/.bundle/ruby/2.4.0/gems/thor-0.19.4/lib/thor/invocation.rb:126:in `invoke_command'
  /Users/juno/src/test/.bundle/ruby/2.4.0/gems/thor-0.19.4/lib/thor.rb:369:in `dispatch'
  /Users/juno/src/test/.bundle/ruby/2.4.0/gems/thor-0.19.4/lib/thor/base.rb:444:in `start'
  /Users/juno/src/test/.bundle/ruby/2.4.0/gems/pronto-0.8.1/bin/pronto:6:in `<top (required)>'
  /Users/juno/src/test/.bundle/ruby/2.4.0/bin/pronto:22:in `load'
  /Users/juno/src/test/.bundle/ruby/2.4.0/bin/pronto:22:in `<top (required)>'

Run without exclude config (OK):

[~/src/test]$ rm .pronto.yml
[~/src/test]$ bundle exec pronto run

Root cause

PR #185 introduced unintentionally return type conversion at Pronto::Runner#reject_excluded.

-    def reject_excluded(patches)
-      return patches unless @config.excluded_files.any?
-      patches.reject! { |patch| excluded?(patch) }
-      patches
-    end
+    def reject_excluded(excluded_files, patches)
+      return patches unless excluded_files.any?
  
-    def excluded?(patch)
-      @config.excluded_files.include?(patch.new_file_full_path.to_s)
+      patches.reject do |patch|
+        excluded_files.include?(patch.new_file_full_path.to_s)
+      end
     end

Since Pronto::Git::Patches does override reject! but reject doesn't, therefore Enumerable#reject has called and the method returns Array instead Pronto::Git::Patches.

Before: Pronto::Runners#reject_excluded returns Array
After:  Pronto::Runners#reject_excluded returns Pronto::Git::Patches
@mmozuras mmozuras merged commit c3f5483 into prontolabs:master Feb 20, 2017
@mmozuras
Copy link
Member

@juno thanks! 🙇

@siebertm
Copy link
Contributor

@mmozuras would you release this as a patch release?

svbergerem added a commit to svbergerem/diaspora that referenced this pull request Mar 2, 2017
Add them again once prontolabs/pronto#203 has been
released.
svbergerem added a commit to svbergerem/diaspora that referenced this pull request Mar 2, 2017
Add them again once prontolabs/pronto#203 has been
released.
svbergerem added a commit to svbergerem/diaspora that referenced this pull request Mar 2, 2017
Add them again once prontolabs/pronto#203 has been
released.
@mmozuras
Copy link
Member

mmozuras commented Mar 3, 2017

@doits @siebertm @svbergerem done, released v0.8.2 a minute ago! 🙇

apiology pushed a commit to apiology/pronto that referenced this pull request Dec 27, 2019
Preventing NoMethodError at `Pronto::Runners#run` with exclude config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants