Search code examples
encryptionmercurialconfiguration-filesrepository

Encrypting files added to Mercurial repositories on commit


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.


Solution

  • 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.