Can Mercurial be made to preserve file permissions?

前端 未结 5 1868
星月不相逢
星月不相逢 2021-01-30 10:19

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

相关标签:
5条回答
  • 2021-01-30 11:00

    I assumed that metastore was abandonware due to the dead git link on author's site so I whipped the below which is placed directly in repo's .hc/hgrc configuration file:

    [paths]
    default = ...
    
    [hooks]
    # NOTE: precommit is different than pre-commit, see https://www.mercurial-scm.org/repo/hg/help/hgrc for list of hooks
    pre-commit  =
            # export permissions
            hg st -camn0 | sort -z | xargs -0 getfacl > .hg.hook.pre-commit.acl.export
            hg add .hg.hook.pre-commit.acl.export
    
            # export timestamps
            hg st -camn0 | sort -z | xargs -0 stat > .hg.hook.pre-commit.stat.export
            hg add .hg.hook.pre-commit.stat.export
    
    update =
            # import permissions
            setfacl --restore=.hg.hook.pre-commit.acl.export
    
            # import timestamps
            # TODO: use touch to restore timestamps
    
    0 讨论(0)
  • 2021-01-30 11:08

    It is not good idea to store permissions in VCS. However, Mercurial supports "executable" flag (that is not the same as permissions, although in Unix executable flag is part of permissions).

    0 讨论(0)
  • 2021-01-30 11:12

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

    0 讨论(0)
  • 2021-01-30 11:18

    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.

    0 讨论(0)
  • 2021-01-30 11:24

    What about using this solution from the Mercurial FAQ:

    If you're using Mercurial for config file management, you might want to track file properties (ownership and permissions) too. Mercurial only tracks the executable bit of each file.

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

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

    This is far from perfect, but you get the idea. For a more sophisticated solution, check out etckeeper.

    0 讨论(0)
提交回复
热议问题