2

I have a php webapp controlled by mercurial. It's in /var/www/directory/. The files are owned by user and group 'www-data'. After I pull some changes, the files become owned by root.root.

That's because the hg is run by root? it's a remote server and I have only root access, how to fix this? I don't want to run chown manually and recursively in the directories after every pull, also because there are some subdirs which can't belong to www-data .

Don't know if I'm doing right, tried to modify the hgrc with

[trusted]
users = www-data
groups = www-data

didn't work

Kreker
  • 2,438
  • 3
  • 23
  • 27
  • Can't you create another user and run hg as that? – Ringding Mar 21 '14 at 07:46
  • and what's the purpouse? If I use a new user, the files will be owned by the new user. Still got the problem. And how to run hg as the user? Maybe I don't understand. Explain me please – Kreker Mar 21 '14 at 08:17
  • I have no idea what you are trying to achieve or how it is that you run hg as root. – Ringding Mar 21 '14 at 12:03
  • cause it's a remote rent server and I have only root access. So when I run hg pull or hg update I'm root, and I don't want that the new file from the commit result owned by root because apache can't get file owned by root, only www-data or som other user inside this group. Root of course isn't in it – Kreker Mar 21 '14 at 13:23
  • Which is the best way to use and install mercurial in dev environment? – Kreker Mar 21 '14 at 16:09

1 Answers1

2

A new file created by root when root is running hg are going to be owned by root. You can use the sticky group bit to set the group, but you're stuck with root as the user.

You can probably put a hook in the repo's .hg/hgrc pretty easily. Something like:

[hooks]
post-pull = chown -R user:www-data .hg

You said there are some directories you want to exclude, but you can do that in a hook too.

Ry4an Brase
  • 78,112
  • 7
  • 148
  • 169
  • Ok I defined 2 hookw, one for the whole tree and one for the different directory. But after the update, not the pull. I call them post-update.whole and post-update.otherdir and chowning the whole directory not .hg. thanks – Kreker Mar 27 '14 at 14:01
  • 1
    Ah, I didn't see you were talking about the working directory files. Most people run into these problems when they're pushing as user X and then can't pull as user Y, which is what ownership in .hg is about. You're right that if it's workign files you're interested in then `post-update` is your guy. – Ry4an Brase Mar 27 '14 at 14:06