josephburnett / jd

JSON diff and patch
MIT License
826 stars 38 forks source link

docs: Use jd as a git diff driver #49

Closed karlb closed 2 years ago

karlb commented 2 years ago

Analogous to https://github.com/josephburnett/jd/issues/38, providing instructions for setting it up as a git diff driver might also be interesting. Here's roughly what is needed:

A wrapper script to only pass the old and new files in. I also added || true, since I always get fatal: external diff died otherwise. This wrapper script could be avoided if there was a way to tell jd to read git's diff args directly.

#!/bin/sh
jd "$2" "$5" || true

Setting jd as a diff driver, e.g. in .gitconfig:

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

Use .gitattributes to default to jd for JSON diffs:

*.json  diff=jd
josephburnett commented 2 years ago

Good idea. We should add a flag -git-diff-driver to place jd in this mode. It would require exactly 7 parameters (path old-file old-hex old-mode new-file new-hex new-mode) and ignore all but old and new files (just like your script).

@karlb would you like to add this flag? Then we can add this to the docs without the wrapper script.

karlb commented 2 years ago

Sorry, but I prefer to focus on other tasks at the moment.

josephburnett commented 2 years ago

I've added --git-diff-driver in c79c2ec. I'm just waiting until the next minor release to update the README. Works great and doesn't need the wrapper script. Thanks @karlb for the idea. :)

karlb commented 2 years ago

Glad to hear that my comment was helpful. Thanks for the implementation!