2

I'd like to version a file such that for repository-related functions such as (and even sophisticated conflict solutions) the file appears to be a directory with its included files being committed regularly to git, except that on checkout one should obtain a valid tar archive again. Is this somehow achievable?

I first thought about using smudge/clean filters, but they merely allow you to modify the file contents of the stored git blob.

So, now I'm thinking about using hooks (pre-commit and post-checkout, as suggested here, though I wish there were a pre-add filter as well...) which would either simply convert between tar file and directory structure or, in order to maintain the metadata correctly, directly plumbing with git objects (or, as a compromise, use the intermediate directory but override the metadata). But, before I start with this potentially insane work, is there either

  • a better way to achieve this, or
  • an already existing solution?

This is strongly related to Can git treat zip files as directories and files inside the zip as blobs?, although I hope that due to files being merely a concatenation of files and metadata without compression, treating them might be easier.

Tobias Kienzler
  • 25,759
  • 22
  • 127
  • 221
  • 1
    To diff two tar files, you can use this: http://superuser.com/a/706286/4803 - basically enable `textconv` for `*.tar` and cat the output of each tar file as text so they can be diff'd. But I don't think this helps you with merge. – John Zwinck May 03 '16 at 10:59
  • @JohnZwinck Thanks, that's helpful for `diff`ing, but I agree with you that this probably won't help in merging (or other git porcelain) – Tobias Kienzler May 03 '16 at 11:02
  • Is there any reason that you must track the tars? Why do you not track the directories, and you can use checkout to generate the tar (which should be ignored AND untracked). This does not answer your question, but it may solve your problem. – Joseph K. Strauss May 04 '16 at 00:36
  • @JosephK.Strauss In my actual case, I'm starting with a binary format that I can already convert to/from tar in a clean/smudge cycle. I'm not sure its metadata (which would become incomplete on Windows when extracting to a directory structure) matters, but apart from that I'd like my colleagues to be able to use git directly on the binary format without having to know about the conversion. _And_ I'm curious whether it's possible... – Tobias Kienzler May 04 '16 at 05:49

1 Answers1

0

I would suggest what was mentioned in one of the comments, namely to use textconv.

Instead of manually, using cat, you could simple invoke the --textconv option for git diff.

For merging you can use the renormalize option, or configure this as the default with merge.renormalize.

I have never actually tested this, but I believe it will work.

Joseph K. Strauss
  • 4,683
  • 1
  • 23
  • 40