问题
New to GIT trying to implement a workflow.
Our local office setup uses a shared Debian Samba disk with Apache, Linux, etc. We therefore clone projects from a "local path" of type w:/webs/site.com/site.git
This are BARE repos.
We've created a bash script as a "post-receive" hook located on w:/webs/site.com/site.git/hooks/post-receive wich we thought would be executed by the "linux" git at something like `/home/samba/webs/site.com/hooks... that includes a conditional script depending on the branch commited to checkout similar to:
GIT_WORK_TREE=/home/samba/webs/site.com/html git checkout -f $BRANCH
The problem is that when we PUSH from our tortoiseGIT local copy to the origin branch the hook fails with a:
remote: fatal: Could not switch to 'C:/Program Files (x86)/Git/home/samba/webs/site.com/html': No such file or directory To w:/webs/site.com/site.git
Which we understand means the WORK_TREE or whole hook script is being executed by the clients GIT.
The problem is that we plan to open SSH and other access to the repos, so if we used Windows local paths those would fail when we push from a non Windows local network client. The alternative might be to PULL the repos via SSH even if locally but we feel this is rather inefficient and would only be required for this hook issue.
Any suggestions and/or GIT variables we could use that can be compatible with both? Thanks.
回答1:
The issue is really related to the path for the GIT_WORK_TREE rather than the interpreter itself.
We've now figured that using: GIT_WORK_TREE="../html" works perfectly either from Windows clients accessing via Samba or SSH git pushes via Linux.
Apparently GIT hooks are executed within the repository root directory itself (not the hook directory one) where the .git exists.
Our "other" issues now are related to symlinks... if the push process is done from the Windows client the symlinks appear in the autogenerated (checkout) HTML dir as files instead as like the original symlinks.
We've finally decided for this reason to access the repos via SSH even if local. ;(
来源:https://stackoverflow.com/questions/11636192/how-to-force-git-post-receive-hook-not-to-be-executed-by-the-client