簡體   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