post-update
ベア git リポジトリ内でフックとして実行される非常に単純な「デプロイ」スクリプトを作成しました。
変数は次のとおりです。
live domain = ~/mydomain.com
staging domain = ~/stage.mydomain.com
git repo location = ~/git.mydomain.com/thisrepo.git (bare)
core = ~/git.mydomain.com/thisrepo.git
core == added remote into each live & stage gits
両方ともgit リポジトリ (ベアではない) を初期化しlive
、リポジトリのそれぞれから更新されたファイルをプルするようstage
に、ベア リポジトリをそれぞれにリモートとして追加しました (名前はcore
) 。git pull core stage
git pull core live
branch
core
スクリプトは次のとおりです。
#!/usr/bin/env ruby
# Loop over each passed in argument
ARGV.each do |branch|
# If it matches the stage then 'update' the staging files
if branch == "refs/heads/stage"
puts ""
puts "Looks like the staging branch was updated."
puts "Running a tree checkout now…"
puts ""
`cd ~/stage.mydomain.com`
`unset GIT_DIR` # <= breaks!
`git pull core stage`
puts ""
puts "Tree pull completed on staging branch."
puts ""
# If it's a live site update, update those files
elsif branch == "refs/heads/live"
puts ""
puts "Looks like the live branch was updated."
puts "Running a tree checkout now…"
puts ""
`cd ~/mydomain.com`
`unset GIT_DIR` # <= breaks!
`git pull core live`
puts ""
puts "Tree checkout completed on live branch."
puts ""
end
end
たとえば、次の git コマンドを実行するために使用するこの bash スクリプトからのファイルの「更新」を適応させようとしました。サーバー上の別のフォルダーに私のレポが追加されています。unset GIT_DIR
git pull core stage
core
remote
bare
ただし、上記のスクリプトを実行すると、次のエラーが発生します。
remote: hooks/post-update:35: command not found: unset GIT_DIR
remote: fatal: /usr/lib/git-core/git-pull cannot be used without a working tree.
unset GIT_DIR
Rubyスクリプト内でbashスクリプトと同じことを行う方法はありますか?
どうもありがとう、
ジャニス