Git post hook does not fire external script

Here is what I have done so far:

  • I have a server hosting websites and their git repositories.
  • I have a user named git who owns all the repositories and has the ability to log in like any user without entering a password.
  • I created a hook called post-receive in the hooks directory on my repo.
  • I also created a script called gitpull that automatically uploads information to sites.

Everything is OK when I type this command:

 su - git -c "/git/sitename.git/hooks/post-receive" 

but when I push something from my development machine, it does not run the gitpull script.

Here are my files:

  • /etc/gitpull :

     #!/bin/bash su - $1 -c "cd ~/www;git pull;" 
  • /git/sitename/hooks/post-receive :

     #!/bin/bash /etc/gitpull sitename 

How can i fix this? What am I doing wrong?

+4
source share
1 answer

The post-receive hook must be marked as executable or git will not run it. When you test with sh -c , you bypass the permission check for execution.

I am sure this will work if you run chmod a+x /git/sitename.git/hooks/post-receive .


So what's wrong, huh?

Oh, su asks for a password at startup, right? You cannot provide login for intercepts, so you need to make sure that you can enter /git/sitename.git/hooks/post-receive yourself as your regular user account and run it without any interaction with you.

+1
source

Source: https://habr.com/ru/post/1443457/


All Articles