rubocop-git icon indicating copy to clipboard operation
rubocop-git copied to clipboard

Raises error when git configuration `diff.mnemonicprefix` is enabled

Open dsbonev opened this issue 8 years ago • 4 comments

Output is

.gem/ruby/2.1.2/gems/rubocop-git-0.1.1/lib/rubocop/git/diff_parser.rb:24:in `block in parse': undefined method `patch' for nil:NilClass (NoMethodError)

The following regex does not match the patched file name

[1] pry(main)> '+++ i/test.rb' =~ %r{^\+{3} b/(?<path>[^\t\n\r]+)} 
=> nil

It has i/ prefix instead of b/ because I have diff.mnemonicprefix enabled.

To fix this I would suggest either (1) handle the mnemonic prefixes as well or (2) pass configuration option when this gem executes the git diff command git -c diff.mnemonicprefix=false.

dsbonev avatar Jun 29 '16 08:06 dsbonev

@dsbonev Thanks for the idea about how to work around this issue. 👍

Just to save others a bit of time... the line https://github.com/m4i/rubocop-git/blob/8d6d002390427fe7fe8f425e5ccf8855ff62cebb/lib/rubocop/git/runner.rb#L36 needs to be changed to this: args = %w(-c diff.mnemonicprefix=false diff --diff-filter=AMCR --find-renames --find-copies)

gerrywastaken avatar Jul 28 '16 15:07 gerrywastaken

@m4i Looks like #32 provides a solution for this and the --no-color issue. Can we get it merged in? This would have saved me a world of hurt getting the gem to work.

collin-mcgrath avatar Jan 22 '18 18:01 collin-mcgrath

if anyone is still using this, i've release a forked gem, rubocop-git2, with this and other fixes included

jaynetics avatar Mar 24 '23 21:03 jaynetics

@jaynetics Why not link it: jaynetics/rubocop-git2. Also, updating the readme with usage info and screenshots would probably lead to this getting a lot more use.

gerrywastaken avatar Mar 24 '23 22:03 gerrywastaken