Including submodules in git checkout in GIT_WORK_TREE per hook

Is it possible to enable submodules when using the following code in the hook after updating?

GIT_WORK_TREE=/path/to/directory git checkout -f

What other options would I have to distribute the code, including submodules from the hook after the upgrade?

Thank.

+5
source share
1 answer

The question “ Use git submodule update --initin an error message ” mentions an error message that you might see if you used this in your tag post-update:

GIT_WORK_TREE=/path/to/directory git submodule update --init

This will give:

remote: You need to run this command from the toplevel of the working tree.

So it’s better to cddirectly in the target repo and execute a command from there:

export GIT_DIR=$(pwd)

cd /path/to/target/workingtree

git checkout -f master
git submodule update --init --recursive

, " / git ?:

, git GIT_WORK_TREE:
, .

" Git push : " , 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

, , , - ( , ):

git :

-, 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
Initialized empty Git repository in /var/www/vhosts/aaronadams.ca/sites/staging.aaronadams.ca/.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

, !

, (, , ).
; , , .


OP iliveinapark , :

, .

+10

All Articles