2

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)
  |          |
  |          |
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?

2 Answers 2

1

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'.

Sign up to request clarification or add additional context in comments.

9 Comments

Rudi: I looked at that file and it says, I can only modify by doing sudo visudo. However, when I try and execute that : sudo: visudo: command not found. So editing that is something I'm having trouble with. In terms of the git directory structure, do you know why I'm having trouble executing the pull? I mean, the /live/website is a shared repository. I ensured , I made it such by doing git repo-config core.sharedRepository true
Can you su into the root account and run visudo there? On debian visudo is in the sudo package (packages.debian.org/lenny/i386/sudo/filelist) and lives in /usr/sbin/visudo.
As for the /live/website part: Do you have set up the /path/to/staging repo yet? If so the /live/website must be a non-bare repo, since you want the files appearing there. I suggest to move the current /live/website path away and replace it with a regular clone of /live/website.
The files in .git/objects are all 0777, so I'm not sure why is there still a permission error ...
Did you cloned /live/website from a developer account or the webserver account? Does it work when you chown -R webserver-user-account /live/website?
|
1

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"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.