5

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 stagegit pull core livebranchcore

スクリプトは次のとおりです。

#!/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_DIRgit pull core stagecoreremotebare

ただし、上記のスクリプトを実行すると、次のエラーが発生します。

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_DIRRubyスクリプト内でbashスクリプトと同じことを行う方法はありますか?

どうもありがとう、

ジャニス

4

2 に答える 2

6

これは次のように見えます

`cd ~/stage.mydomain.com && unset GIT_DIR && git pull core stage`

仕事をすることができました。

理由を推測します(私はルビーに慣れていないので推測します):unsetコマンドを実行するシェルとは別のシェルでコマンドを実行していましたgit pull(そして、samoldが彼の回答で指摘しているように、同じ問題が現在の作業ディレクトリで発生します)。

これは、Ruby がバックティック演算子で起動するシェルに渡す環境を操作し、現在の作業ディレクトリを変更する Ruby API が存在する可能性があることを示唆しています。

于 2011-04-02T23:33:15.910 に答える
5

行を次のように置き換えてみてください。

ENV['GIT_DIR']=nil

あなたのことはよくわかりません:

`cd ~/stage.mydomain.com`
`unset GIT_DIR` # <= breaks!
`git pull core stage`

GIT_DIRが適切に設定解除されていても、セクションは機能します。各バッククォートは、古いシェルとは無関係の新しいシェルを開始し、子シェルは親プロセスの現在の作業ディレクトリを変更できません。

これを試して:

ENV["GIT_DIR"]=nil
`cd ~/stage.mydomain.com ; git pull core stage`
于 2011-04-02T23:35:23.043 に答える