Our bespoke IDE outputs XML files with an encoding that makes them look like binary files. Diffs and merges of these files fail.
We can create ASCII versions of these files with the tr command. I would like to get to a state where these files are always automatically converted to ascii before they are committed.
I picked up my copy of Version Control with Git and it wholeheartedly warns me away from using hooks unless I really need to.
Should I be using a hook for this purpose? Or can I do something else to ensure the files are always converted before commit?
Windows XP with msysgit 1.7.4
–= update =–
Thanks everyone for your help and patience. Looking to this question I tried the following, but it does not work:
echo "*.xrp filter=xrp" > .git/info/attributes
git config --global filter.xrp.clean 'tr -cd '\''\11\12\15\40-\176'\'''
git config --global filter.xrp.smudge cat
git checkout --force
The files remain unchanged after this config change. Even when I delete and re-checkout.
The tr command configured as the clean task does work in isolation. Proof:
$ head -n 1 cashflow/repo/C_GMM_CashflowRepo.xrp
ÿþ< ! - - X M L R e p o s i t o r y f i l e 1 . 0 - - >
$ tr -cd '\''\11\12\15\40-\176'\' < cashflow/repo/C_GMM_CashflowRepo.xrp | head -n 1
<!-- XML Repository file 1.0 -->
Can anyone see what is wrong with my config?
One issue with hooks is that they aren’t distributed.
.gitattributeshas some directive to manage the diff and content of a file, but another option would be an attribute filter (still in.gitattributes), and could automatically convert those files on commit.(That is if the clean script is able to detect those files based on their content alone)
Per this chat discussion, the OP Synesso reports a success:
Note that, for any modification which doesn’t concern just one user, but potentially any user cloning that repo, I prefer adding (and committing) an extra
.gitattributesfile in which the filter is declared, rather than modifying the.git/info/attributefile (which isn’t cloned around).From the
gitattributesman page:http://git-scm.com/docs/gitattributes
phyatt adds in the comments: