如何使用坚固耐用的`git diff --name-only master`?

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

在 Ruby 中,使用 rugged gem,如何执行以下等价操作?

%x(git diff --name-only master)

我需要列出已暂存或未暂存的已更改文件。

这是我想出的解决方案:

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