开发者

git hook permission problem

开发者 https://www.devze.com 2023-01-29 09:16 出处:网络
I\'ve set my git working structure as follows (thanks to a recommendation in another question git : Small project work)

I've set my git working structure as follows (thanks to a recommendation in another question git : Small project work)

 /live/website
       |
       |
/path/to/staging (bare)
  |          |
  |          |开发者_如何学Python
dev1        dev2

Currently, both dev1 and dev2, push the projects to the /path/to/staging repo. I have a hook in /path/to/staging, that automatically triggers a git pull from my /live/website. This way, I have a working copy of files there.

Also /path/to/staging (bare) was initialized with share=0777, so I know for a fact the share is not a problem. Also, I've CHMODded all files to 777 and set the stick bit as well.

I've created the /live/website repo as user : root. However, I've created the repo in dev1 as user : dev1. I can make changes in dev1 fine, however when I try to push the repo from dev1, here's the problem I face:

error: Couldn't set refs/remotes/origin/master
From /path/to/staging
 ! 8b4fddc2 .. e2a0b21  master     -> origin/master  (unable to update local ref)
To path/to/staging
   8c5fddc2  .. e2a0b21 master -> master

And basically, I don't see the files transfer successfully to /live/website. I think this problem arises since I'm executing the code as user : dev1. However, when I browse to /live/website and do a git pull manually as user : root, it does successfully pull the changes made by dev1 and changes the working file.

Can someone recommend if there is a way to work around this problem? Since it beats the purpose of the automatic hook ...

Something else that I thought of doing was in the hook, I was thinking of changing the user:

su root
password

However, when it executes, I don't think I'm entering the password at the prompt, since the error message I receive is :

hooks/post-receive: line 18: password: command not found

EDIT ,

Also, can someone suggest a way to go back from a push? And get the previous state of files?


AFAIK you can't give su a password on the command line. But you can use sudo, add the permitted user into /etc/sudoers with no password, so you can run your command as sudo -u webside-user-name 'cd /live/website && git fetch && git checkout master'.


I am using a similar workflow and I don't even have root access on the live webserver and it still works fine. Here's the script I'm using (it's a post-receive hook; I suppose it could be a post-update hook instead but I haven't tested that):

#!/bin/sh
# To enable this hook, make this file executable by "chmod +x post-receive".
GIT_WORK_TREE=/path/to/htdocs git checkout -f

Then you can test the hook by running hooks/post-receive. If it works when you test it manually, it should work when you run "git push"

0

精彩评论

暂无评论...
验证码 换一张
取 消