Skip to content

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

Closed
@glennsarti

Description

@glennsarti

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions