Git post-receive hook acts differently to shell

2019-02-25 16:13发布

I'm trying to setup a git repo on my live server to automatically update a subdomain on receive. Using this guide http://toroid.org/ams/git-website-howto.

hooks/post-receive

#!/bin/sh
pwd
git checkout -f

config

[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        worktree = /var/www/vhosts/domain.com/subdomains/staging/httpdocs
[receive]
        denycurrentbranch = ignore

If I run git checkout -f in /var/git/domain.com.git/ it works, the subdomain is updated. However, when I push I get the following output:

/var/git/domain.com.git
fatal: This operation must be run in a work tree

I'm not sure why this works in the shell, but not in the hook. Can anyone enlighten me?

2条回答
Summer. ? 凉城
2楼-- · 2019-02-25 16:59

add cd /var/www/vhosts/domain.com/subdomains/staging/httpdocs to your post-recieve hook.

查看更多
仙女界的扛把子
3楼-- · 2019-02-25 17:07

The permissions on the worktree do not allow it to be read which causes the fatal: This operation must be run in a work tree error.

查看更多
登录 后发表回答