In ruby/grit, how do I get a list of files changed

2019-08-10 20:52发布

I want a list of files affected by a certain commit in git. Through the command line, I can do this with:

git show --pretty="format:" --name-only (sha)

But how can I do this through Grit in Ruby?

2条回答
老娘就宠你
2楼-- · 2019-08-10 21:15

You can use your_commit.diffs which returns an array of Grit::Diff instances. Grit::Diff has a_path and b_path properties.

Some (untested) example code:

paths = [];
@commit.diffs.each do |diff|
    paths += [diff.a_path, diff.b_path]
end
paths.uniq!
查看更多
疯言疯语
3楼-- · 2019-08-10 21:17

Since Grit's git module employs method_missing to shell out, you can also try:

grit.git.show({ :pretty => :format, :name_only => true}, sha)

查看更多
登录 后发表回答