Call a script from a git hook

后端 未结 1 1081
臣服心动
臣服心动 2021-01-28 17:21

Let\'s say I have two scripts in server /hooks folder:

First one initiates logging and writes essential information about push: (post-receive)

#!/bin/sh
         


        
相关标签:
1条回答
  • 2021-01-28 18:04

    Exercise: where is . (or $PWD) during the post-receive hook operation?

    When you run it, it's whatever your $PWD is. What about when it's run automatically? (Have a look in the receiving system's bare git repository: your $LOGFILE output will be in that directory.)

    (There's a missing close quote in the hook text in your posting, so presumably you hand-copied some part(s) of the script and perhaps there's something else missing. Also, be sure the hook has execute-permission. But my guess is that you're being bitten by the fact that git runs hooks with $PWD set to the .git directory, not the hook directory.)

    (Side note: your hook is probably incomplete, as it only reads one oldrev newrev refname, but a git push can push many refs. Normally you should loop: while read oldrev newrev refname; do ...; done. If you have a pre-receive hook that rejects pushes that push more than one ref, though, this particular post-receive hook could be correct.)

    0 讨论(0)
提交回复
热议问题