Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Mercurial be made to preserve file permissions?

I've seen a number of blog posts, and have experienced for myself, that Mercurial does not preserve the permissions on files pushed from one repo to another. Does anyone know of a Mercurial extension that would preserve the permissions? I'm assuming it can't be done with a hook, because what does a hook know about permissions at the originating repo?

Requested elaboration:

  • If the only change to a file is a change in permissions (e.g., chmod o+r filename), attempts to commit the file fail with a message saying that the file has not changed.

  • If I commit a file with permissions 600 (rw-------), then clone the repo, the same file in the clone has permissions 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 

This examples shows that hg clone does not preserve permissions, but hg push does not preserve them either.

In my application, one repo is on a publically accessible path, and it's of major importance that

  • Multiple users have the right to change the repo

  • Files in the public repo become readable only when explicitly made readable.

like image 822
Norman Ramsey Avatar asked Aug 17 '09 19:08

Norman Ramsey


People also ask

How do you preserve permissions?

Preserve File Permissions Using cp You can use the -p option of cp to preserve the mode, ownership, and timestamps of the file. However, you will need to add the -r option to this command when dealing with directories. It will copy all sub-directories and individual files, keeping their original permissions intact.

How the permission of a file is maintained in the Linux system?

In Linux, to list file permissions, the ls command can be used. The syntax to list the file permission and the group and user who own the file is as follows: ls–lg [filename] To change file permissions in Linux, you usually use the chmod command.

What permission can be set on a file in Linux?

The owner of a file can change the permissions for user ( u ), group ( g ), or others ( o ) by adding ( + ) or subtracting ( - ) the read, write, and execute permissions. There are two basic ways of using chmod to change file permissions: The symbolic method and the absolute form.

How do I set full permissions in Linux?

To change directory permissions for everyone, use “u” for users, “g” for group, “o” for others, and “ugo” or “a” (for all). chmod ugo+rwx foldername to give read, write, and execute to everyone. chmod a=r foldername to give only read permission for everyone.


1 Answers

It looks like it can be done using hooks and an auxiliary tool (and a little chewing gum and baling wire):

  1. Get David Hardeman's Metastore, which saves and restores file metadata.

  2. Alter the sources so it will ignore directory .hg as well as .git.

  3. Use the following Mercurial hooks:

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

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

This lashup will work most of the time, but if you change only permissions and want to propagate it, you'll have to run metastore -s in order to push those changes into the .metadata file where hg will see the change; otherwise the commit thinks nothing is new.

like image 87
Norman Ramsey Avatar answered Sep 20 '22 06:09

Norman Ramsey