Can Mercurial be done to preserve file permissions?

I saw several blog posts and experienced for myself that Mercurial does not save permissions on files being dragged from one repo to another. Does anyone know of a Mercurial extension that will save permissions? I assume that this cannot be done with a hook, because what does the hook know about permissions in the original repo?

Requested Development:

  • If the only change in the file is a permission change (for example, chmod o+r filename ), attempts to transfer the file fail with a message that the file has not changed.

  • If I commit a file with permissions of 600 (rw -------), then clone the repo, the same file in the clone has permissions of 664 (rw-rw-r -):

     : nr@yorkie 6522 ; hg clone one two updating working directory 1 files updated, 0 files merged, 0 files removed, 0 files unresolved : nr@yorkie 6523 ; ls -l one two one: total 4 -rw------- 1 nr nr 8 Aug 18 21:50 foo two: total 4 -rw-rw-r-- 1 nr nr 8 Aug 18 21:51 foo 

These examples show that hg clone does not save permissions, but hg push does not save them either.

In my application, one repo is on the public path and it is important that

  • Several users have the right to change repo

  • Files in a public repo become readable only when they are explicitly read.

+43
mercurial file-permissions
Aug 17 '09 at 19:05
source share
4 answers

It seems that this can be done with hooks and an auxiliary tool (and a small chewing gum and a bundling wire):

  • Get David Hardeman Metastore , which saves and restores file metadata.

  • Change the sources so that they ignore the .hg directory as well as the .git .

  • Use the following Mercurial hooks:

      precommit.meta = metastore -s changegroup.update = hg update update.meta = /usr/unsup/nr/bin/metastore -a 

You need to add the .metadata file to the repo.

This lashup will work most of the time, but if you only change the permissions and want to deploy it, you will need to run metastore -s to paste these changes into the .metadata file, where hg will see the change; otherwise, the commit does not consider that there was anything new.

+32
Aug 18 '09 at 2:30
source share

How to use this solution from the Mercurial FAQ :

If you use Mercurial to configure file management, you might want the properties of the tracking file (ownership and permissions). Only Mercurial tracks the executable bit of each file.

Here is an example of how to save properties along with files (works on Linux if you have the acl package installed):

 # cd /etc && getfacl -R . >/tmp/acl.$$ && mv /tmp/acl.$$ .acl # hg commit 

It is far from perfect, but you get the idea. For a more complex solution, check etckeeper.

+15
Oct 05 '09 at 22:48
source share

For a specific case of the / etc directory, etckeeper looks interesting.

+1
Nov 19 '09 at 7:13
source share

It is not recommended to store permissions in VCS. However, Mercurial supports an β€œexecutable” flag (this is not the same as permissions, although some permissions are included in the Unix executable flag).

-one
Aug 17 '09 at 19:08
source share



All Articles