繁体   English   中英

确定使用Ruby更改了哪些git文件?

[英]Determine which git files have changed using Ruby?

我有一个带有博客条目的Rails应用程序,我想从一个单独的Blog.git存储库中进行更新。

我将工作流程设想为:

  1. 撰写新博客条目
  2. 推送到远程Git仓库
  3. 调用上限deploy:update,它将调用Rake任务以使用任何已更改或新条目更新数据库

困难在于查找哪些文件已更改。 我想利用Git做到这一点,而且我知道我可以在git diff上做一些awk或Perl脚本。

但有更好的方法吗? 我简要看过Grit,但找不到一个好的解决方案。

更新 :事实证明,Grit是解决此问题的最佳方法,至少就我所知。 这是我用来解决问题的方法:

desc 'Posts all entries to database'
task :post_all do
  Dir.chdir REPO do
    Grit::Repo.new('.').tree.contents.each do |file|
      # post_entry cleans up my blog entries and posts them via Post.create()
      post_entry(file.data, :text) unless file.basename =~ /\.gitignore/
    end
  end
end

desc 'Posts all new or changed entries to database'
task :post_new do
  Dir.chdir REPO do
    Grit::Repo.new('.').head.commit.diffs.each do |diff|
      post_entry diff.b_blob.data, :text
    end
  end
end

desc 'Deletes entries from database'
task :remove_all do
  Post.destroy_all
end

desc 'Synchronizes the remote blog repo and the database'
task :sync => [ :remove_all, :post_all ]

数据库真的有必要吗? 查看jekyll宝石。 数百个(甚至数千个)简单博客都在使用它,其中包括两个。

http://github.com/mojombo/jekyll

否则,砂砾是一个很好的解决方案。 我已经将它用于一些事情,并且效果很好。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM