【发布时间】:2011-07-28 10:42:01
【问题描述】:
我编写了一个非常简单的“部署”脚本,作为我的 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
live 和 stage 都已初始化 git repos(非裸),我已将我的裸 repo 添加为它们每个的远程(命名为 core),以便 git pull core stage 或 git pull core live从core repo 的相应branch 中提取更新的文件。
脚本如下:
#!/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
我已经尝试从 this bash script here 调整文件的“更新”,它使用 unset GIT_DIR 运行下一个 git 命令 git pull core stage 例如。 core 是我的bare 存储库在服务器上不同文件夹中添加的remote。
但是在执行上面的脚本时,我遇到了以下错误:
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.
有没有办法在我的 ruby 脚本中的 bash 脚本中执行与 unset GIT_DIR 相同的操作?
非常感谢,
詹尼斯
【问题讨论】:
标签: ruby git shell variables unset