2

Having read this past question for git, I would like to ask if there exists something like that, but

  1. can be done programmatically (file list) on each machine;
  2. works for Mercurial.

The reason for this is that I would like to include in my public dotfiles repository some configuration files that store password in plaintext. I know I could write a wraparound script for hg(1) but I would like to know if there are alternative approaches, just for the sake of curiosity.

Thank you.

Community
  • 1
  • 1
Emanuele Cipolla
  • 301
  • 3
  • 16

2 Answers2

4

You could use a pair of pre-commit and post-update hooks to encrypt/decrypt as necessary. See http://hgbook.red-bean.com/read/handling-repository-events-with-hooks.html for more details.

However, it's worth pointing out that if you're storing encrypted text in your repo you'll be unable to create meaningful diffs -- essentially everything will be like a binary file but also poorly compressible.

Ry4an Brase
  • 78,112
  • 7
  • 148
  • 169
  • 1
    *so use sparingly, but still a solid idea for extra security. [link to the hackernews thread](https://news.ycombinator.com/item?id=5178914). – egbutter Jun 28 '13 at 15:46
  • Does this include file & directory names? Confidentiality is otherwise affected by filenames alone... – bytecode77 Apr 05 '17 at 01:24
2

Mercurial has a filter system that lets you mangle files when they are read from the repository or written back. If you have a program like the SSH agent running that lets you do non-interactive encryption and decryption, then this might just be workable.

As Ryan points out, this will necessarily lead to a bigger repository since each encrypted version of your files will look completely different from the previous version. Mercurial detects this and stores the versions uncompressed (encrypted files cannot be compressed anyway). Since you will use this for dotfiles, you can ignore the space overhead, but it's something to take into consideration if you will be versioning bigger files in encrypted form.

Please post a mail to Mercurial mailing list with your experiences so that other users can benefit from them too.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Martin Geisler
  • 72,968
  • 25
  • 171
  • 229
  • Thank you Martin, I didn't have any spare time to test your suggestion; as this question outlines a real problem for me (and I do have an ssh-agent running) rest assured that I will duly report my experience, when I get some time to tinker with my repository. Thanks again. – Emanuele Cipolla Oct 08 '10 at 17:09