views:

3046

answers:

7

I am trying to implement a post-commit hook to update a working copy. As far as i can figure out the post commit hook is being runned ( i wrote something in a file to test it out ) but the update command was not runned

At first i did

cd /home/user/working/copy
svn update

but that didn't work, then i read you have to give the full path to svn:

cd /home/user/working/copy
/usr/bin/svn update

but still it failed to work.

I changed permisions to 777 and have runned the script in an empty enviroment ... and it works.

+1  A: 

The working copy is in a user's home directory. If the SVN server runs as a different user, say "svnserver", then the post-commit hook script will run as "svnserver". It makes sense that one user cannot modify or read another user's files unless the permission settings on the files are such that this is allowed.

You should not share working copies among multiple users. If you really must, then simply giving read/write permission to each user is not enough. You would also need to make sure that none of the users create files which are inaccessible to other users. To achieve that you would need to write wrapper scripts for the svn commands that set the proper umask, or give all involved users the ability to act as one specific user through sudo.

Wim Coenen
then how do you recommend to update the working copy ?
solomongaby
Updating a working copy is something that should be initiated by developer who is using that working copy. It should not occur automatically whenever somebody commits. Maybe it would clarify things if you explained why you are trying to automatically keep the working copy up to date.
Wim Coenen
each developer from our team has a working copy on his computer ... and we have a server online that holds the SVN Server, and we wanted to have a dev area on the same server witch will reflect the latest verion from track. This would be used by the project manager to check the latest version.
solomongaby
If only one user is touching the working copy (i.e. the svn server) then your setup should be OK. Just set the permissions on the working copy so that the svn server can update it.
Wim Coenen
sorry to be a pain in the *** but can you tell me how cand i find out the user the subversion server is using ... is it simple svn ?
solomongaby
Use the command "ps -aux | less" to list all processes. If the repository URL starts with svn://, look for svnserve. If it starts with http://, look for apache. Use the '/' search command. There should be a 'username' column in the ps output if I remember it right.
Wim Coenen
+1  A: 

If you do not use the workingcopy by yourself, you can chown the workingcopy to the user which runs the hook-script

Peter Parker
A: 

I believe the post-commit actually is run before the commit is made visible. It's strange, but say you committed revision 30. The post-commit would still see 29 as being the latest revision. Once the post-commit script is done, you'll see 30 as the head revision.

I could be wrong. This is strictly from memory. Something to try at least.

That would be the pre-commit hook.
Wim Coenen
+3  A: 
#!/bin/bash
/usr/bin/svn update /home/user/working/copy

The above code should work as a post-commit hook.

Add --username & --password options if needed.

Edit:

See http://subversion.tigris.org/faq.html#website-auto-update

The server program performing the commit (svnserve or apache) is the same program that will be running the post-commit hook script. That means that this program must have proper permissions to update the working copy.

If the 'working copy' that needs to be updated is owned by the same user, then you need NOT worry about username & password.

The Subversion FAQ suggests using Setuid with the following C program.

#include <stddef.h>
#include <stdlib.h>
#include <unistd.h>
int main(void)
{
execl("/usr/local/bin/svn", "svn", "update", "/home/joe/public_html/",
    (const char *) NULL);
return(EXIT_FAILURE);
}
StackKrish
aren't the username and password already stored from when i did the checkout ?
solomongaby
I have edited my original response to add more details.
StackKrish
A: 

the final solution that i got working was a mix some of the answers i got. My server had apache running as nobody, so i made the working copy be owned by nobody and in the group UserName and then chmod it to 775. This way the hook will work and also the username will also have permision to update files by FTP.

solomongaby
A: 

wcoenen's answer is definitely on the right track. The easiest way to get around this problem would be to add the SVN user to your group. Let's say your post-commit hook is owned by user someUser and group someUser. Adding the SVN server to the someUser group, and chmodding your post-commit hook script to be group-executable, would solve your problem.

I hope that made sense :P

KOGI
A: 

This script is better because it updates only required files... http://vidax.net/blog/en/2010/03/subversion-post-commit-hook/

Aquel