GIT& Ruby:如何在ruby脚本中取消设置GIT_DIR变量?

我写了一个非常简单的“部署”脚本,作为我的
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(非裸)并且我已将我的裸仓库作为遥控器添加到每个(名为
core
),以便
git pull core stage
git pull core live
将从
core
仓库的相应
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
我试过调整这个bash脚本中文件的'更新',这里使用
unset GIT_DIR
来运行下一个git命令
git pull core stage
core
是我在服务器上另一个文件夹中添加的
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
相同的操作? 非常感谢, Jannis     
已邀请:
这看起来像
`cd ~/stage.mydomain.com && unset GIT_DIR && git pull core stage`
可以做这个工作。 推测为什么(推测我不熟悉ruby):你在运行
git pull
的shell中运行
unset
命令(并且在他的回答中指出samold指出,当前工作目录也会出现同样的问题) )。 这表明可能有一些ruby API操纵环境ruby传递给它使用反引号运算符启动的shell,并且还可以更改当前工作目录。     
尝试用这个替换你的行:
ENV['GIT_DIR']=nil
我不确定你的:
`cd ~/stage.mydomain.com`
`unset GIT_DIR` # <= breaks!
`git pull core stage`
即使
GIT_DIR
未正确设置,部分仍然有效;每个反引号都会启动一个与旧shell无关的新shell,子shell无法更改其父进程的当前工作目录。 试试这个:
ENV["GIT_DIR"]=nil
`cd ~/stage.mydomain.com ; git pull core stage`
    

要回复问题请先登录注册