git submodule update in post-receive hook ignores -C
Asked Answered
M

0

1

I try to write a post-receive hook to build a static webpage, but the git submodule update --init command fails. The script runs successfully when not run by the hook.


OUTPUT=$HOME/post_receive_out

REPO=$HOME/repositories/personal/www_root.git
WORKING_DIR=$HOME/hugo_web_temp
WWW_DIR=/var/www/servers/levente.logonex.eu/pages

echo -ne "This is the post receive hook. I am " > $OUTPUT

whoami >> $OUTPUT

rm -rf $WORKING_DIR
git clone $REPO $WORKING_DIR
git -C $WORKING_DIR submodule update --init

hugo -s $WORKING_DIR/lev -d $WWW_DIR
chmod -R a+r $WWW_DIR

says:

fatal: not a git repository: '.'

For now I fixed it with this:

cd  $WORKING_DIR
git --git-dir $WORKING_DIR/.git --work-tree $WORKING_DIR submodule update --init

found in Git submodule update from post-receive hook

Minify answered 28/8, 2020 at 16:0 Comment(3)
What version of Git are you using on that server?Flower
@VonC, I'm using git version 2.20.1 from Debian stable.Minify
OK so above the 1.8.5 (https://mcmap.net/q/12539/-git-pull-while-not-in-a-git-directory) required to use -CFlower

© 2022 - 2024 — McMap. All rights reserved.