Inspired by this answer, I wonder if there is a way to obtain the same behavior in Mercurial
than the one obtained with the smudge/clean filters specified in the .gitattributes
file for git
. This is, applying some preprocessing to some files before committing, without affecting the working copy.
You can find a proper description of what I mean in the git documentation on gitattributes
in the filters
subsection. Also, from the Pro Git book:
It turns out that you can write your own filters for doing substitutions in files on commit/checkout. These are called “clean” and “smudge” filters. In the .gitattributes file, you can set a filter for particular paths and then set up scripts that will process files just before they’re checked out (“smudge”, see Figure 8-2) and just before they’re staged (“clean”, see Figure 8-3). These filters can be set to do all sorts of fun things.
My use case is similar to the one stated in this other question: to clean up part of some files before committing them to the repository but without affecting the working copy.
The most similar thing I was able to find is the encode
/decode
functionality of Mercurial. The problem is that the documentation on this feature is quite succinct (I couldn't find much information anywhere else).
But then, the encode
/decode
functionality is marked as an unloved feature. Why is that? Does it mean there is a better way to do what it does? For some reason there is no proper way to do it but I should go for this one like everyone else?