Can I use a git smudge/clean filter to convert binary file to multiple files and back?

222 views Asked by At

I have a binary file that can be deserialized into a text representation along with some supporting image files.

Can I use smudge and clean to do this conversion from 1 file to many, and then back again?

Eg:

The binary file:

  • Demo.bin

Would deserialize to:

  • Demo.txt (important to be able to do diffs on this file)
  • Demo.Picture1.bmp
  • Demo.Picture2.gif
1

There are 1 answers

0
torek On

The short answer is "no". The longer answer is more complicated: sure, you can write such files into the work-tree all you want. You cannot make them wind up in the index, though, so by definition they will be untracked files. You could try to overwrite existing index files but that would be fraught with peril.

(Both the old style filter-driver and the new-style filter-as-process are expected / assumed (by Git) to work on one specified path at a time. Using the process method, you could perhaps delay touching the index until your filter is terminated, which will be just before Git assumes it is done with whatever it is doing—whether that requires smudging or cleaning.)