In Ruby, using the rugged gem, how does one do the equivalent of the following?
%x(git diff --name-only master)
I need to list changed files that are either staged or unstaged.
Here's the solution I came up with:
files0 = %x(git diff --name-only master).split($RS)
require 'rugged'
files1 = []
changed = %i(index_modified index_new worktree_modified worktree_new)
repo = Rugged::Repository.new(Dir.pwd)
repo.status { |f, d| files1 << f unless (changed & d).empty? }
puts(files0.sort == files1.sort ? "PASS" : "FAIL")