0
我有一個Rails應用程序,我想從一個單獨的Blog.git回購更新博客條目。確定哪些git文件使用Ruby進行了更改?
我設想我的工作流程是這樣的:
- 寫新博客條目
- 推送到遠程的Git回購
- 呼叫帽部署:更新,這將調用一個Rake任務來更新數據庫任何更改或新條目
這裏的順序是查找哪些文件已更改。我想爲此利用Git,並且我知道我可以在git diff
上執行一些awk或Perl腳本。
但是有沒有更好的方法?我簡單地看了一下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 ]
我開始使用託託(Alexis Sellier),因爲我想要一個簡約的解決方案。不過,我希望能夠隨心所欲地對我的作品進行排序,並且希望將我的所有其他模型與文章相關聯(因爲這只是作爲博客開始 - 它可能會變得更大)。也就是說,我想出了我自己的問題,但是我會給你點,因爲傑基爾只是一件好事(tm)。乾杯。 – 2010-10-12 02:31:54
:)謝謝! ...很高興看到你解決了它。 – 2010-10-12 14:24:10