Skip to content

Diff fails with NoMethodError: undefined method '[]' for nil:NilClass when line ending warnings are emitted #326

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

Closed
glennsarti opened this issue Feb 22, 2017 · 4 comments

Comments

@glennsarti
Copy link

glennsarti commented Feb 22, 2017

Repro case:

  • Download a repository which contains a file with CRLF endings on an operating system that uses LF endings
  • Extracting the diff will throw a NoMethodError: undefined method '[]' for nil:NilClass error in method process_full_diff

Example output;

Overriding any local changes to repositories in modules
Not managing Rakefile in puppetlabs-chocolatey
Not managing spec/spec_helper.rb in puppetlabs-chocolatey
Using no-op. Files in puppetlabs-chocolatey may be changed but will not be committed.
Files changed:
Error while updating puppetlabs-chocolatey
bundler: failed to load command: msync (/mnt/c/Source/modulesync_configs/.bundle/bash/ruby/2.3.0/bin/msync)
NoMethodError: undefined method `[]' for nil:NilClass
  /mnt/c/Source/modulesync_configs/.bundle/bash/ruby/2.3.0/gems/git-1.3.0/lib/git/diff.rb:151:in `block in process_full_diff'
  /mnt/c/Source/modulesync_configs/.bundle/bash/ruby/2.3.0/gems/git-1.3.0/lib/git/diff.rb:134:in `each'
  /mnt/c/Source/modulesync_configs/.bundle/bash/ruby/2.3.0/gems/git-1.3.0/lib/git/diff.rb:134:in `process_full_diff'
  /mnt/c/Source/modulesync_configs/.bundle/bash/ruby/2.3.0/gems/git-1.3.0/lib/git/diff.rb:109:in `process_full'
  /mnt/c/Source/modulesync_configs/.bundle/bash/ruby/2.3.0/gems/git-1.3.0/lib/git/diff.rb:68:in `each'
  /mnt/c/Source/modulesync_configs/.bundle/bash/ruby/2.3.0/bundler/gems/modulesync-899483f48304/lib/modulesync/git.rb:162:in `update_noop'
  /mnt/c/Source/modulesync_configs/.bundle/bash/ruby/2.3.0/bundler/gems/modulesync-899483f48304/lib/modulesync.rb:114:in `manage_module'
  /mnt/c/Source/modulesync_configs/.bundle/bash/ruby/2.3.0/bundler/gems/modulesync-899483f48304/lib/modulesync.rb:133:in `block in update'

The reason it fails because the code at; https://github.com/schacon/ruby-git/blob/master/lib/git/diff.rb#L139-L151 expects the first line to contain the filename whereas raw diff comes back as;

warning: CRLF will be replaced by LF in examples/init.pp.
The file will have its original line endings in your working directory.
diff --git a/.gitattributes b/.gitattributes
index 900ea0c..02d4646 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1,5 +1,5 @@
 #This file is generated by ModuleSync, do not edit.

Suggested fix:

I suggest the line at https://github.com/schacon/ruby-git/blob/master/lib/git/diff.rb#L138 be changed from else to elsif !current_file.nil? so that it won't process diff text until a valid filename is detected

@glennsarti glennsarti changed the title Diff fails with NoMethodError: undefined method []' for nil:NilClass` when line ending warnings are emitted Diff fails with NoMethodError: undefined method '[]' for nil:NilClass when line ending warnings are emitted Feb 22, 2017
@glennsarti
Copy link
Author

May be related to #326

@stale
Copy link

stale bot commented Apr 1, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Apr 1, 2018
@stale stale bot closed this as completed Apr 9, 2018
@ekohl
Copy link

ekohl commented May 27, 2018

Given we still have a monkey patch in voxpupuli's modulesync I think this isn't resolved and should be reopened.

@neomilium
Copy link

Seems to be fixed with PR #405.

neomilium added a commit to opus-codium/modulesync that referenced this issue Dec 20, 2020
According to ruby-git/ruby-git#405, it seems to close the issue reported at ruby-git/ruby-git#326.

This have been merged then released in 1.7.0.

It finally removes the deprecation warning:
lib/monkey_patches.rb:13: warning: Using the last argument as keyword parameters is deprecated
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

No branches or pull requests

3 participants