[英]How to halt mina deployment if local and remote git branch differ?
Since mina uses local deployment code, it would be useful if before deployments a check would run ensuring both local branch and origin branch (on github) are in sync. 由于mina使用本地部署代码,因此如果在部署之前进行检查以确保本地分支和Origin分支(在github上)都同步,则将很有用。
So far I have solved this by defining a checker method in deploy.rb 到目前为止,我已经通过在deploy.rb中定义一个检查器方法解决了这个问题
def heads_match?
`git fetch`
if `git diff #{branch} origin/#{branch}`.size < 1
puts "Yay, HEADs match"
return true
else
puts "Noo, Branches are not in sync"
return false
end
end
And calling in the deploy task 并调用部署任务
task :deploy => :environment do
if heads_match?
deploy do
# Rest of deployment code here
end
end
end
The problem is that git fetch
takes several seconds and is probably overhead if I could get by with checking whether last commits of local branch and remote branch are the same. 问题是,
git fetch
需要花费几秒钟的时间,如果我可以检查本地分支和远程分支的最后提交是否相同,则可能会产生开销。
How to check local and remote branch last commit equality quickly? 如何快速检查本地和远程分支的最后一次提交相等性?
You can only check for this using git fetch
, but you do not need to merge the changes if you don't want to. 您只能使用
git fetch
检查,但如果不想,则不需要合并更改。
This answer for a similar question states that the easiest way to do this is by running: 这个问题类似的答案指出,最简单的方法是运行:
git fetch origin
# See if there are any incoming changes
git log HEAD..origin/master --oneline
If you want to do this with other methods, you'll have to hit GitHub with a REST client, in order to check if the last commit matches your local one, but that's a bit of heavy scripting compared to the simple command above and in my opinion git fetch
shouldn't take long in a normal network setup in a repo that doesn't contain large files. 如果要使用其他方法执行此操作,则必须使用REST客户端访问GitHub,以检查上一次提交是否与您的本地提交相匹配,但是与上面和下面的简单命令相比,这有点繁琐我认为
git fetch
在不包含大文件的仓库中的正常网络设置中不应花费很长时间。
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.