0

I am trying to find all the lines of code within the current git diff that have been deleted (in the unstaged changes) using the ruby gem grit, i.e. I want to see all the unstaged changes involving deletions. This would be the equivalent of doing git diff -U0 | grep ^-[^-] in the shell.

So far I have only been able to figure out how to get the diffs between two commits, or get the names of the files that have been changed.

polpetti
  • 787
  • 7
  • 21

1 Answers1

1

Try as follows:

diff = @repo.git.diff({:U0 => true}).split( "\n" ).grep( /^-[^-]/ ).join( "\n" )
Малъ Скрылевъ
  • 16,187
  • 5
  • 56
  • 69
  • Not bad. I guess this answers the question in that getting a negative changes only or positive changes only diff with Grit is not possible in any particularly unique way...just by translating the shell into ruby – polpetti Feb 02 '14 at 13:44
  • @IlyaKavalerov Grit is not fully covered the git calls, show call like this, can be done only by using native call to git. – Малъ Скрылевъ Feb 03 '14 at 08:20