How to `git diff --name-only master` with rugged?

335 views Asked by At

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.

1

There are 1 answers

0
jwfearn On BEST ANSWER

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")