Specific diff tool for single file type in git with git-diff like header information

Viewed 190

So I have a lot of jsons to compare and for this I use the npm package json-diff, which generates a nice diff for the jsons, but it only prints the diff. I would like to prepend this with the standard git diff header informing me of rename, file mode (shouldn't change but can happen by accident), etc:

diff --git a/license.mk b/license.mk
old mode 100644
new mode 100755
index ee34415..0d95c00
--- a/license.mk
+++ b/license.mk

I found this SO question: How do I view 'git diff' output with my preferred diff tool/ viewer? and could get json-diff to integrate by using .gitattributes

*.json diff=json-diff

and gitconfig:

[diff "json-diff"]
    command = json-diff-wrapper.sh

This wrapper script basically takes the 7 input arguments and pipes $2 and $5 to json-diff. But I would like to print the same header and I'm confused where it takes the filenames from, since one of the two files is always in /tmp but the filename starts with a hash so I can't simply use basename $2 and basename $5. Is there some way to get this information from git diff somehow? Or should I use a different way of wrapping the call?

Also which is the local file and which is the remote file? $2 seems to be the remote one

0 Answers
Related