thkala
thkala

Reputation: 86443

Creating and using a Mercurial repository for system files

I've been using Mercurial successfully for my programming projects for quite some time, so it was a logical step to let it handle the rest of my versioning needs as well. The first step in this direction would be to have Mercurial handle the configuration files that I modify manually on my Linux system. Unfortunately, I seem to have hit a few snags here:

  1. Mercurial does not store file metadata (ownership, permissions, extended attributes).

  2. Mercurial will not handle files that do not reside in the repository directory.

I believe that I have found a solution for (1), although it apparently involves modifying the source of a separate utility and a bit of hgrc magic.

The second point seems trickier: I do not want to place a Mercurial repository at the filesystem root (/), for a variety of reasons. Unfortunately - for what is admittedly a very good reason - Mercurial will not handle files that reside outside the repository root, either directly or through symbolic links.

I could probably write a wrapper script that would use e.g. mount --bind or unionfs to allow Mercurial to access the root filesystem. I wrote a similar script in the past, but it was by no means transparent and I had to jump through a lot of hoops while using it - doing it correctly would be tricky, especially if I want to handle absolute file paths.

At this point I am starting to feel that I'd have to pile a lot of home-grown solutions on top of each other to make Mercurial work in this use case - perhaps too many. There would always be rough edges that I'd occasionally hit.

Upvotes: 3

Views: 388

Answers (2)

thkala
thkala

Reputation: 86443

I finally found a straight-forward solution using git. More specifically, git allows the work directory (work tree in git terms) to reside away from the repository itself. Thefore all I have to do is:

  • Create a secure directory in the desired location:

    # mkdir -p /root/git
    # chmod 700 /root/git
    
  • Initialize a git repository within the previous directory:

    # cd /root/git
    # git init
    
  • Modify .git/config to contain the core.worktree option, by adding worktree = /etc in the [core] section

  • Use git normally:

    # git add /etc/hosts
    # git commit -m "..." -a
    

Upvotes: 1

Brian Cain
Brian Cain

Reputation: 14619

Alternatively - and quite reluctantly - is there a modern version control system or other versioning solution that will do this out of the box?

Flyback (similar to Apple's "Time Machine") is not a VCS, but if all you want is a linear history, it might be exactly what you need.

Upvotes: 2

Related Questions