开发者

GIT post-receive hook not checking out submodules

开发者 https://www.devze.com 2023-03-11 18:22 出处:网络
I 开发者_如何学编程have been working on a Kohana 3 project that I installed using the downloaded zip file awhile ago. I have a git repository on my remote server \"project.git\" which checks out the l

I 开发者_如何学编程have been working on a Kohana 3 project that I installed using the downloaded zip file awhile ago. I have a git repository on my remote server "project.git" which checks out the latest commits to the working directory "public_html" where I test the application

My post-receive hook file

GIT_WORK_TREE=/var/www/public_html;
git checkout -f;

which was working for a couple of months until I decided to remove some kohana folders and use git submodule instead, so I can do updates via git.

Now the problem is that the submodules are not in the working directory. I tried going in there to add the submodules but the "public_html" directory isn't a repository. In the "project.git" directory, git commands throw an error that I must perform them in the working directory.

How do I modify my hook to checkout submodules when I do a commit?

Update

As per @manojlds's suggestion: I added it to the hook and now it looks like this:

GIT_WORK_TREE=/var/www/public_html;
git submodule init;
git submodule update; 
git checkout -f;

But I get this message,

remote: You need to run this command from the Top level of the working tree

and no changes to the submodules in

public_html


You have to add the following (appropriately using the GIT_WORK_TREE environment varible):

git submodule init
git submodule update

so that you can get the contents of the submodules on the remote server and then copy them to public_html

The below is the full post-receive hook ( modified to support proper functioning of the submodules) :

#!/bin/sh
unset GIT_DIR
git clone /path/to/repo /tmp/public_html
cd /tmp/public_html
git submodule init
git submodule update
cp -R /tmp/public_html /var/www/
rm -rf /tmp/public_html
rm -rf /var/www/public_html/.git


This is my post-receive hook: Replace WORK_DIR with a location where you want to checkout to. This is a main web directory in my case. It is initialized as a git repository and simply pulls from the git bare repository this hooks runs in. This solves both the checkout speed (git is much faster in checking out than cp -R from the other answer is) and also keeps submodules properly synced.

#!/bin/sh
unset GIT_DIR
echo "Checking out"
(cd $WORK_DIR && git pull --recurse-submodules=yes --force)
echo "Submodule update..."
(cd $WORK_DIR && git --work-tree="$WORK_DIR" submodule update --init --recursive --force)
0

精彩评论

暂无评论...
验证码 换一张
取 消