Why is my git hook not working after receiving

I have an Amazon EC2 instance that runs linux and has git. I am setting up a git repository using the following command.

git init --bare

      

Then I cd into the hooks directory and created a file after receiving which has the following bash script.

#!/bin/sh
GIT_WORK_TREE=/var/www/mysite
export GIT_WORK_TREE
git checkout -f

      

when i log out of my local repo to the server everything seems to be going well. I tested this by adding a new myfile.html to my project and pushing to the server. I have no errors. However, when I connect to the / var / www / mysite directory, I don't see the new file I added, but if I clone the remote repo into a new directory locally, I get all the changes I pushed to the server.

My thought is that changes are tracked with git only ok, but when running post-receive there might be some kind of permissions issue so that files aren't moved around and applied to my / var / www / mysite directory?

Hoping that someone can shed some light on what could happen and how it can be done.

=========================================

So basically, the file after being received needs the following permissions to execute it.

chmod +x post-receive 

      

After doing this, I now have a real permissions issue where I tell git to move files when they are clicked and the post fetch starts.

I am guessing that post-receive is trying to move files to the / var / www / mysite folder as I ask, but now it gives me fail access when I try to move and modify files.

I tried adding sudo to my post-receive script how to do it

    #!/bin/sh
    sudo GIT_WORK_TREE=/var/www/mysite
    export GIT_WORK_TREE
    sudo git checkout -f

      

which gave me the following error when I pushed the code.

remote: usage: sudo [-D level] -h | -K | -k | -V
remote: usage: sudo -v [-AknS] [-D level] [-g groupname|#gid] [-p prompt] [-u user
remote:             name|#uid]
remote: usage: sudo -l[l] [-AknS] [-D level] [-g groupname|#gid] [-p prompt] [-U user
remote:             name] [-u user name|#uid] [-g groupname|#gid] [command]
remote: usage: sudo [-AbEHknPS] [-r role] [-t type] [-C fd] [-D level] [-g
remote:             groupname|#gid] [-p prompt] [-u user name|#uid] [-g groupname|#gid]
remote:             [VAR=value] [-i|-s] [<command>]
remote: usage: sudo -e [-AknS] [-r role] [-t type] [-C fd] [-D level] [-g
remote:             groupname|#gid] [-p prompt] [-u user name|#uid] file ...
remote: fatal: This operation must be run in a work tree

      

+3


source to share





All Articles