我编写了一个非常简单的“部署”脚本,post-update
在我的裸 git repo 中作为我的钩子运行。
变量如下
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
两者live
&stage
都初始化了 git repos(非裸),并且我已将我的裸 repo 作为远程添加到它们中的每一个(命名core
),以便git pull core stage
或git pull core live
将从各自branch
的core
repo 中提取更新的文件。
脚本如下:
#!/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
我已经尝试从这个 bash 脚本中调整文件的“更新”,例如,它使用unset GIT_DIR
来运行下一个 git 命令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 脚本相同的事情?
非常感谢,
詹尼斯