更新後のフックで次のコードを使用する場合、サブモジュールを含めることは可能ですか?
GIT_WORK_TREE=/path/to/directory git checkout -f
更新後のフックからのサブモジュールを含め、コードを配布するために他にどのようなオプションが必要ですか?
ありがとう。
更新後のフックで次のコードを使用する場合、サブモジュールを含めることは可能ですか?
GIT_WORK_TREE=/path/to/directory git checkout -f
更新後のフックからのサブモジュールを含め、コードを配布するために他にどのようなオプションが必要ですか?
ありがとう。
質問 " Using git submodule update --init
on a post hookpost-update
" は、フックでこれを使用した場合に表示される可能性のあるエラー メッセージについて言及しています。
GIT_WORK_TREE=/path/to/directory git submodule update --init
それは次のようになります:
remote: You need to run this command from the toplevel of the working tree.
cd
そのため、ターゲット リポジトリに直接移動し、そこからコマンドを実行するのが最善です。
export GIT_DIR=$(pwd)
cd /path/to/target/workingtree
git checkout -f master
git submodule update --init --recursive
ただし、「裸の作業ディレクトリにプッシュした後、作業ツリーで git サブモジュールを初期化/更新するにはどうすればよいですか?」に示すように:
実行中の「git submodule update」を設定できないように見えます
GIT_WORK_TREE
。
スーパープロジェクトではなく、サブモジュールの作業ツリーとしてこれを使用しようとします。
Aaron Adams によるブログ投稿「Git push with submodules: a how-to guide 」では、 OP iliveinaparkがコメントに示すのと同様のエラー メッセージについて説明しています。
悲しいことに、これは機能しません。私のレポは裸のレポであるためだと思います。
これらのコマンドに従って表示されるエラーは次のとおりです。
fatal: This operation must be run in a work tree
上記のエラーを克服するために、次のようなものを使用する場合:
git --git-dir=<my bare repo> --work-tree=<where I export to> submodule update --init --recursive
私は得る:
fatal: working tree '<where I export to>' already exists. Clone of '<submodule repo>' into submodule path '<submodule path>' failed
上記のブログ投稿では、非ベアリポジトリに基づくアプローチを提案しています (通常、プッシュ先としては推奨されませんが、この場合は必要です)。
まず、レポジトリごとに変更する必要のないユニバーサルな post-receive フックを作成しましょう。
[aaron@aaronadams]$ cat > /usr/local/share/git-core/templates/hooks/post-receive.sample
#!/bin/sh
#
# An example hook script to update the working tree, including its
# submodules, after receiving a push.
#
# This hook requires core.worktree to be explicitly set, and
# receive.denyCurrentBranch to be set to false.
#
# To enable this hook, rename this file to "post-receive".
# Read standard input or hook will fail
while read oldrev newrev refname
do
:
done
# Unset GIT_DIR or the universe will implode
unset GIT_DIR
# Change directory to the working tree; exit on failure
cd `git config --get core.worktree` || exit
# Force checkout
git checkout --force
# Force update submodules
git submodule update --init --recursive --force
[aaron@aaronadams]$ chmod +x /usr/local/share/git-core/templates/hooks/post-receive.sample
さあ、すべてのルールを破りましょう。
に行っていました:
- ウェブサイトのディレクトリで、裸ではない Git リポジトリを初期化します。
- git push から受信できることを確認してください。
- 作業ツリーを親ディレクトリに明示的に設定します。
- 作成したばかりのフックを有効にします。
[aaron@aaronadams]$ cd /var/www/vhosts/aaronadams.ca/sites/staging.aaronadams.ca [aaron@aaronadams]$ git init && git config --bool receive.denyCurrentBranch false && git config --path core.worktree ../ && mv .git/hooks/post-receive.sample .git/hooks/post-receive /var/www/vhosts/aaronadams.ca/sites/staging.aaronadams.ca/.git/ で初期化された空の Git リポジトリ
最後に、ローカル マシンで、新しいリポジトリの場所を反映するようにリモートを変更し、プッシュします。
[aaron@aaronadams]$ git remote set-url staging aaron@aaronadams.ca:sites/staging.aaronadams.ca
[aaron@aaronadams]$ git push staging master
remote: Submodule 'codeigniter' (git://github.com/EllisLab/CodeIgniter.git) registered for path 'codeigniter'
remote: Cloning into 'codeigniter'...
remote: Submodule path 'codeigniter': checked out 'fd24adf31255822d6aa9a5d2dce9010ad2ee4cf0'
To aaron@aaronadams.ca:sites/staging.aaronadams.ca
* [new branch] master -> master
なんてこった、うまくいった!
この方法はサブモジュールと互換性があるだけでなく、新しいリモート リポジトリをセットアップするのに 1 つのコマンドしか必要としません(これは 4 つのコマンドで構成されています)。
また、リポジトリと作業ツリーを同じ場所に保持します。また、構成ファイルやフック ファイルに絶対パスを必要としないため、完全に移植可能になりました。
ただし、OP iliveinaparkは次のよう に言及しています。
ただし、これは少し面倒になりすぎたので、単純な強制チェックアウトを使用し、サブモジュールの更新を手動で管理します。